From 4710c53dcad1ebf3755f3efb9e80ac24bd72a9b2 Mon Sep 17 00:00:00 2001 From: darylm503 Date: Mon, 16 Apr 2012 22:12:42 +0000 Subject: AppPkg/Applications/Python: Add Python 2.7.2 sources since the release of Python 2.7.3 made them unavailable from the python.org web site. These files are a subset of the python-2.7.2.tgz distribution from python.org. Changed files from PyMod-2.7.2 have been copied into the corresponding directories of this tree, replacing the original files in the distribution. Signed-off-by: daryl.mcdaniel@intel.com git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13197 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Python/Python-2.7.2/Tools/freeze/parsesetup.py | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 AppPkg/Applications/Python/Python-2.7.2/Tools/freeze/parsesetup.py (limited to 'AppPkg/Applications/Python/Python-2.7.2/Tools/freeze/parsesetup.py') diff --git a/AppPkg/Applications/Python/Python-2.7.2/Tools/freeze/parsesetup.py b/AppPkg/Applications/Python/Python-2.7.2/Tools/freeze/parsesetup.py new file mode 100644 index 0000000000..b14a6dac47 --- /dev/null +++ b/AppPkg/Applications/Python/Python-2.7.2/Tools/freeze/parsesetup.py @@ -0,0 +1,112 @@ +# Parse Makefiles and Python Setup(.in) files. + +import re + + +# Extract variable definitions from a Makefile. +# Return a dictionary mapping names to values. +# May raise IOError. + +makevardef = re.compile('^([a-zA-Z0-9_]+)[ \t]*=(.*)') + +def getmakevars(filename): + variables = {} + fp = open(filename) + pendingline = "" + try: + while 1: + line = fp.readline() + if pendingline: + line = pendingline + line + pendingline = "" + if not line: + break + if line.endswith('\\\n'): + pendingline = line[:-2] + matchobj = makevardef.match(line) + if not matchobj: + continue + (name, value) = matchobj.group(1, 2) + # Strip trailing comment + i = value.find('#') + if i >= 0: + value = value[:i] + value = value.strip() + variables[name] = value + finally: + fp.close() + return variables + + +# Parse a Python Setup(.in) file. +# Return two dictionaries, the first mapping modules to their +# definitions, the second mapping variable names to their values. +# May raise IOError. + +setupvardef = re.compile('^([a-zA-Z0-9_]+)=(.*)') + +def getsetupinfo(filename): + modules = {} + variables = {} + fp = open(filename) + pendingline = "" + try: + while 1: + line = fp.readline() + if pendingline: + line = pendingline + line + pendingline = "" + if not line: + break + # Strip comments + i = line.find('#') + if i >= 0: + line = line[:i] + if line.endswith('\\\n'): + pendingline = line[:-2] + continue + matchobj = setupvardef.match(line) + if matchobj: + (name, value) = matchobj.group(1, 2) + variables[name] = value.strip() + else: + words = line.split() + if words: + modules[words[0]] = words[1:] + finally: + fp.close() + return modules, variables + + +# Test the above functions. + +def test(): + import sys + import os + if not sys.argv[1:]: + print 'usage: python parsesetup.py Makefile*|Setup* ...' + sys.exit(2) + for arg in sys.argv[1:]: + base = os.path.basename(arg) + if base[:8] == 'Makefile': + print 'Make style parsing:', arg + v = getmakevars(arg) + prdict(v) + elif base[:5] == 'Setup': + print 'Setup style parsing:', arg + m, v = getsetupinfo(arg) + prdict(m) + prdict(v) + else: + print arg, 'is neither a Makefile nor a Setup file' + print '(name must begin with "Makefile" or "Setup")' + +def prdict(d): + keys = d.keys() + keys.sort() + for key in keys: + value = d[key] + print "%-15s" % key, str(value) + +if __name__ == '__main__': + test() -- cgit v1.2.3