(filename)
| 10 | makevardef = re.compile('^([a-zA-Z0-9_]+)[ \t]*=(.*)') |
| 11 | |
| 12 | def getmakevars(filename): |
| 13 | variables = {} |
| 14 | fp = open(filename) |
| 15 | pendingline = "" |
| 16 | try: |
| 17 | while 1: |
| 18 | line = fp.readline() |
| 19 | if pendingline: |
| 20 | line = pendingline + line |
| 21 | pendingline = "" |
| 22 | if not line: |
| 23 | break |
| 24 | if line.endswith('\\\n'): |
| 25 | pendingline = line[:-2] |
| 26 | matchobj = makevardef.match(line) |
| 27 | if not matchobj: |
| 28 | continue |
| 29 | (name, value) = matchobj.group(1, 2) |
| 30 | # Strip trailing comment |
| 31 | i = value.find('#') |
| 32 | if i >= 0: |
| 33 | value = value[:i] |
| 34 | value = value.strip() |
| 35 | variables[name] = value |
| 36 | finally: |
| 37 | fp.close() |
| 38 | return variables |
| 39 | |
| 40 | |
| 41 | # Parse a Python Setup(.in) file. |
no test coverage detected
searching dependent graphs…