summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/pdeps.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/scripts/pdeps.py')
-rwxr-xr-xTools/scripts/pdeps.py77
1 files changed, 40 insertions, 37 deletions
diff --git a/Tools/scripts/pdeps.py b/Tools/scripts/pdeps.py
index 4e8e930..da63e35 100755
--- a/Tools/scripts/pdeps.py
+++ b/Tools/scripts/pdeps.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python3
+#! /usr/bin/env python
# pdeps
#
@@ -30,25 +30,25 @@ import os
def main():
args = sys.argv[1:]
if not args:
- print('usage: pdeps file.py file.py ...')
+ print 'usage: pdeps file.py file.py ...'
return 2
#
table = {}
for arg in args:
process(arg, table)
#
- print('--- Uses ---')
+ print '--- Uses ---'
printresults(table)
#
- print('--- Used By ---')
+ print '--- Used By ---'
inv = inverse(table)
printresults(inv)
#
- print('--- Closure of Uses ---')
+ print '--- Closure of Uses ---'
reach = closure(table)
printresults(reach)
#
- print('--- Closure of Used By ---')
+ print '--- Closure of Used By ---'
invreach = inverse(reach)
printresults(invreach)
#
@@ -64,34 +64,35 @@ m_from = re.compile('^[ \t]*import[ \t]+([^#]+)')
# Collect data from one file
#
def process(filename, table):
- with open(filename) as fp:
- mod = os.path.basename(filename)
- if mod[-3:] == '.py':
- mod = mod[:-3]
- table[mod] = list = []
- while 1:
- line = fp.readline()
- if not line: break
- while line[-1:] == '\\':
- nextline = fp.readline()
- if not nextline: break
- line = line[:-1] + nextline
- m_found = m_import.match(line) or m_from.match(line)
- if m_found:
- (a, b), (a1, b1) = m_found.regs[:2]
- else: continue
- words = line[a1:b1].split(',')
- # print '#', line, words
- for word in words:
- word = word.strip()
- if word not in list:
- list.append(word)
+ fp = open(filename, 'r')
+ mod = os.path.basename(filename)
+ if mod[-3:] == '.py':
+ mod = mod[:-3]
+ table[mod] = list = []
+ while 1:
+ line = fp.readline()
+ if not line: break
+ while line[-1:] == '\\':
+ nextline = fp.readline()
+ if not nextline: break
+ line = line[:-1] + nextline
+ if m_import.match(line) >= 0:
+ (a, b), (a1, b1) = m_import.regs[:2]
+ elif m_from.match(line) >= 0:
+ (a, b), (a1, b1) = m_from.regs[:2]
+ else: continue
+ words = line[a1:b1].split(',')
+ # print '#', line, words
+ for word in words:
+ word = word.strip()
+ if word not in list:
+ list.append(word)
# Compute closure (this is in fact totally general)
#
def closure(table):
- modules = list(table.keys())
+ modules = table.keys()
#
# Initialize reach with a copy of table
#
@@ -122,7 +123,7 @@ def closure(table):
def inverse(table):
inv = {}
for key in table.keys():
- if key not in inv:
+ if not inv.has_key(key):
inv[key] = []
for item in table[key]:
store(inv, item, key)
@@ -134,7 +135,7 @@ def inverse(table):
# If there is no list for the key yet, it is created.
#
def store(dict, key, item):
- if key in dict:
+ if dict.has_key(key):
dict[key].append(item)
else:
dict[key] = [item]
@@ -143,17 +144,19 @@ def store(dict, key, item):
# Tabulate results neatly
#
def printresults(table):
- modules = sorted(table.keys())
+ modules = table.keys()
maxlen = 0
for mod in modules: maxlen = max(maxlen, len(mod))
+ modules.sort()
for mod in modules:
- list = sorted(table[mod])
- print(mod.ljust(maxlen), ':', end=' ')
+ list = table[mod]
+ list.sort()
+ print mod.ljust(maxlen), ':',
if mod in list:
- print('(*)', end=' ')
+ print '(*)',
for ref in list:
- print(ref, end=' ')
- print()
+ print ref,
+ print
# Call main and honor exit status