Skip to content

Commit

Permalink
Use with statement when opening files
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Sep 6, 2023
1 parent 21dc784 commit 47bd6ff
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 59 deletions.
15 changes: 8 additions & 7 deletions support/palvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
105 changes: 53 additions & 52 deletions support/sst2pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit 47bd6ff

Please sign in to comment.