Back to index

python3.2  3.2.2
Functions | Variables
pdeps Namespace Reference

Functions

def main
def process
def closure
def inverse
def store
def printresults

Variables

tuple m_import = re.compile('^[ \t]*from[ \t]+([^ \t]+)[ \t]+')
tuple m_from = re.compile('^[ \t]*import[ \t]+([^#]+)')

Function Documentation

def pdeps.closure (   table)

Definition at line 94 of file pdeps.py.

00094 
00095 def closure(table):
00096     modules = list(table.keys())
00097     #
00098     # Initialize reach with a copy of table
00099     #
00100     reach = {}
00101     for mod in modules:
00102         reach[mod] = table[mod][:]
00103     #
00104     # Iterate until no more change
00105     #
00106     change = 1
00107     while change:
00108         change = 0
00109         for mod in modules:
00110             for mo in reach[mod]:
00111                 if mo in modules:
00112                     for m in reach[mo]:
00113                         if m not in reach[mod]:
00114                             reach[mod].append(m)
00115                             change = 1
00116     #
00117     return reach
00118 
00119 
00120 # Invert a table (this is again totally general).
00121 # All keys of the original table are made keys of the inverse,
00122 # so there may be empty lists in the inverse.
#

Here is the call graph for this function:

Here is the caller graph for this function:

def pdeps.inverse (   table)

Definition at line 123 of file pdeps.py.

00123 
00124 def inverse(table):
00125     inv = {}
00126     for key in table.keys():
00127         if not inv.has_key(key):
00128             inv[key] = []
00129         for item in table[key]:
00130             store(inv, item, key)
00131     return inv
00132 
00133 
00134 # Store "item" in "dict" under "key".
00135 # The dictionary maps keys to lists of items.
00136 # If there is no list for the key yet, it is created.
#

Here is the call graph for this function:

Here is the caller graph for this function:

def pdeps.main ( void  )

Definition at line 30 of file pdeps.py.

00030 
00031 def main():
00032     args = sys.argv[1:]
00033     if not args:
00034         print('usage: pdeps file.py file.py ...')
00035         return 2
00036     #
00037     table = {}
00038     for arg in args:
00039         process(arg, table)
00040     #
00041     print('--- Uses ---')
00042     printresults(table)
00043     #
00044     print('--- Used By ---')
00045     inv = inverse(table)
00046     printresults(inv)
00047     #
00048     print('--- Closure of Uses ---')
00049     reach = closure(table)
00050     printresults(reach)
00051     #
00052     print('--- Closure of Used By ---')
00053     invreach = inverse(reach)
00054     printresults(invreach)
00055     #
00056     return 0
00057 
00058 
00059 # Compiled regular expressions to search for import statements
#

Here is the call graph for this function:

Here is the caller graph for this function:

def pdeps.printresults (   table)

Definition at line 146 of file pdeps.py.

00146 
00147 def printresults(table):
00148     modules = sorted(table.keys())
00149     maxlen = 0
00150     for mod in modules: maxlen = max(maxlen, len(mod))
00151     for mod in modules:
00152         list = sorted(table[mod])
00153         print(mod.ljust(maxlen), ':', end=' ')
00154         if mod in list:
00155             print('(*)', end=' ')
00156         for ref in list:
00157             print(ref, end=' ')
00158         print()
00159 
00160 
# Call main and honor exit status

Here is the call graph for this function:

Here is the caller graph for this function:

def pdeps.process (   filename,
  table 
)

Definition at line 66 of file pdeps.py.

00066 
00067 def process(filename, table):
00068     fp = open(filename, 'r')
00069     mod = os.path.basename(filename)
00070     if mod[-3:] == '.py':
00071         mod = mod[:-3]
00072     table[mod] = list = []
00073     while 1:
00074         line = fp.readline()
00075         if not line: break
00076         while line[-1:] == '\\':
00077             nextline = fp.readline()
00078             if not nextline: break
00079             line = line[:-1] + nextline
00080         if m_import.match(line) >= 0:
00081             (a, b), (a1, b1) = m_import.regs[:2]
00082         elif m_from.match(line) >= 0:
00083             (a, b), (a1, b1) = m_from.regs[:2]
00084         else: continue
00085         words = line[a1:b1].split(',')
00086         # print '#', line, words
00087         for word in words:
00088             word = word.strip()
00089             if word not in list:
00090                 list.append(word)
00091 
00092 
00093 # Compute closure (this is in fact totally general)
#

Here is the call graph for this function:

Here is the caller graph for this function:

def pdeps.store (   dict,
  key,
  item 
)

Definition at line 137 of file pdeps.py.

00137 
00138 def store(dict, key, item):
00139     if key in dict:
00140         dict[key].append(item)
00141     else:
00142         dict[key] = [item]
00143 
00144 
00145 # Tabulate results neatly
#

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

tuple pdeps.m_from = re.compile('^[ \t]*import[ \t]+([^#]+)')

Definition at line 61 of file pdeps.py.

tuple pdeps.m_import = re.compile('^[ \t]*from[ \t]+([^ \t]+)[ \t]+')

Definition at line 60 of file pdeps.py.