2 # vim: set ts=4 sts=4 sw=4 textwidth=92:
5 Holds the JoinProtected class.
7 This module works with joined sets where the joined files are
8 protected directly by the PAR2 files.
10 It will detect sets like the following:
19 Where the PAR2 files protect a file named X.001, etc. It works in the case
20 that the PAR2 files are protecting the X.001, etc. files directly.
22 It currently whitelists a number of media formats that can be protected.
25 __author__ = "Ira W. Snyder (devel@irasnyder.com)"
26 __copyright__ = "Copyright (c) 2014 Ira W. Snyder (devel@irasnyder.com)"
27 __license__ = "GNU GPL v2 (or, at your option, any later version)"
31 # Copyright (C) 2014 Ira W. Snyder (devel@irasnyder.com)
33 # This program is free software; you can redistribute it and/or modify
34 # it under the terms of the GNU General Public License as published by
35 # the Free Software Foundation; either version 2 of the License, or
36 # (at your option) any later version.
38 # This program is distributed in the hope that it will be useful,
39 # but WITHOUT ANY WARRANTY; without even the implied warranty of
40 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 # GNU General Public License for more details.
43 # You should have received a copy of the GNU General Public License
44 # along with this program; if not, write to the Free Software
45 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47 import os, re, logging
48 from PAR2Set import Base, utils
50 class JoinProtected(Base):
52 ############################################################################
54 # find all prefixes in the protected set by stripping the extension off
56 def getPrefixes(self):
59 for f in self.protectedFiles:
60 prefix, extension = os.path.splitext(f)
66 ############################################################################
70 # check to see that there are joined files in the set
71 regex = r'^.*\.\d\d\d$'
72 if not utils.hasAMatch(regex, self.protectedFiles):
75 # This is a good match if this criteria is met
76 prefixes = self.getPrefixes()
77 if len(prefixes) == 1:
82 ############################################################################
86 regex = r'^.*\.\d\d\d$'
87 files = utils.findMatches(regex, self.protectedFiles)
88 utils.runCommand(['par2repair'] + self.PAR2Files + files, self.directory)
90 ############################################################################
94 # we guaranteed there is exactly one prefix during detection
95 filename = self.getPrefixes()[0]
97 regex = r'^.*\.\d\d\d$'
98 files = utils.findMatches(regex, self.protectedFiles)
100 # concatenate all '.001' files into a single output file
101 with open(filename, 'wb') as f:
102 utils.runCommand(['cat'] + files, self.directory, stdout=f)
104 ############################################################################
106 def findDeletableFiles(self):
108 prefixes = self.getPrefixes()
110 files = Base.findDeletableFiles(self)
111 files = [f for f in files if f not in prefixes]
115 ############################################################################