summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorDylan Baker <[email protected]>2018-10-24 12:08:38 -0700
committerDylan Baker <[email protected]>2018-10-31 16:37:12 -0700
commit1df086662a993340127637f88cfe0462b48e66c8 (patch)
treec7a78da600c0ba229b6312991b32581c89015b37 /src/util
parentbc4a7645e4cc37f47211eb8176251ecd74417f87 (diff)
util/gen_xmlpool: use with statement to open file
Which ensures it is closed at the end of the scope. Reviewed-by: Emil Velikov <[email protected]>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/xmlpool/gen_xmlpool.py66
1 files changed, 32 insertions, 34 deletions
diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py
index a39f9e9e2fa..6a5dcee0a87 100644
--- a/src/util/xmlpool/gen_xmlpool.py
+++ b/src/util/xmlpool/gen_xmlpool.py
@@ -189,42 +189,40 @@ def main():
# Process the options template and generate options.h with all
# translations.
- template = io.open(args.template, mode="rt", encoding='utf-8')
- descMatches = []
- for line in template:
- if len(descMatches) > 0:
- matchENUM = reENUM.match(line)
- matchDESC_END = reDESC_END.match(line)
- if matchENUM:
- descMatches.append(matchENUM)
- elif matchDESC_END:
- expandMatches(descMatches, translations, line)
- descMatches = []
+ with io.open(args.template, mode="rt", encoding='utf-8') as template:
+ descMatches = []
+ for line in template:
+ if len(descMatches) > 0:
+ matchENUM = reENUM.match(line)
+ matchDESC_END = reDESC_END.match(line)
+ if matchENUM:
+ descMatches.append(matchENUM)
+ elif matchDESC_END:
+ expandMatches(descMatches, translations, line)
+ descMatches = []
+ else:
+ print("Warning: unexpected line inside description dropped:\n",
+ line, file=sys.stderr)
+ continue
+ if reLibintl_h.search(line):
+ # Ignore (comment out) #include <libintl.h>
+ print("/* %s * commented out by gen_xmlpool.py */" % line)
+ continue
+ matchDESC = reDESC.match(line)
+ matchDESC_BEGIN = reDESC_BEGIN.match(line)
+ if matchDESC:
+ assert len(descMatches) == 0
+ expandMatches([matchDESC], translations)
+ elif matchDESC_BEGIN:
+ assert len(descMatches) == 0
+ descMatches = [matchDESC_BEGIN]
else:
- print("Warning: unexpected line inside description dropped:\n", line,
- file=sys.stderr)
- continue
- if reLibintl_h.search(line):
- # Ignore (comment out) #include <libintl.h>
- print("/* %s * commented out by gen_xmlpool.py */" % line)
- continue
- matchDESC = reDESC.match(line)
- matchDESC_BEGIN = reDESC_BEGIN.match(line)
- if matchDESC:
- assert len(descMatches) == 0
- expandMatches([matchDESC], translations)
- elif matchDESC_BEGIN:
- assert len(descMatches) == 0
- descMatches = [matchDESC_BEGIN]
- else:
- # In Python 2, stdout expects encoded byte strings, or else it will
- # encode them with the ascii 'codec'
- if sys.version_info.major == 2:
- line = line.encode('utf-8')
-
- print(line, end='')
+ # In Python 2, stdout expects encoded byte strings, or else it will
+ # encode them with the ascii 'codec'
+ if sys.version_info.major == 2:
+ line = line.encode('utf-8')
- template.close()
+ print(line, end='')
if len(descMatches) > 0:
print("Warning: unterminated description at end of file.", file=sys.stderr)