From: Ira W. Snyder Date: Tue, 2 Jan 2007 01:07:09 +0000 (-0800) Subject: Add NoExtract detector X-Git-Tag: v2.0.0~9 X-Git-Url: https://www.irasnyder.com/gitweb/?p=rarslave2.git;a=commitdiff_plain;h=005129118bcc031f57c57d39ba8b05ed1842c47c Add NoExtract detector Add a new PAR2Set-derived detector which will detect types that are not extractable, and should be repaired only. Signed-off-by: Ira W. Snyder --- diff --git a/PAR2Set/NoExtract.py b/PAR2Set/NoExtract.py new file mode 100644 index 0000000..ce2fdfa --- /dev/null +++ b/PAR2Set/NoExtract.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# vim: set ts=4 sts=4 sw=4 textwidth=92: + +import logging +import PAR2Set.Base +import rsutil.common + +# +# This is a class that will only repair and delete, not extract +# +# It will detect sets like the following: +# X.par2 +# X.vol0+1.par2 +# X.vol1+2.par2 +# 01.mp3 +# 02.mp3 +# 03.mp3 +# +# Where the PAR2 files protect the mp3 files. +# + +def detector (name_files, prot_files): + EXTRACT_REGEX = rsutil.common.config_get_value ('regular expressions', 'extractable_regex') + return not rsutil.common.has_a_match (EXTRACT_REGEX, prot_files) + + +class NoExtract (PAR2Set.Base.Base): + + def __repr__ (self): + return 'NoExtract' + + def runAll (self): + + # Repair Stage + ret = self.runVerifyAndRepair () + + if ret != rsutil.common.SUCCESS: + logging.critical ('Repair stage failed for: %s' % self.p2file) + return -rsutil.common.ECHECK + + self.update_matches () + + # Deletion Stage + ret = self.runDelete () + + if ret != rsutil.common.SUCCESS: + logging.critical ('Deletion stage failed for: %s' % self.p2file) + return -rsutil.common.EDELETE + + logging.info ('Successfully completed: %s' % self.p2file) + return rsutil.common.SUCCESS + diff --git a/PAR2Set/__init__.py b/PAR2Set/__init__.py index f42d2ad..753613e 100644 --- a/PAR2Set/__init__.py +++ b/PAR2Set/__init__.py @@ -15,9 +15,10 @@ import Join import NewRAR import OldRAR import ZIP +import NoExtract __all__ = ['Base', 'ExtractFirstBase', 'ExtractFirstNewRAR', 'ExtractFirstOldRAR', 'Join', - 'NewRAR', 'OldRAR', 'ZIP'] + 'NewRAR', 'OldRAR', 'ZIP', 'NoExtract'] def main (): pass diff --git a/RarslaveDetector.py b/RarslaveDetector.py index 08a0b66..0895e46 100644 --- a/RarslaveDetector.py +++ b/RarslaveDetector.py @@ -10,6 +10,7 @@ import PAR2Set.OldRAR import PAR2Set.NewRAR import PAR2Set.ExtractFirstOldRAR import PAR2Set.ExtractFirstNewRAR +import PAR2Set.NoExtract import logging @@ -24,6 +25,7 @@ class RarslaveDetector (object): (PAR2Set.NewRAR.detector, PAR2Set.NewRAR.NewRAR), (PAR2Set.ExtractFirstOldRAR.detector, PAR2Set.ExtractFirstOldRAR.ExtractFirstOldRAR), (PAR2Set.ExtractFirstNewRAR.detector, PAR2Set.ExtractFirstNewRAR.ExtractFirstNewRAR), + (PAR2Set.NoExtract.detector, PAR2Set.NoExtract.NoExtract), ) def __init__ (self, dir, p2file): diff --git a/rsutil/config.py b/rsutil/config.py index 17e87d3..e0ab710 100644 --- a/rsutil/config.py +++ b/rsutil/config.py @@ -124,6 +124,8 @@ class config (object): '^.*\.(par2|\d|\d\d\d|rar|r\d\d|zip)$', ('regular expressions', 'basename_regex') : '^(.+)\.(par2|vol\d+\+\d+|\d\d\d|part\d+|rar|zip|avi|mp4|mkv|ogm)$', + ('regular expressions', 'extractable_regex') : + '^.+\.(rar|r\d\d|\d\d\d|zip)$', ('commands', 'unrar') : 'unrar x -o+ -- ', ('commands', 'unzip') : 'unzip \"%s\" -d \"%s\" ', ('commands', 'noextract') : 'mv \"%s\" \"%s\" ',