#!/usr/bin/env python
# vim: set ts=4 sts=4 sw=4 textwidth=92:
-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,2007 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
+
+import PAR2Set.Base
+import rsutil.common
+
def detector (name_files, prot_files):
+ """Detect a zip set"""
+
all_files = rsutil.common.no_duplicates (name_files + prot_files)
return rsutil.common.has_a_match ('^.*\.zip$', all_files)
class ZIP (PAR2Set.Base.Base):
+ """Class for working with normal zip sets"""
+
def __repr__ (self):
return 'ZIP'
def find_extraction_heads (self):
+ """Find the heads of extraction for a zip set"""
+
return rsutil.common.find_matches ('^.*\.zip', self.all_files)
def extraction_function (self, file, todir):
- ZIP_CMD = rsutil.common.config_get_value ('commands', 'unzip')
-
- cmd = ZIP_CMD % (file, todir)
- ret = rsutil.common.run_command (cmd)
+ """Extract a single zip file to the given directory.
- # Check error code
- if ret != 0:
- return -rsutil.common.EEXTRACT
+ file -- the file to extract
+ todir -- the directory to extract into"""
- return rsutil.common.SUCCESS
+ rsutil.common.run_command(['unzip', file], todir)