2 # vim: set ts=4 sts=4 sw=4 textwidth=92:
10 # This is a regular joined file type
12 # It will detect sets like the following:
20 # Where the PAR2 files protect a file named X.avi (or similar). It will not
21 # work where the PAR2 files are protecting the .001, etc files directly.
24 def detector (name_files, prot_files):
25 return rsutil.common.has_a_match ('^.*\.\d\d\d$', name_files) \
26 and not rsutil.common.has_a_match ('^.*\.\d\d\d$', prot_files)
29 class Join (PAR2Set.Base.Base):
34 def find_joinfiles (self):
35 return rsutil.common.find_matches ('^.*\.\d\d\d$', self.name_matched_files)
37 def runVerifyAndRepair (self):
38 PAR2_CMD = rsutil.common.config_get_value ('commands', 'par2repair')
40 # assemble the command
41 # par2repair -- PAR2 PAR2_EXTRA [JOIN_FILES]
42 command = "%s \"%s\" " % (PAR2_CMD, self.p2file)
44 for f in self.all_p2files:
46 command += "\"%s\" " % os.path.split (f)[1]
48 for f in self.find_joinfiles ():
49 command += "\"%s\" " % os.path.split (f)[1]
52 ret = rsutil.common.run_command (command, self.dir)
56 logging.critical ('PAR2 Check / Repair failed: %s' % self.p2file)
57 return -rsutil.common.ECHECK
59 return rsutil.common.SUCCESS
61 def find_extraction_heads (self):
62 return self.prot_matched_files
64 def extraction_function (self, file, todir):
65 """Extract a single file of this type to the given directory"""
67 NOEXTRACT_CMD = rsutil.common.config_get_value ('commands', 'noextract')
69 # Make sure that both files are not the same file. If they are, don't run at all.
70 if os.path.samefile (file, os.path.join (todir, file)):
71 return rsutil.common.SUCCESS
73 cmd = NOEXTRACT_CMD % (file, todir)
74 ret = rsutil.common.run_command (cmd)
78 return -rsutil.common.EEXTRACT
80 return rsutil.common.SUCCESS