Support use with python version 2.4
[grml2usb.git] / grml2usb
index fd03ef9..fd6dc17 100755 (executable)
--- a/grml2usb
+++ b/grml2usb
@@ -12,7 +12,7 @@ This script installs a grml system (either a running system or ISO[s]) to a USB
 
 """
 
 
 """
 
-from __future__ import with_statement
+from __future__ import with_statement
 from optparse import OptionParser
 from inspect import isroutine, isclass
 import datetime, logging, os, re, subprocess, sys, tempfile, time
 from optparse import OptionParser
 from inspect import isroutine, isclass
 import datetime, logging, os, re, subprocess, sys, tempfile, time
@@ -612,20 +612,21 @@ def install_grub(device):
         device_mountpoint = tempfile.mkdtemp(prefix="grml2usb")
         register_tmpfile(device_mountpoint)
         try:
         device_mountpoint = tempfile.mkdtemp(prefix="grml2usb")
         register_tmpfile(device_mountpoint)
         try:
-            mount(device, device_mountpoint, "")
-            logging.debug("grub-install --recheck --no-floppy --root-directory=%s %s", device_mountpoint, device)
-            proc = subprocess.Popen(["grub-install", "--recheck", "--no-floppy",
-                "--root-directory=%s" % device_mountpoint, device], stdout=file(os.devnull, "r+"))
-            proc.wait()
-            if proc.returncode != 0:
-                # raise Exception("error executing grub-install")
-                logging.critical("Fatal: error executing grub-install (please check the grml2usb FAQ)")
+            try:
+                mount(device, device_mountpoint, "")
+                logging.debug("grub-install --recheck --no-floppy --root-directory=%s %s", device_mountpoint, device)
+                proc = subprocess.Popen(["grub-install", "--recheck", "--no-floppy",
+                    "--root-directory=%s" % device_mountpoint, device], stdout=file(os.devnull, "r+"))
+                proc.wait()
+                if proc.returncode != 0:
+                    # raise Exception("error executing grub-install")
+                    logging.critical("Fatal: error executing grub-install (please check the grml2usb FAQ)")
+                    cleanup()
+                    sys.exit(1)
+            except CriticalException, error:
+                logging.critical("Fatal: %s" % error)
                 cleanup()
                 sys.exit(1)
                 cleanup()
                 sys.exit(1)
-        except CriticalException, error:
-            logging.critical("Fatal: %s" % error)
-            cleanup()
-            sys.exit(1)
 
         finally:
             unmount(device_mountpoint, "")
 
         finally:
             unmount(device_mountpoint, "")
@@ -1479,12 +1480,13 @@ def handle_dir(live_image, device):
             sys.exit(1)
 
     try:
             sys.exit(1)
 
     try:
-        grml_flavour = identify_grml_flavour(live_image)
-        logging.info("Identified grml flavour \"%s\"." % grml_flavour)
-        install_iso_files(grml_flavour, live_image, device, device_mountpoint)
-    except TypeError:
-        logging.critical("Fatal: a critical error happend during execution (not a grml ISO?), giving up")
-        sys.exit(1)
+        try:
+            grml_flavour = identify_grml_flavour(live_image)
+            logging.info("Identified grml flavour \"%s\"." % grml_flavour)
+            install_iso_files(grml_flavour, live_image, device, device_mountpoint)
+        except TypeError:
+            logging.critical("Fatal: a critical error happend during execution (not a grml ISO?), giving up")
+            sys.exit(1)
     finally:
         if remove_device_mountpoint:
             try:
     finally:
         if remove_device_mountpoint:
             try:
@@ -1537,12 +1539,13 @@ def handle_iso(iso, device):
             sys.exit(1)
 
     try:
             sys.exit(1)
 
     try:
-        grml_flavour = identify_grml_flavour(iso_mountpoint)
-        logging.info("Identified grml flavour \"%s\"." % grml_flavour)
-        install_iso_files(grml_flavour, iso_mountpoint, device, device_mountpoint)
-    except TypeError:
-        logging.critical("Fatal: a critical error happend during execution (not a grml ISO?), giving up")
-        sys.exit(1)
+        try:
+            grml_flavour = identify_grml_flavour(iso_mountpoint)
+            logging.info("Identified grml flavour \"%s\"." % grml_flavour)
+            install_iso_files(grml_flavour, iso_mountpoint, device, device_mountpoint)
+        except TypeError:
+            logging.critical("Fatal: a critical error happend during execution (not a grml ISO?), giving up")
+            sys.exit(1)
     finally:
         if os.path.isdir(iso_mountpoint) and remove_iso_mountpoint:
             unmount(iso_mountpoint, "")
     finally:
         if os.path.isdir(iso_mountpoint) and remove_iso_mountpoint:
             unmount(iso_mountpoint, "")