#!/usr/bin/env python
# vim: set ts=4 sts=4 sw=4 textwidth=92:
-import logging
-import PAR2Set.Base
-import rsutil.common
+"""
+Holds the NoExtract class.
+This module works with sets that only need to repair and delete, and do
+not need any extraction.
+
+It will detect sets like the following:
+X.par2
+X.vol0+1.par2
+...
+
+01.mp3
+02.mp3
+...
+
+Where the PAR2 files protect the mp3 files directly.
+
+NOTE: It doesn't just detect mp3's, it will detect any set that does not
+NOTE: have any extractable elements in it.
+"""
+
+__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)"
+
+# NoExtract.py
#
-# This is a class that will only repair and delete, not extract
+# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com)
#
-# It will detect sets like the following:
-# X.par2
-# X.vol0+1.par2
-# X.vol1+2.par2
-# 01.mp3
-# 02.mp3
-# 03.mp3
+# 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 the mp3 files.
+# 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
+
+from PAR2Set import Base, utils
+
+class NoExtract(Base):
+
+ ############################################################################
-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)
+ def detect(self):
+ regex = r'^.+\.(rar|r\d\d|\d\d\d|zip)$'
-class NoExtract (PAR2Set.Base.Base):
+ # This set has no extractable files
+ if utils.hasAMatch(regex, self.protectedFiles):
+ raise TypeError
- def __repr__ (self):
- return 'NoExtract'
+ ############################################################################
- def runAll (self):
+ # A NoExtract set is very different from the other types of sets in terms
+ # of filesystem state. It is very likely that normal name matching will not
+ # work correctly.
+ #
+ # We override this to try to match on every name that is protected by this set,
+ # which will detect the .1 files that are produced when repairing
+ def updateFilesystemState(self):
- # Repair Stage
- ret = self.runVerifyAndRepair ()
+ self.similarlyNamedFiles = utils.findFileNameMatches(self.directory, self.baseName)
- if ret != rsutil.common.SUCCESS:
- logging.critical ('Repair stage failed for: %s' % self.p2file)
- return -rsutil.common.ECHECK
+ # Find extra name matched files
+ for f in self.protectedFiles:
+ baseName = utils.getBasename(f)
+ matches = utils.findFileNameMatches(self.directory, baseName)
- self.update_matches ()
+ self.similarlyNamedFiles += matches
- # Deletion Stage
- ret = self.runDelete ()
+ # Remove all duplicates
+ self.similarlyNamedFiles = list(set(self.similarlyNamedFiles))
- if ret != rsutil.common.SUCCESS:
- logging.critical ('Deletion stage failed for: %s' % self.p2file)
- return -rsutil.common.EDELETE
+ # Update the allFiles set
+ self.allFiles = set(self.similarlyNamedFiles + self.protectedFiles)
- logging.info ('Successfully completed: %s' % self.p2file)
- return rsutil.common.SUCCESS
+ ############################################################################