Back to index

python3.2  3.2.2
Classes | Functions | Variables
modulefinder Namespace Reference

Classes

class  Module
class  ModuleFinder

Functions

def AddPackagePath
def ReplacePackage
def test

Variables

string READ_MODE = "rU"
tuple LOAD_CONST = bytes([dis.opname.index('LOAD_CONST')])
tuple IMPORT_NAME = bytes([dis.opname.index('IMPORT_NAME')])
tuple STORE_NAME = bytes([dis.opname.index('STORE_NAME')])
tuple STORE_GLOBAL = bytes([dis.opname.index('STORE_GLOBAL')])
list STORE_OPS = [STORE_NAME, STORE_GLOBAL]
tuple HAVE_ARGUMENT = bytes([dis.HAVE_ARGUMENT])
dictionary packagePathMap = {}
dictionary replacePackageMap = {}
tuple mf = test()

Detailed Description

Find modules used by a script, using introspection.

Function Documentation

def modulefinder.AddPackagePath (   packagename,
  path 
)

Definition at line 31 of file modulefinder.py.

00031 
00032 def AddPackagePath(packagename, path):
00033     paths = packagePathMap.get(packagename, [])
00034     paths.append(path)
00035     packagePathMap[packagename] = paths

Here is the caller graph for this function:

def modulefinder.ReplacePackage (   oldname,
  newname 
)

Definition at line 44 of file modulefinder.py.

00044 
00045 def ReplacePackage(oldname, newname):
00046     replacePackageMap[oldname] = newname
00047 

Definition at line 602 of file modulefinder.py.

00602 
00603 def test():
00604     # Parse command line
00605     import getopt
00606     try:
00607         opts, args = getopt.getopt(sys.argv[1:], "dmp:qx:")
00608     except getopt.error as msg:
00609         print(msg)
00610         return
00611 
00612     # Process options
00613     debug = 1
00614     domods = 0
00615     addpath = []
00616     exclude = []
00617     for o, a in opts:
00618         if o == '-d':
00619             debug = debug + 1
00620         if o == '-m':
00621             domods = 1
00622         if o == '-p':
00623             addpath = addpath + a.split(os.pathsep)
00624         if o == '-q':
00625             debug = 0
00626         if o == '-x':
00627             exclude.append(a)
00628 
00629     # Provide default arguments
00630     if not args:
00631         script = "hello.py"
00632     else:
00633         script = args[0]
00634 
00635     # Set the path based on sys.path and the script directory
00636     path = sys.path[:]
00637     path[0] = os.path.dirname(script)
00638     path = addpath + path
00639     if debug > 1:
00640         print("path:")
00641         for item in path:
00642             print("   ", repr(item))
00643 
00644     # Create the module finder and turn its crank
00645     mf = ModuleFinder(path, debug, exclude)
00646     for arg in args[1:]:
00647         if arg == '-m':
00648             domods = 1
00649             continue
00650         if domods:
00651             if arg[-2:] == '.*':
00652                 mf.import_hook(arg[:-2], None, ["*"])
00653             else:
00654                 mf.import_hook(arg)
00655         else:
00656             mf.load_file(arg)
00657     mf.run_script(script)
00658     mf.report()
00659     return mf  # for -i debugging
00660 

Here is the call graph for this function:


Variable Documentation

Definition at line 20 of file modulefinder.py.

Definition at line 16 of file modulefinder.py.

Definition at line 15 of file modulefinder.py.

tuple modulefinder.mf = test()

Definition at line 663 of file modulefinder.py.

Definition at line 28 of file modulefinder.py.

Definition at line 12 of file modulefinder.py.

Definition at line 36 of file modulefinder.py.

Definition at line 18 of file modulefinder.py.

Definition at line 17 of file modulefinder.py.

Definition at line 19 of file modulefinder.py.