Browse Source

No error if files cannot be opened

pull/58/head
Louis 11 years ago
parent
commit
5048930f44
  1. 4
      patacrep/index.py
  2. 4
      patacrep/templates.py
  3. 4
      songbook

4
patacrep/index.py

@ -40,12 +40,14 @@ def process_sxd(filename):
Return an Index object. Return an Index object.
""" """
data = [] data = []
index_file = None
try: try:
index_file = encoding.open_read(filename, 'r') index_file = encoding.open_read(filename, 'r')
for line in index_file: for line in index_file:
data.append(line.strip()) data.append(line.strip())
finally: finally:
index_file.close() if index_file:
index_file.close()
i = 1 i = 1
idx = Index(data[0]) idx = Index(data[0])

4
patacrep/templates.py

@ -177,6 +177,7 @@ class TexRenderer(object):
""" """
subvariables = {} subvariables = {}
template_file = None
templatename = self.texenv.get_template(template).filename templatename = self.texenv.get_template(template).filename
try: try:
template_file = encoding.open_read(templatename, 'r') template_file = encoding.open_read(templatename, 'r')
@ -200,7 +201,8 @@ class TexRenderer(object):
) )
) )
finally: finally:
template_file.close() if template_file:
template_file.close()
return (subvariables, subtemplates) return (subvariables, subtemplates)

4
songbook

@ -101,6 +101,7 @@ def main():
basename = os.path.basename(songbook_path)[:-3] basename = os.path.basename(songbook_path)[:-3]
songbook_file = None
try: try:
songbook_file = encoding.open_read(songbook_path) songbook_file = encoding.open_read(songbook_path)
songbook = json.load(songbook_file) songbook = json.load(songbook_file)
@ -109,7 +110,8 @@ def main():
LOGGER.error("Error while loading file '{}'.".format(songbook_path)) LOGGER.error("Error while loading file '{}'.".format(songbook_path))
sys.exit(1) sys.exit(1)
finally: finally:
songbook_file.close() if songbook_file:
songbook_file.close()
# Gathering datadirs # Gathering datadirs
datadirs = [] datadirs = []

Loading…
Cancel
Save