2 # vim: set ts=4 sts=4 sw=4 textwidth=92:
7 This module works with normal joined sets.
9 It will detect sets like the following:
18 Where the PAR2 files protect a file named X.avi, or similar other types.
19 It will not work where the PAR2 files are protecting the X.001, etc files
23 __author__ = "Ira W. Snyder (devel@irasnyder.com)"
24 __copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)"
25 __license__ = "GNU GPL v2 (or, at your option, any later version)"
29 # Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com)
31 # This program is free software; you can redistribute it and/or modify
32 # it under the terms of the GNU General Public License as published by
33 # the Free Software Foundation; either version 2 of the License, or
34 # (at your option) any later version.
36 # This program is distributed in the hope that it will be useful,
37 # but WITHOUT ANY WARRANTY; without even the implied warranty of
38 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 # GNU General Public License for more details.
41 # You should have received a copy of the GNU General Public License
42 # along with this program; if not, write to the Free Software
43 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
51 def detector (name_files, prot_files):
52 """Detects a Join set"""
54 return rsutil.common.has_a_match ('^.*\.\d\d\d$', name_files) \
55 and not rsutil.common.has_a_match ('^.*\.\d\d\d$', prot_files)
58 class Join (PAR2Set.Base.Base):
60 """Class for normal joined-file sets"""
65 def find_joinfiles (self):
66 """Finds files which contain data to be joined together"""
68 return rsutil.common.find_matches ('^.*\.\d\d\d$', self.name_matched_files)
70 def runVerifyAndRepair (self):
71 """Verify and Repair a PAR2Set. This version extends the PAR2Set.Base.Base
72 version by adding the datafiles to be joined at the end of the command
75 This is done using the par2repair command by default"""
77 PAR2_CMD = rsutil.common.config_get_value ('commands', 'par2repair')
79 # assemble the command
80 # par2repair -- PAR2 PAR2_EXTRA [JOIN_FILES]
81 command = "%s \"%s\" " % (PAR2_CMD, self.p2file)
83 for f in self.all_p2files:
85 command += "\"%s\" " % os.path.split (f)[1]
87 for f in self.find_joinfiles ():
88 command += "\"%s\" " % os.path.split (f)[1]
91 ret = rsutil.common.run_command (command, self.dir)
95 logging.critical ('PAR2 Check / Repair failed: %s' % self.p2file)
96 return -rsutil.common.ECHECK
98 return rsutil.common.SUCCESS
100 def find_extraction_heads (self):
101 """Find the extraction heads. Since this should not be an extractable set,
102 we return the files which are protected directly by the PAR2 files."""
104 return self.prot_matched_files
106 def extraction_function (self, file, todir):
107 """Extract a single file of the Join type.
109 file -- the file to extract
110 todir -- the directory to extract to
112 This command ignores the extraction if file and todir+file are the same
113 file. This keeps things like mv working smoothly."""
115 NOEXTRACT_CMD = rsutil.common.config_get_value ('commands', 'noextract')
117 # Make sure that both files are not the same file. If they are, don't run at all.
118 if os.path.samefile (file, os.path.join (todir, file)):
119 return rsutil.common.SUCCESS
121 cmd = NOEXTRACT_CMD % (file, todir)
122 ret = rsutil.common.run_command (cmd)
126 return -rsutil.common.EEXTRACT
128 return rsutil.common.SUCCESS