lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

makelsr.py: don't delete the output directory (issue 341050043 by addres


From: nine . fierce . ballads
Subject: makelsr.py: don't delete the output directory (issue 341050043 by address@hidden)
Date: Mon, 02 Apr 2018 11:08:57 -0700

Reviewers: ,

Description:
makelsr.py: don't delete the output directory

If the output directory is not a directory, don't just delete it. Abort
and let the user decide how to address it.

I am pretty confident that these changes are good, but I would be
grateful if someone familiar with this script would try running it
because I can not test the full script myself.  (I have set up my build
environment without write access to the source, so updating source files
fails.  Yes, I have the expertise to change the approach, but I lack the
interest.)

Please review this at https://codereview.appspot.com/341050043/

Affected files (+13, -25 lines):
  M scripts/auxiliar/makelsr.py


Index: scripts/auxiliar/makelsr.py
diff --git a/scripts/auxiliar/makelsr.py b/scripts/auxiliar/makelsr.py
index 71c8179f36721a047821e23cd25d9bf20fbe3618..2ad0387c8a0cc88be0257af68c51cb0a10de6fe6 100755
--- a/scripts/auxiliar/makelsr.py
+++ b/scripts/auxiliar/makelsr.py
@@ -117,34 +117,22 @@ if not os.path.isdir (new_lys):
sys.stderr.write ("Error: new snippets path: %s: not a directory\n" % lys_from_lsr)
     sys.exit (3)

-ly_output_ok = False
-if os.path.isdir (options.ly_output):
-    ly_output = options.ly_output
-    ly_output_ok = True
-elif os.path.exists (options.ly_output):
+def find_or_create_temp_dir (requested_dir):
+    if os.path.isdir (requested_dir):
+        return requested_dir
+    if os.path.exists (requested_dir): # maybe a typo; play it safe
+        sys.stderr.write ("Error: %s: not a directory\n" % requested_dir)
+        sys.exit (3)
     try:
-        os.unlink (options.ly_output)
-    except Exception as e:
- sys.stderr.write ("Warning: could not delete file before creating directory: %s\n" % e)
-    else:
-        try:
-            os.makedirs (options.ly_output)
-        except Exception as e:
- sys.stderr.write ("Warning: could not create directory: %s\n" % e)
-        else:
-            ly_output = options.ly_output
-            ly_output_ok = True
-else:
-    try:
-        os.makedirs (options.ly_output)
+        os.makedirs (requested_dir)
+        return requested_dir
     except Exception as e:
         sys.stderr.write ("Warning: could not create directory: %s\n" % e)
-    else:
-        ly_output = options.ly_output
-        ly_output_ok = True
-if not ly_output_ok:
-    ly_output = tempfile.gettempdir ()
- sys.stderr.write ("Warning: could not use or create directory %s, using default %s\n" % (options.ly_output, ly_output))
+    dir = tempfile.gettempdir ()
+ sys.stderr.write ("Warning: could not use or create directory %s, using default %s\n" % (requested_dir, dir))
+    return dir
+
+ly_output = find_or_create_temp_dir (options.ly_output)

 def exit_with_usage (n=0):
     options_parser.print_help (sys.stderr)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]