# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-import os
-import logging
-import PAR2Set.Base
-import rsutil.common
+import os, re, logging
+from PAR2Set import Base, utils
+class Join(Base):
-def detector (name_files, prot_files):
- """Detects a Join set"""
+ ############################################################################
- return rsutil.common.has_a_match ('^.*\.\d\d\d$', name_files) \
- and not rsutil.common.has_a_match ('^.*\.\d\d\d$', prot_files)
+ def detect(self):
+ regex = r'^.*\.\d\d\d$'
+ m1 = utils.hasAMatch(regex, self.similarlyNamedFiles)
+ m2 = utils.hasAMatch(regex, self.protectedFiles)
-class Join (PAR2Set.Base.Base):
+ # This is a good match if this criteria is met
+ if m1 and not m2:
+ return
- """Class for normal joined-file sets"""
+ raise TypeError
- def __repr__ (self):
- return 'JOIN'
+ ############################################################################
- def find_joinfiles (self):
- """Finds files which contain data to be joined together"""
+ def repair(self):
- return rsutil.common.find_matches ('^.*\.\d\d\d$', self.name_matched_files)
+ regex = r'^.*\.\d\d\d$'
+ files = utils.findMatches(regex, self.similarlyNamedFiles)
+ utils.runCommand(['par2repair'] + self.PAR2Files + files, self.directory)
- def runVerifyAndRepair (self):
- """Verify and Repair a PAR2Set. This version extends the PAR2Set.Base.Base
- version by adding the datafiles to be joined at the end of the command
- line.
+ ############################################################################
- This is done using the par2repair command by default"""
+ def findDeletableFiles(self):
- PAR2_CMD = rsutil.common.config_get_value ('commands', 'par2repair')
+ files = Base.findDeletableFiles(self)
+ files = [f for f in files if f not in self.protectedFiles]
- # assemble the command
- # par2repair -- PAR2 PAR2_EXTRA [JOIN_FILES]
- command = "%s \"%s\" " % (PAR2_CMD, self.p2file)
+ return files
- 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 = rsutil.common.run_command (command, self.dir)
-
- # check the result
- if ret != 0:
- logging.critical ('PAR2 Check / Repair failed: %s' % self.p2file)
- return -rsutil.common.ECHECK
-
- return rsutil.common.SUCCESS
-
- def find_extraction_heads (self):
- """Find the extraction heads. Since this should not be an extractable set,
- we return the files which are protected directly by the PAR2 files."""
-
- return self.prot_matched_files
-
- def extraction_function (self, file, todir):
- """Extract a single file of the Join type.
-
- file -- the file to extract
- todir -- the directory to extract to
-
- This command ignores the extraction if file and todir+file are the same
- file. This keeps things like mv working smoothly."""
-
- NOEXTRACT_CMD = rsutil.common.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 rsutil.common.SUCCESS
-
- cmd = NOEXTRACT_CMD % (file, todir)
- ret = rsutil.common.run_command (cmd)
-
- # Check error code
- if ret != 0:
- return -rsutil.common.EEXTRACT
-
- return rsutil.common.SUCCESS
+ ############################################################################