X-Git-Url: https://www.irasnyder.com/gitweb/?p=rarslave2.git;a=blobdiff_plain;f=PAR2Set%2FOldRAR.py;h=b139570ca4555b571dbc90d0e03af9f2cdfdecd2;hp=9b1c68a855d571c4e8c9629e94baa41a95077300;hb=3e0a5dd7c7549636eb70c6a641987da66742f1db;hpb=896ca43ecafc98cc2b1045a5ad49adb05dac937c;ds=sidebyside diff --git a/PAR2Set/OldRAR.py b/PAR2Set/OldRAR.py index 9b1c68a..b139570 100644 --- a/PAR2Set/OldRAR.py +++ b/PAR2Set/OldRAR.py @@ -1,54 +1,78 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: -import PAR2Set.Base -import rsutil.common +""" +Holds the OldRAR class. +This module works with old-style rar sets. + +It will detect sets like the following: +X.par2 +X.vol0+1.par2 +... + +Y.rar +Y.r00 +Y.r01 +... + +Where the PAR2 files protect all of the rar files. Note that Y can be the same +as X, but is not required to be. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# OldRAR.py -- detect and work with old-style rar sets # -# This is an old-style rar type -# -# It will detect sets like the following: -# X.par2 -# X.vol0+1.par2 -# X.vol1+2.par2 -# X.rar -# X.r00 -# X.r01 -# -# OR +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) # -# ABC.rar -# ABC.r00 -# ABC.r01 +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# Where the PAR2 files protect all files that do not match in basename -# with the PAR2 file itself. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import os +import PAR2Set.Base +import rsutil.common + def detector (name_files, prot_files): + """Detect OldRAR sets""" + return rsutil.common.has_a_match ('^.*\.r00$', prot_files) class OldRAR (PAR2Set.Base.Base): + """Class for working with old-style rar sets""" + def __repr__ (self): return 'OLDRAR' def find_extraction_heads (self): - return rsutil.common.find_matches ('^.*\.rar', self.all_files) + """Find the heads of extraction for an old-style rar set""" - def extraction_function (self, file, todir): - assert os.path.isfile (file) - assert os.path.isdir (todir) + return rsutil.common.find_matches ('^.*\.rar$', self.all_files) - RAR_CMD = rsutil.common.config_get_value ('commands', 'unrar') + def extraction_function (self, file, todir): + """Extract a single rar file to the given directory. - cmd = '%s \"%s\"' % (RAR_CMD, file) - ret = rsutil.common.run_command (cmd, todir) + file -- the file to extract + todir -- the directory to extract the file to""" - # Check error code - if ret != 0: - return -rsutil.common.EEXTRACT + assert os.path.isfile (file) + assert os.path.isdir (todir) - return rsutil.common.SUCCESS + rsutil.common.run_command(['unrar', 'x', '-o+', file], todir)