+ # Just move this file to the $todir, since no extraction is needed
+ # FIXME: NOTE: mv will fail by itself if you're moving to the same dir!
+ cmd = 'mv \"%s\" \"%s\"' % (file, todir)
+ ret = run_command (cmd)
+
+
+
+class RarslaveRepairer (object):
+ # Verify (and repair) the set
+ # Make sure it worked, otherwise clean up and return failure
+
+ def __init__ (self, dir, file, join=False):
+ self.dir = dir # the directory containing the par2 file
+ self.file = file # the par2 file
+ self.join = join # True if the par2 set is 001 002 ...
+
+ assert os.path.isdir (dir)
+ assert os.path.isfile (os.path.join (dir, file))
+
+ def checkAndRepair (self):
+ # Form the command:
+ # par2repair -- PAR2 PAR2_EXTRA [JOIN_FILES]
+ PAR2_CMD = 'par2repair -- '
+
+ # Get set up
+ basename = get_basename (self.file)
+ all_files = find_likely_files (basename, self.dir)
+ all_files.sort ()
+ par2_files = find_par2_files (all_files)
+
+ # assemble the command
+ command = "%s \"%s\" " % (PAR2_CMD, self.file)
+
+ for f in par2_files:
+ if f != self.file:
+ command += "\"%s\" " % get_filename(f)
+
+ if self.join:
+ for f in all_files:
+ if f not in par2_files:
+ command += "\"%s\" " % get_filename(f)
+
+ # run the command
+ ret = run_command (command, self.dir)
+
+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.
+
+ pwd = os.getcwd ()
+
+ if indir != None:
+ assert os.path.isdir (indir) # MUST be a directory!
+ os.chdir (pwd)
+
+ # FIXME: re-enable this after testing
+ print 'RUNNING (%s): %s' % (indir, cmd)
+ # return os.system (cmd)
+
+
+def full_abspath (p):
+ return os.path.abspath (os.path.expanduser (p))