-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_dependences.py
executable file
·59 lines (44 loc) · 1.46 KB
/
python_dependences.py
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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
from subprocess import Popen, PIPE
def dpkg_S(file):
dpkg_pipe = Popen("dpkg -S %s" % file, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
retcode = dpkg_pipe.wait()
if (retcode == 0):
pkg_name = dpkg_pipe.stdout.readline().split(":")[0]
return pkg_name
else:
print "%s not found" % file
print >>sys.stderr, dpkg_pipe.stderr.read()
return None
if (len(sys.argv) != 2):
print "Usage: %s modules.list" % sys.argv[0]
sys.exit(0)
fo = open(sys.argv[1], "r")
for module_name in fo.readlines():
module_name = module_name.strip()
try:
exec("import %s" % module_name)
except:
print "WARNING: skipping %s" % module_name
continue
# skip built-in module
if (repr(sys.modules[module_name]).find("built-in") != -1):
continue
exec("module_file = %s.__file__" % module_name)
if (module_file[-4:] == ".pyc"):
module_file = module_file[:-1]
while (1):
if (os.path.islink(module_file)):
module_file_tmp = os.readlink(module_file)
if (module_file_tmp[0] != "/"):
module_file_tmp = os.path.abspath("%s/%s" % (os.path.dirname(module_file), module_file_tmp))
module_file = module_file_tmp
else:
break
pkg_name = dpkg_S(module_file)
if (pkg_name):
print "%s => %s" % (module_name, pkg_name)
fo.close()