forked from niess/python-appimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.py
More file actions
54 lines (40 loc) · 1.16 KB
/
system.py
File metadata and controls
54 lines (40 loc) · 1.16 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
import os
import re
import subprocess
from .compat import decode
from .log import debug
__all__ = ['ldd', 'system']
try:
basestring
except NameError:
basestring = (str, bytes)
def system(args, exclude=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:')
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
if err:
err = decode(err)
stripped = [line for line in err.split(os.linesep) if line]
for pattern in exclude:
stripped = [line for line in stripped
if not line.startswith(pattern)]
if stripped:
raise RuntimeError(err)
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)