[RARSLAVE] Fix extraction
[rarslave2.git] / rarslave.py
index 53f0b41..2e9861a 100644 (file)
@@ -23,11 +23,11 @@ class RarslaveExtractor (object):
 
                self.heads.append (os.path.join (dir, head))
 
-       def extract (self, todir):
+       def extract (self, todir=None):
                # Extract all heads of this set
 
                # Create the directory $todir if it doesn't exist
-               if not os.path.isdir (todir):
+               if todir != None and not os.path.isdir (todir):
                        # TODO: LOGGER
                        try:
                                os.makedirs (todir)
@@ -44,7 +44,11 @@ class RarslaveExtractor (object):
 
                # Call the extraction function on each head
                for h in self.heads:
-                       extraction_func (h, todir)
+                       if todir == None:
+                               # Run in the head's directory
+                               extraction_func (h, os.path.dirname (h))
+                       else:
+                               extraction_func (h, todir)
 
        def __extract_rar (self, file, todir):
                assert os.path.isfile (file)
@@ -133,7 +137,7 @@ def run_command (cmd, indir=None):
 
        if indir != None:
                assert os.path.isdir (indir) # MUST be a directory!
-               os.chdir (pwd)
+               os.chdir (indir)
 
        # FIXME: re-enable this after testing
        print 'RUNNING (%s): %s' % (indir, cmd)