#!/usr/bin/env python
-# vim: set ts=4 sts=4 sw=4 textwidth=92:
+# vim: set ts=4 sts=4 sw=4 textwidth=80:
-import PAR2Set.Base
-import rsutil.common
+"""
+Holds the ZIP class.
+This module works with regular zip file sets.
+
+It will detect sets like the following:
+X.par2
+X.vol0+1.par2
+...
+
+Y.zip
+...
+
+Where the PAR2 files protect the Y.zip file(s). Note that Y can be equal to
+X, but is not required to be.
+"""
+
+__author__ = "Ira W. Snyder (devel@irasnyder.com)"
+__copyright__ = "Copyright (c) 2006-2008 Ira W. Snyder (devel@irasnyder.com)"
+__license__ = "GNU GPL v2 (or, at your option, any later version)"
+
+# ZIP.py -- detect and work with zip sets
#
-# This is a regular zip file type
+# 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
-# X.zip
-# ABC.zip
+# 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 a file named X.zip and/or ABC.zip.
+# 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 ZIP(Base):
+
+ ############################################################################
-def detector (name_files, prot_files):
- all_files = rsutil.common.no_duplicates (name_files + prot_files)
- return rsutil.common.has_a_match ('^.*\.zip$', all_files)
+ def detect(self):
+ regex = r'^.*\.zip$'
-class ZIP (PAR2Set.Base.Base):
+ if utils.hasAMatch(regex, self.allFiles):
+ return
- def __repr__ (self):
- return 'ZIP'
+ raise TypeError
- def find_extraction_heads (self):
- return rsutil.common.find_matches ('^.*\.zip', self.all_files)
+ ############################################################################
- def extraction_function (self, file, todir):
- ZIP_CMD = rsutil.common.config_get_value ('commands', 'unzip')
+ def extract(self):
- cmd = ZIP_CMD % (file, todir)
- ret = rsutil.common.run_command (cmd)
+ regex = r'^.*\.zip$'
+ files = utils.findMatches(regex, self.allFiles)
- # Check error code
- if ret != 0:
- return -rsutil.common.EEXTRACT
+ for f in files:
+ utils.runCommand(['unzip', f], self.directory)
- return rsutil.common.SUCCESS
+ ############################################################################