b872ccf5556b2b1e65c7a73f5317a99044a82d51
[rarslave2.git] / PAR2Set / OldRAR.py
1 #!/usr/bin/env python
2 # vim: set ts=4 sts=4 sw=4 textwidth=92:
3
4 """
5 Holds the OldRAR class.
6
7 This module works with old-style rar sets.
8
9 It will detect sets like the following:
10 X.par2
11 X.vol0+1.par2
12 ...
13
14 Y.rar
15 Y.r00
16 Y.r01
17 ...
18
19 Where the PAR2 files protect all of the rar files. Note that Y can be the same
20 as X, but is not required to be.
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 #    OldRAR.py -- detect and work with old-style rar sets
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
46 import PAR2Set.Base
47 import rsutil.common
48
49
50 def detector (name_files, prot_files):
51         """Detect OldRAR sets"""
52
53         return rsutil.common.has_a_match ('^.*\.r00$', prot_files)
54
55
56 class OldRAR (PAR2Set.Base.Base):
57
58         """Class for working with old-style rar sets"""
59
60         def __repr__ (self):
61                 return 'OLDRAR'
62
63         def find_extraction_heads (self):
64                 """Find the heads of extraction for an old-style rar set"""
65
66                 return rsutil.common.find_matches ('^.*\.rar$', self.all_files)
67
68         def extraction_function (self, file, todir):
69                 """Extract a single rar file to the given directory.
70
71                    file -- the file to extract
72                    todir -- the directory to extract the file to"""
73
74                 assert os.path.isfile (file)
75                 assert os.path.isdir (todir)
76
77                 RAR_CMD = rsutil.common.config_get_value ('commands', 'unrar')
78
79                 cmd = '%s \"%s\"' % (RAR_CMD, file)
80                 ret = rsutil.common.run_command (cmd, todir)
81
82                 # Check error code
83                 if ret != 0:
84                         return -rsutil.common.EEXTRACT
85
86                 return rsutil.common.SUCCESS
87