propagated exception
[mp3tohtml.git] / mp3tohtml / mp3tohtml.py
index db32bdc..1cd1004 100755 (executable)
@@ -1,16 +1,23 @@
 #!/usr/bin/python2
 
-# Generate an HTML page containing information about MP3s in a
-# directory.
+# usage: mp3tohtml.py [-h] [--config CONFIG] dir
 #
-# Usage: mp3tohtml.py <mp3_dir>
+# Generate an HTML containing information about the MP3 files.
+#
+# positional arguments:
+#  dir              The directory containing the MP3 files
+#
+# optional arguments:
+#  -h, --help       show this help message and exit
+#  --config CONFIG  The directory containing the configuration
 #
 # Last version of this tool can be get from the GIT repository:
-# http://git.wpitchoune.net/radio.git
+# http://wpitchoune.net/mp3tohtml
 #
+# Released under the terms of the GPLv2 license.
 # (c) 2016 Jean-Philippe Orsini  <jeanfi@gmail.com>
 
-import argparse;
+import argparse
 import eyeD3
 import fnmatch
 import glob
@@ -43,15 +50,29 @@ def fma_copyright_to_html(path, copyright):
 
 def copy_header(path):
     header_path = path + "/header.tpl"
-    header = open(header_path, "r")
-    for line in header:
-        sys.stdout.write(line)
+    try:
+        header = open(header_path, "r")
+        for line in header:
+            sys.stdout.write(line)
+        header.close()
+    except IOError as e:
+        sys.stderr.write("Failed to read header file "
+                         + header_path
+                         + ": " + e.strerror + "\n")
+        raise
 
 def copy_footer(path):
     footer_path = path + "/footer.tpl"
-    footer = open(footer_path, "r")
-    for line in footer:
-        sys.stdout.write(line)
+    try:
+        footer = open(footer_path, "r")
+        for line in footer:
+            sys.stdout.write(line)
+        footer.close()
+    except IOError as e:
+        sys.stderr.write("Failed to read footer file "
+                         + footer_path
+                         + ": " + e.strerror + "\n")
+        raise
 
 parser = argparse.ArgumentParser(description='Generate an HTML containing information about the MP3 files.')
 parser.add_argument('dir', help='The directory containing the MP3 files')