Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

import logging 

import os 

import shutil 

import subprocess 

 

 

logger = logging.getLogger(__name__) 

 

 

TYPES = [] 

 

 

def register_xtract(cls): 

"""Register xtract type class.""" 

TYPES.append(cls) 

return cls 

 

 

class FileTypeNotSupported(Exception): 

"""The given file type is not supported.""" 

 

pass 

 

 

def run(cmd, cwd=None, log=True): 

"""Run the given command as a subprocess.""" 

p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) 

 

stdout, stderr = p.communicate() 

 

stdout = stdout.strip().decode() 

if stdout and log: 

logger.debug('Command output: {}'.format(stdout)) 

 

stderr = stderr.strip().decode() 

36 ↛ 37line 36 didn't jump to line 37, because the condition on line 36 was never true if stderr and log: 

logger.error('Command error: {}'.format(stderr)) 

 

39 ↛ 40line 39 didn't jump to line 40, because the condition on line 39 was never true if p.returncode: 

raise subprocess.CalledProcessError(p.returncode, cmd, output=stdout, stderr=stderr) 

 

 

def delete_path(path): 

try: 

os.unlink(path) 

except IsADirectoryError: 

shutil.rmtree(path)