diff --git a/support/palvers.py b/support/palvers.py index 29a4f09..8666db0 100644 --- a/support/palvers.py +++ b/support/palvers.py @@ -44,13 +44,14 @@ def read_pal_version(): """ verfile = os.path.join("cextern", "pal", "configure.ac") verstring = "-1.-1.-1" - for line in open(verfile): - if line.startswith("AC_INIT"): - # Version will be in string [nn.mm.pp] - match = re.search(r"\[(\d+\.\d+\.\d+)\]", line) - if match: - verstring = match.group(1) - break + with open(verfile) as fh: + for line in fh: + if line.startswith("AC_INIT"): + # Version will be in string [nn.mm.pp] + match = re.search(r"\[(\d+\.\d+\.\d+)\]", line) + if match: + verstring = match.group(1) + break (major, minor, patch) = verstring.split(".") return (verstring, major, minor, patch) diff --git a/support/sst2pydoc.py b/support/sst2pydoc.py index 3b7567b..8aed59e 100644 --- a/support/sst2pydoc.py +++ b/support/sst2pydoc.py @@ -50,60 +50,61 @@ def read_prologs(filename): content = "" counter = 0 - for line in open(filename): - line = line.strip() - - # Start of a completely new prolog so reset everything - if line.startswith("*+"): - if counter != 0: - raise ValueError("Started prologue without closing previous prologue") - prolog = {} - heading = "" - content = "" + with open(filename) as fh: + for line in fh: + line = line.strip() + + # Start of a completely new prolog so reset everything + if line.startswith("*+"): + if counter != 0: + raise ValueError("Started prologue without closing previous prologue") + prolog = {} + heading = "" + content = "" + counter = counter + 1 + continue + + # End of a prolog. Must store the current dict + if line.startswith("*-"): + counter = 0 + if len(heading): + # Flush current heading + prolog[heading] = content + content = "" + name = prolog['name'].strip() + results[name] = prolog + prolog = None + continue + + # If we are not in a prologue then nothing further is needed + if counter == 0: + continue + counter = counter + 1 - continue - - # End of a prolog. Must store the current dict - if line.startswith("*-"): - counter = 0 - if len(heading): - # Flush current heading - prolog[heading] = content + + # Completely blank lines are ignored + if len(line) == 0: + continue + + # Look for a new section heading + match_head = heading_re.search(line) + if match_head is not None: + if len(heading): + # Flush previous heading + prolog[heading] = content + heading = match_head.group(1).lower() content = "" - name = prolog['name'].strip() - results[name] = prolog - prolog = None - continue - - # If we are not in a prologue then nothing further is needed - if counter == 0: - continue - - counter = counter + 1 - - # Completely blank lines are ignored - if len(line) == 0: - continue - - # Look for a new section heading - match_head = heading_re.search(line) - if match_head is not None: - if len(heading): - # Flush previous heading - prolog[heading] = content - heading = match_head.group(1).lower() - content = "" - continue - - if line.startswith("* "): - content = content + line[6:] + "\n" - continue - elif line == "*": - content = content + "\n" - continue - - if counter: - raise ValueError("Error parsing SST prologue line "+str(counter)+":'" + line + "'") + continue + + if line.startswith("* "): + content = content + line[6:] + "\n" + continue + elif line == "*": + content = content + "\n" + continue + + if counter: + raise ValueError("Error parsing SST prologue line "+str(counter)+":'" + line + "'") return results if __name__ == "__main__":