diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2020-03-20 17:26:55 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-03-21 08:15:11 +0100 |
commit | 69ffb52052afb7104d7db690f5ce2253bbfdab05 (patch) | |
tree | ddbeaa5c5db45e5ff8ec03b400be8305792d04a3 | |
parent | 8cea43730177a89c7686cda64f87a2e9e63fd7fd (diff) |
Explicitly close all opened files.
Change-Id: I83afa6ccda72dd0c8a4c61a5858a67b620ffac8f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90805
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | solenv/bin/image-sort.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/solenv/bin/image-sort.py b/solenv/bin/image-sort.py index 10558629bb7c..ce69db3e64a4 100644 --- a/solenv/bin/image-sort.py +++ b/solenv/bin/image-sort.py @@ -30,10 +30,11 @@ def read_icons(fname): if not os.path.exists(full_path): print("Skipping non-existent {}\n".format(full_path)) return images - for line in open(full_path): - m = re.search(r'xlink:href="\.uno:(\S+)"\s+', line) - if m: - images.append(m.group(1).lower()) + with open(full_path) as fp: + for line in fp: + m = re.search(r'xlink:href="\.uno:(\S+)"\s+', line) + if m: + images.append(m.group(1).lower()) return images # filter out already seen icons & do prefixing @@ -79,10 +80,10 @@ def process_file(fname, prefix): global_list.append(icon) global_hash[icon] = 1 -def chew_controlfile(fname): +def chew_controlfile(ifile): global global_list, global_hash filelist = [] - for line in open(fname): + for line in ifile: line = line.strip() if line.startswith('#'): continue @@ -126,10 +127,13 @@ base_path = sys.argv[2] # output if len(sys.argv) > 3: output = open(sys.argv[3], 'w') + close_output = True else: output = sys.stdout + close_output = False -chew_controlfile(control) +with open(control) as controlfile: + chew_controlfile(controlfile) for icon in global_list: if not icon.startswith('sc_'): @@ -139,4 +143,7 @@ for icon in global_list: if icon.startswith('sc_'): output.write(icon + "\n") +if close_output: + output.close() + # dnl vim:set shiftwidth=4 softtabstop=4 expandtab: |