Use exceptions for error handling
[rarslave2.git] / rarslave.py
index 7c1b4c8..18bb540 100755 (executable)
@@ -122,17 +122,28 @@ def generate_all_parsets (dir):
 def check_required_progs():
        """Check if the required programs are installed"""
 
-       shell_not_found = 32512
        needed = []
 
-       if rsutil.common.run_command ('par2repair --help > /dev/null 2>&1') == shell_not_found:
-               needed.append ('par2repair')
+       try:
+               rsutil.common.run_command(['par2repair', '--help'])
+       except OSError:
+               needed.append('par2repair')
+       except RuntimeError:
+               pass
 
-       if rsutil.common.run_command ('unrar --help > /dev/null 2>&1') == shell_not_found:
-               needed.append ('unrar')
+       try:
+               rsutil.common.run_command(['unrar', '--help'])
+       except OSError:
+               needed.append('unrar')
+       except RuntimeError:
+               pass
 
-       if rsutil.common.run_command ('unzip --help > /dev/null 2>&1') == shell_not_found:
-               needed.append ('unzip')
+       try:
+               rsutil.common.run_command(['unzip', '--help'])
+       except OSError:
+               needed.append('unzip')
+       except RuntimeError:
+               pass
 
        if needed:
                for n in needed:
@@ -169,6 +180,7 @@ def run_options (options):
 
        if options.check_progs:
                check_required_progs ()
+               sys.exit (0)
 
        if options.write_def_config:
                config.write_config (default=True)
@@ -264,14 +276,14 @@ def main ():
                        parsets = generate_all_parsets (dir)
                        for (p2dir, p2file) in parsets:
                                detector = RarslaveDetector.RarslaveDetector (p2dir, p2file)
-                               ret = detector.runMatchingTypes ()
+                               detector.runMatchingTypes ()
 
        # Non-recursive
        else:
                parsets = generate_all_parsets (options.work_dir)
                for (p2dir, p2file) in parsets:
                        detector = RarslaveDetector.RarslaveDetector (p2dir, p2file)
-                       ret = detector.runMatchingTypes ()
+                       detector.runMatchingTypes ()
 
        # Print the results
        if logger.size () > 0: