--- /dev/null
+#!/usr/bin/env python
+# vim: set ts=4 sts=4 sw=4 textwidth=92:
+
+import logging
+import PAR2Set
+from RarslaveCommon import *
+
+#
+# This is a regular joined file type
+#
+# It will detect sets like the following:
+# X.par2
+# X.vol0+1.par2
+# X.vol1+2.par2
+# X.001
+# X.002
+# X.003
+#
+# Where the PAR2 files protect a file named X.avi (or similar). It will not
+# work where the PAR2 files are protecting the .001, etc files directly.
+#
+
+def detect_JOIN (name_files, prot_files):
+ return has_a_match ('^.*\.\d\d\d$', name_files) \
+ and not has_a_match ('^.*\.\d\d\d$', prot_files)
+
+
+class PAR2Set_JOIN (PAR2Set.PAR2Set):
+
+ def __repr__ (self):
+ return 'JOIN'
+
+ def find_joinfiles (self):
+ return find_matches ('^.*\.\d\d\d$', self.name_matched_files)
+
+ def runVerifyAndRepair (self):
+ PAR2_CMD = config_get_value ('commands', 'par2repair')
+
+ # assemble the command
+ # par2repair -- PAR2 PAR2_EXTRA [JOIN_FILES]
+ command = "%s \"%s\" " % (PAR2_CMD, self.p2file)
+
+ for f in self.all_p2files:
+ if f != self.p2file:
+ command += "\"%s\" " % os.path.split (f)[1]
+
+ for f in self.find_joinfiles ():
+ command += "\"%s\" " % os.path.split (f)[1]
+
+ # run the command
+ ret = run_command (command, self.dir)
+
+ # check the result
+ if ret != 0:
+ logging.critical ('PAR2 Check / Repair failed: %s' % self.p2file)
+ return -ECHECK
+
+ return SUCCESS
+
+ def find_extraction_heads (self):
+ return self.prot_matched_files
+
+ def extraction_function (self, file, todir):
+ """Extract a single file of this type to the given directory"""
+
+ NOEXTRACT_CMD = config_get_value ('commands', 'noextract')
+
+ # Make sure that both files are not the same file. If they are, don't run at all.
+ if os.path.samefile (file, os.path.join (todir, file)):
+ return SUCCESS
+
+ cmd = NOEXTRACT_CMD % (file, todir)
+ ret = run_command (cmd)
+
+ # Check error code
+ if ret != 0:
+ return -EEXTRACT
+
+ return SUCCESS
+