From 5048930f44e5cd8dbea81935b4a40abc3241a170 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 4 Jul 2014 20:48:12 +0200 Subject: [PATCH] No error if files cannot be opened --- patacrep/index.py | 4 +++- patacrep/templates.py | 4 +++- songbook | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/patacrep/index.py b/patacrep/index.py index b921a65d..27fa1eb1 100755 --- a/patacrep/index.py +++ b/patacrep/index.py @@ -40,12 +40,14 @@ def process_sxd(filename): Return an Index object. """ data = [] + index_file = None try: index_file = encoding.open_read(filename, 'r') for line in index_file: data.append(line.strip()) finally: - index_file.close() + if index_file: + index_file.close() i = 1 idx = Index(data[0]) diff --git a/patacrep/templates.py b/patacrep/templates.py index 1030aaa1..1b2e7458 100755 --- a/patacrep/templates.py +++ b/patacrep/templates.py @@ -177,6 +177,7 @@ class TexRenderer(object): """ subvariables = {} + template_file = None templatename = self.texenv.get_template(template).filename try: template_file = encoding.open_read(templatename, 'r') @@ -200,7 +201,8 @@ class TexRenderer(object): ) ) finally: - template_file.close() + if template_file: + template_file.close() return (subvariables, subtemplates) diff --git a/songbook b/songbook index f9aee049..65adfbbf 100755 --- a/songbook +++ b/songbook @@ -101,6 +101,7 @@ def main(): basename = os.path.basename(songbook_path)[:-3] + songbook_file = None try: songbook_file = encoding.open_read(songbook_path) songbook = json.load(songbook_file) @@ -109,7 +110,8 @@ def main(): LOGGER.error("Error while loading file '{}'.".format(songbook_path)) sys.exit(1) finally: - songbook_file.close() + if songbook_file: + songbook_file.close() # Gathering datadirs datadirs = []