Added support for creating ZIP archives.

This commit is contained in:
Bastian Kleineidam 2010-03-03 22:04:06 +01:00
parent 8d02fdfe8f
commit 2577a454b9
6 changed files with 43 additions and 1 deletions

View File

@ -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)

View File

@ -77,6 +77,7 @@ ArchivePrograms = {
'extract': ('unzip', '7z'),
'list': ('unzip', '7z'),
'test': ('unzip', '7z'),
'create': ('zip',),
},
'gzip': {
None: ('gzip', '7z'),

27
patoolib/programs/zip.py Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
"""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

View File

@ -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)

View File

@ -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'

View File

@ -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):