# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-import re
-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):
- rsutil.common.run_command(['par2repair'] + self.all_p2files + self.find_joinfiles(), self.dir)
+ files = Base.findDeletableFiles(self)
+ files = [f for f in files if f not in self.protectedFiles]
- def find_deleteable_files (self):
- """Find all files which are deletable by using the regular expression from the
- configuration file"""
+ return files
- DELETE_REGEX = rsutil.common.config_get_value ('regular expressions', 'delete_regex')
- dregex = re.compile (DELETE_REGEX, re.IGNORECASE)
+ ############################################################################
- return [f for f in self.all_files if dregex.match (f) and \
- f not in self.prot_matched_files]
-
- 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."""
-
- # The Join type doesn't need any extraction
- pass