Major Update
[rarslave2.git] / PAR2Set / Join.py
1 #!/usr/bin/env python
2 # vim: set ts=4 sts=4 sw=4 textwidth=92:
3
4 """
5 Holds the Join class.
6
7 This module works with normal joined sets.
8
9 It will detect sets like the following:
10 X.par2
11 X.vol0+1.par2
12 ...
13
14 X.001
15 X.002
16 ...
17
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
20 directly.
21 """
22
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)"
26
27 #    Join.py
28 #
29 #    Copyright (C) 2006,2007  Ira W. Snyder (devel@irasnyder.com)
30 #
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.
35 #
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.
40 #
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
44
45 import os, re, logging
46 from PAR2Set import Base, utils
47
48 class Join(Base):
49
50     ############################################################################
51
52     def detect(self):
53
54         regex = r'^.*\.\d\d\d$'
55         m1 = utils.hasAMatch(regex, self.similarlyNamedFiles)
56         m2 = utils.hasAMatch(regex, self.protectedFiles)
57
58         # This is a good match if this criteria is met
59         if m1 and not m2:
60             return
61
62         raise TypeError
63
64     ############################################################################
65
66     def repair(self):
67
68         regex = r'^.*\.\d\d\d$'
69         files = utils.findMatches(regex, self.similarlyNamedFiles)
70         utils.runCommand(['par2repair'] + self.PAR2Files + files, self.directory)
71
72     ############################################################################
73
74     def findDeletableFiles(self):
75
76         files = Base.findDeletableFiles(self)
77         files = [f for f in files if f not in self.protectedFiles]
78
79         return files
80
81     ############################################################################
82