Use exceptions for error handling
[rarslave2.git] / rsutil / common.py
index 66b7d02..370d7d6 100644 (file)
@@ -29,13 +29,12 @@ __license__   = "GNU GPL v2 (or, at your option, any later version)"
 import os
 import re
 import logging
 import os
 import re
 import logging
+import subprocess
+import exceptions
 
 import rsutil.globals
 import rsutil.par2parser
 
 
 import rsutil.globals
 import rsutil.par2parser
 
-# Global constants
-(SUCCESS, ECHECK, EEXTRACT, EDELETE, ECREATE, EDETECT, EPARSE) = range(7)
-
 def find_matches (regex, li, ignorecase=True):
 
        if ignorecase:
 def find_matches (regex, li, ignorecase=True):
 
        if ignorecase:
@@ -66,14 +65,22 @@ def run_command (cmd, indir=None):
        # Runs the specified command-line in the directory given (or, in the current directory
        # if none is given). It returns the status code given by the application.
 
        # Runs the specified command-line in the directory given (or, in the current directory
        # if none is given). It returns the status code given by the application.
 
-       pwd = os.getcwd ()
-
-       if indir != None:
+       if indir == None:
+               indir = os.getcwd()
+       else:
                assert os.path.isdir (indir) # MUST be a directory!
                assert os.path.isdir (indir) # MUST be a directory!
-               os.chdir (indir)
 
 
-       ret = os.system (cmd)
-       os.chdir (pwd)
+       print 'RUNNING COMMAND'
+       print 'Directory: %s' % indir
+       print 'Command: %s' % cmd[0]
+       for f in cmd[1:]:
+               print '-> %s' % f
+
+       ret = subprocess.Popen(cmd, cwd=indir).wait()
+
+       if ret != 0:
+               raise RuntimeError
+
        return ret
 
 def full_abspath (p):
        return ret
 
 def full_abspath (p):
@@ -143,11 +150,7 @@ def list_eq (l1, l2):
        if len(l1) != len(l2):
                return False
 
        if len(l1) != len(l2):
                return False
 
-       for e in l1:
-               if e not in l2:
-                       return False
-
-       return True
+       return set(l1) == set(l2)
 
 # Convience functions for the config
 
 
 # Convience functions for the config