Add support for Join sets where the parity protects the split files
[rarslave2.git] / PAR2Set / NoExtract.py
1 #!/usr/bin/env python
2 # vim: set ts=4 sts=4 sw=4 textwidth=92:
3
4 """
5 Holds the NoExtract class.
6
7 This module works with sets that only need to repair and delete, and do
8 not need any extraction.
9
10 It will detect sets like the following:
11 X.par2
12 X.vol0+1.par2
13 ...
14
15 01.mp3
16 02.mp3
17 ...
18
19 Where the PAR2 files protect the mp3 files directly.
20
21 NOTE: It doesn't just detect mp3's, it will detect any set that does not
22 NOTE: have any extractable elements in it.
23 """
24
25 __author__    = "Ira W. Snyder (devel@irasnyder.com)"
26 __copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)"
27 __license__   = "GNU GPL v2 (or, at your option, any later version)"
28
29 #    NoExtract.py
30 #
31 #    Copyright (C) 2006,2007  Ira W. Snyder (devel@irasnyder.com)
32 #
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.
37 #
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.
42 #
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
46
47 from PAR2Set import Base, utils
48
49 class NoExtract(Base):
50
51     ############################################################################
52
53     def detect(self):
54
55         regex = r'^.+\.(rar|r\d\d|\d\d\d|zip)$'
56
57         # This set has no extractable files
58         if utils.hasAMatch(regex, self.protectedFiles):
59             raise TypeError
60
61     ############################################################################
62
63     # A NoExtract set is very different from the other types of sets in terms
64     # of filesystem state. It is very likely that normal name matching will not
65     # work correctly.
66     #
67     # We override this to try to match on every name that is protected by this set,
68     # which will detect the .1 files that are produced when repairing
69     def updateFilesystemState(self):
70
71         self.similarlyNamedFiles = utils.findFileNameMatches(self.directory, self.baseName)
72
73         # Find extra name matched files
74         for f in self.protectedFiles:
75             baseName = utils.getBasename(f)
76             matches = utils.findFileNameMatches(self.directory, baseName)
77
78             self.similarlyNamedFiles += matches
79
80         # Remove all duplicates
81         self.similarlyNamedFiles = list(set(self.similarlyNamedFiles))
82
83         # Update the allFiles set
84         self.allFiles = set(self.similarlyNamedFiles + self.protectedFiles)
85
86     ############################################################################
87