X-Git-Url: https://www.irasnyder.com/gitweb/?p=rarslave2.git;a=blobdiff_plain;f=PAR2Set%2FNewRAR.py;h=7c8f25b0f6222773c60e5738daf62ab7fee2d6b1;hp=272700a90bd71953f627790294c3ab939cfd8e36;hb=3e0a5dd7c7549636eb70c6a641987da66742f1db;hpb=896ca43ecafc98cc2b1045a5ad49adb05dac937c diff --git a/PAR2Set/NewRAR.py b/PAR2Set/NewRAR.py index 272700a..7c8f25b 100644 --- a/PAR2Set/NewRAR.py +++ b/PAR2Set/NewRAR.py @@ -1,54 +1,76 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: -import PAR2Set.Base -import rsutil.common +"""Holds the NewRAR class. +This is a new-style rar type. + +It will detect sets like the following: +X.par2 +X.vol0+1.par2 +... + +Y.part01.rar +Y.part02.rar +... + +Where the PAR2 files protect the rar files directly. Y can (but is not required +to be) the same as X. +""" + +__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)" + +# NewRAR.py -- detect and work with a new-style rar set # -# This is an new-style rar type -# -# It will detect sets like the following: -# X.par2 -# X.vol0+1.par2 -# X.vol1+2.par2 -# X.part01.rar -# X.part02.rar -# X.part03.rar -# -# OR +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) # -# ABC.part01.rar -# ABC.part02.rar -# ABC.part03.rar +# 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): + """Detector for the NewRAR type""" + return rsutil.common.has_a_match ('^.*\.part0*1\.rar$', prot_files) class NewRAR (PAR2Set.Base.Base): + """Class for new-style rar sets""" + def __repr__ (self): return 'NEWRAR' def find_extraction_heads (self): + """Find the files to start extraction from. These end in '.part0*1.rar'""" + return rsutil.common.find_matches ('^.*\.part0*1\.rar$', self.all_files) def extraction_function (self, file, todir): - assert os.path.isfile (file) - assert os.path.isdir (todir) - - RAR_CMD = rsutil.common.config_get_value ('commands', 'unrar') + """Extract a single rar file to the directory todir. - cmd = '%s \"%s\"' % (RAR_CMD, file) - ret = rsutil.common.run_command (cmd, todir) + file -- the file to be extracted + todir -- the directory to extract into""" - # 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)