diff --git a/doc/changelog.txt b/doc/changelog.txt index 7f03a57..1fa42b3 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -1,7 +1,8 @@ 0.4 "" (released xx.xx.2010) - * Improved listing of available archive formats. * Added support for Windows systems. + * Added support for creating ZIP files. + * Improved listing of available archive formats. * Improved recognition of MIME types. 0.3 "Management" (released 23.2.2010) diff --git a/patoolib/__init__.py b/patoolib/__init__.py index bcb805c..3879ecf 100644 --- a/patoolib/__init__.py +++ b/patoolib/__init__.py @@ -77,6 +77,7 @@ ArchivePrograms = { 'extract': ('unzip', '7z'), 'list': ('unzip', '7z'), 'test': ('unzip', '7z'), + 'create': ('zip',), }, 'gzip': { None: ('gzip', '7z'), diff --git a/patoolib/programs/zip.py b/patoolib/programs/zip.py new file mode 100644 index 0000000..8ea0ae9 --- /dev/null +++ b/patoolib/programs/zip.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2010 Bastian Kleineidam +# +# 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 3 of the License, or +# (at your option) any later version. +# +# 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, see . +"""Archive commands for the zip program.""" + +def create_zip (archive, encoding, cmd, *args, **kwargs): + """Create a ZIP archive.""" + cmdlist = [cmd] + # XXX if archive already exists, use zip -u (update)? + cmdlist.append('-r') + if kwargs['verbose']: + cmdlist.append('--verbose') + cmdlist.append(archive) + cmdlist.extend(args) + return cmdlist diff --git a/tests/__init__.py b/tests/__init__.py index bae9127..e845129 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -87,6 +87,8 @@ class ArchiveTest (unittest.TestCase): # not all programs can test what they create if self.program == 'compress': program = 'gzip' + elif self.program == 'zip': + program = 'unzip' else: program = self.program patoolib._handle_archive(archive, 'test', program=program) diff --git a/tests/test_archives.py b/tests/test_archives.py index ce2e3f6..1490397 100644 --- a/tests/test_archives.py +++ b/tests/test_archives.py @@ -114,6 +114,11 @@ class TestArchives (ArchiveTest): self.archive_list('t.jar') self.archive_test('t.jar') + @needs_program('zip') + def test_zip (self): + self.program = 'zip' + self.archive_create('t.zip') + @needs_program('gzip') def test_gzip (self): self.program = 'gzip' diff --git a/tests/test_foo_archives.py b/tests/test_foo_archives.py index 2caa741..9ec1c54 100644 --- a/tests/test_foo_archives.py +++ b/tests/test_foo_archives.py @@ -133,6 +133,12 @@ class TestArchives (ArchiveTest): self.archive_list('t.jar.foo') self.archive_test('t.jar.foo') + @needs_program('file') + @needs_program('zip') + def test_zip (self): + self.program = 'zip' + self.archive_create('t.zip.foo', format="zip") + @needs_program('file') @needs_program('gzip') def test_gzip (self):