Back to index

python3.2  3.2.2
Functions | Variables
parsesetup Namespace Reference

Functions

def getmakevars
def getsetupinfo
def test
def prdict

Variables

tuple makevardef = re.compile('^([a-zA-Z0-9_]+)[ \t]*=(.*)')
tuple setupvardef = re.compile('^([a-zA-Z0-9_]+)=(.*)')

Function Documentation

def parsesetup.getmakevars (   filename)

Definition at line 12 of file parsesetup.py.

00012 
00013 def getmakevars(filename):
00014     variables = {}
00015     fp = open(filename)
00016     pendingline = ""
00017     try:
00018         while 1:
00019             line = fp.readline()
00020             if pendingline:
00021                 line = pendingline + line
00022                 pendingline = ""
00023             if not line:
00024                 break
00025             if line.endswith('\\\n'):
00026                 pendingline = line[:-2]
00027             matchobj = makevardef.match(line)
00028             if not matchobj:
00029                 continue
00030             (name, value) = matchobj.group(1, 2)
00031             # Strip trailing comment
00032             i = value.find('#')
00033             if i >= 0:
00034                 value = value[:i]
00035             value = value.strip()
00036             variables[name] = value
00037     finally:
00038         fp.close()
00039     return variables
00040 
00041 
00042 # Parse a Python Setup(.in) file.
00043 # Return two dictionaries, the first mapping modules to their
00044 # definitions, the second mapping variable names to their values.
00045 # May raise IOError.

Here is the caller graph for this function:

def parsesetup.getsetupinfo (   filename)

Definition at line 48 of file parsesetup.py.

00048 
00049 def getsetupinfo(filename):
00050     modules = {}
00051     variables = {}
00052     fp = open(filename)
00053     pendingline = ""
00054     try:
00055         while 1:
00056             line = fp.readline()
00057             if pendingline:
00058                 line = pendingline + line
00059                 pendingline = ""
00060             if not line:
00061                 break
00062             # Strip comments
00063             i = line.find('#')
00064             if i >= 0:
00065                 line = line[:i]
00066             if line.endswith('\\\n'):
00067                 pendingline = line[:-2]
00068                 continue
00069             matchobj = setupvardef.match(line)
00070             if matchobj:
00071                 (name, value) = matchobj.group(1, 2)
00072                 variables[name] = value.strip()
00073             else:
00074                 words = line.split()
00075                 if words:
00076                     modules[words[0]] = words[1:]
00077     finally:
00078         fp.close()
00079     return modules, variables
00080 
00081 
00082 # Test the above functions.

Here is the caller graph for this function:

def parsesetup.prdict (   d)

Definition at line 104 of file parsesetup.py.

00104 
00105 def prdict(d):
00106     keys = sorted(d.keys())
00107     for key in keys:
00108         value = d[key]
00109         print("%-15s" % key, str(value))

Here is the call graph for this function:

Here is the caller graph for this function:

def parsesetup.test ( )

Definition at line 83 of file parsesetup.py.

00083 
00084 def test():
00085     import sys
00086     import os
00087     if not sys.argv[1:]:
00088         print('usage: python parsesetup.py Makefile*|Setup* ...')
00089         sys.exit(2)
00090     for arg in sys.argv[1:]:
00091         base = os.path.basename(arg)
00092         if base[:8] == 'Makefile':
00093             print('Make style parsing:', arg)
00094             v = getmakevars(arg)
00095             prdict(v)
00096         elif base[:5] == 'Setup':
00097             print('Setup style parsing:', arg)
00098             m, v = getsetupinfo(arg)
00099             prdict(m)
00100             prdict(v)
00101         else:
00102             print(arg, 'is neither a Makefile nor a Setup file')
00103             print('(name must begin with "Makefile" or "Setup")')

Here is the call graph for this function:


Variable Documentation

tuple parsesetup.makevardef = re.compile('^([a-zA-Z0-9_]+)[ \t]*=(.*)')

Definition at line 10 of file parsesetup.py.

tuple parsesetup.setupvardef = re.compile('^([a-zA-Z0-9_]+)=(.*)')

Definition at line 46 of file parsesetup.py.