2 # vim: set ts=4 sts=4 sw=4 textwidth=92:
4 """Holds the NewRAR class.
6 This is a new-style rar type.
8 It will detect sets like the following:
17 Where the PAR2 files protect the rar files directly. Y can (but is not required
21 __author__ = "Ira W. Snyder (devel@irasnyder.com)"
22 __copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)"
23 __license__ = "GNU GPL v2 (or, at your option, any later version)"
25 # NewRAR.py -- detect and work with a new-style rar set
27 # Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com)
29 # This program is free software; you can redistribute it and/or modify
30 # it under the terms of the GNU General Public License as published by
31 # the Free Software Foundation; either version 2 of the License, or
32 # (at your option) any later version.
34 # This program is distributed in the hope that it will be useful,
35 # but WITHOUT ANY WARRANTY; without even the implied warranty of
36 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 # GNU General Public License for more details.
39 # You should have received a copy of the GNU General Public License
40 # along with this program; if not, write to the Free Software
41 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
48 def detector (name_files, prot_files):
49 """Detector for the NewRAR type"""
51 return rsutil.common.has_a_match ('^.*\.part0*1\.rar$', prot_files)
54 class NewRAR (PAR2Set.Base.Base):
56 """Class for new-style rar sets"""
61 def find_extraction_heads (self):
62 """Find the files to start extraction from. These end in '.part0*1.rar'"""
64 return rsutil.common.find_matches ('^.*\.part0*1\.rar$', self.all_files)
66 def extraction_function (self, file, todir):
67 """Extract a single rar file to the directory todir.
69 file -- the file to be extracted
70 todir -- the directory to extract into"""
72 assert os.path.isfile (file)
73 assert os.path.isdir (todir)
75 RAR_CMD = rsutil.common.config_get_value ('commands', 'unrar')
77 cmd = '%s \"%s\"' % (RAR_CMD, file)
78 ret = rsutil.common.run_command (cmd, todir)
82 return -rsutil.common.EEXTRACT
84 return rsutil.common.SUCCESS