Repository navigation
Expand file tree
/
Copy pathsystem.py
More file actions
73 lines (55 loc) · 1.77 KB
/
Copy pathsystem.py
File metadata and controls
73 lines (55 loc) · 1.77 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import re
import subprocess
from .compat import decode, encode
from .log import debug, log
__all__ = ['ldd', 'system']
try:
basestring
except NameError:
basestring = (str, bytes)
def system(args, exclude=None, stdin=None):
'''System call with capturing output
'''
cmd = ' '.join(args)
debug('SYSTEM', cmd)
if exclude is None:
exclude = []
elif isinstance(exclude, basestring):
exclude = [exclude]
else:
exclude = list(exclude)
exclude.append('fuse: warning:')
if stdin:
in_arg = subprocess.PIPE
stdin = encode(stdin)
else:
in_arg = None
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stdin=in_arg)
out, err = p.communicate(input=stdin)
if err:
err = decode(err)
stripped = [line for line in err.split(os.linesep) if line]
def matches_pattern(line, pattern):
if isinstance(pattern, re.Pattern):
return bool(pattern.match(line))
return line.startswith(pattern)
for pattern in exclude:
stripped = [line for line in stripped
if not matches_pattern(line, pattern)]
if stripped:
# Tolerate single line warning(s)
for line in stripped:
if (len(line) < 8) or (line[:8].lower() != "warning:"):
raise RuntimeError(err)
else:
for line in stripped:
log('WARNING', line[8:].strip())
return str(decode(out).strip())
_ldd_pattern = re.compile('=> (.+) [(]0x')
def ldd(path):
'''Get dependencies list of dynamic libraries
'''
out = system(('ldd', path))
return _ldd_pattern.findall(out)