system.py 836 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import os
  2. import re
  3. import subprocess
  4. from .compat import decode
  5. from .log import debug
  6. __all__ = ['ldd', 'system']
  7. def system(*args):
  8. '''System call with capturing output
  9. '''
  10. cmd = ' '.join(args)
  11. debug('SYSTEM', cmd)
  12. p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
  13. stderr=subprocess.PIPE)
  14. out, err = p.communicate()
  15. if err:
  16. err = decode(err)
  17. stripped = [line for line in err.split(os.linesep)
  18. if line and not line.startswith('fuse: warning:')]
  19. if stripped:
  20. raise RuntimeError(err)
  21. return str(decode(out).strip())
  22. _ldd_pattern = re.compile('=> (.+) [(]0x')
  23. def ldd(path):
  24. '''Get dependencies list of dynamic libraries
  25. '''
  26. out = system('ldd', path)
  27. return _ldd_pattern.findall(out)