Add Copyright / License information + Documentation
[rarslave2.git] / PAR2Set / ExtractFirstNewRAR.py
1 #!/usr/bin/env python
2 # vim: set ts=4 sts=4 sw=4 textwidth=92:
3
4 """
5 Holds the ExtractFirstNewRAR class.
6
7 This module works with new-style rar sets which need to be extracted
8 before they are verified.
9
10 It will detect sets like the following:
11 X.par2
12 X.vol0+1.par2
13 ...
14
15 X.part01.rar
16 X.part02.rar
17 ...
18
19 Where the PAR2 files do not protect the rar files directly, but instead
20 protect the files contained inside the rar files.
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 #    ExtractFirstNewRAR.py -- detect and work with a new-style rar set
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 PAR2Set.ExtractFirstBase
46 import PAR2Set.NewRAR
47 import rsutil.common
48
49
50 def detector (name_files, prot_files):
51         """Detects a ExtractFirstNewRAR set"""
52
53         return rsutil.common.has_a_match ('^.*\.part0*1\.rar$', name_files) \
54                         and not rsutil.common.has_a_match ('^.*\.part0*1\.rar$', prot_files)
55
56
57 class ExtractFirstNewRAR (PAR2Set.ExtractFirstBase.ExtractFirstBase, \
58                 PAR2Set.NewRAR.NewRAR):
59
60         """Class for new-style rar sets which must be extracted before repair"""
61
62         def __repr__ (self):
63                 return 'EXTRACTFIRST NEWRAR'
64