Added support for RZIP (.rz) archives.

This commit is contained in:
Bastian Kleineidam 2010-03-20 11:34:40 +01:00
parent b4a9a04cdf
commit 82708b74fa
12 changed files with 78 additions and 10 deletions

View File

@ -2,6 +2,7 @@
* Do not use the diff -B option when comparing archives.
* Improved documentation: explain commands in more detail.
* Added support for RZIP (.rz) archives.
0.8 "Storage" (released 11.3.2010)

View File

@ -32,7 +32,8 @@ by the archive file extension.
ARC (.arc), ARJ (.arj),
BZIP2 (.bz2), CAB (.cab), compress (.Z), CPIO (.cpio), DEB (.deb), GZIP (.gz),
LRZIP (.lrz), LZH (.lha, .lzh), LZIP (.lz), LZMA (.lzma), LZOP (.lzo),
RPM (.rpm), RAR (.rar), TAR (.tar), XZ (.xz) and ZIP (.zip, .jar) formats.
RPM (.rpm), RAR (.rar), RZIP (.rz), TAR (.tar), XZ (.xz) and ZIP (.zip, .jar)
formats.
It relies on helper applications to handle those archive formats
(for example bzip2 for BZIP2 archives).
.SH EXAMPLES

View File

@ -24,7 +24,7 @@ ArchiveCommands = ('list', 'extract', 'test', 'create')
# Supported archive formats
ArchiveFormats = ('7z', 'ace', 'alzip', 'ar', 'arc', 'arj', 'bzip2',
'cab', 'compress', 'cpio', 'deb', 'gzip', 'lrzip', 'lzh', 'lzip', 'lzma',
'lzop', 'rar', 'rpm', 'tar', 'xz', 'zip')
'lzop', 'rar', 'rpm', 'rzip', 'tar', 'xz', 'zip')
# Supported encodings (used with tar for example)
# Note that all encodings must also be archive formats
@ -59,6 +59,7 @@ ArchiveMimetypes = {
'application/x-alzip': 'alzip',
'application/x-arc': 'arc',
'application/x-lrzip': 'lrzip',
'application/x-rzip': 'rzip',
}
# List of programs supporting the given encoding
@ -178,6 +179,11 @@ ArchivePrograms = {
'test': ('lzma',),
'create': ('lzma',),
},
'rzip': {
'extract': ('rzip',),
'list': ('echo',),
'create': ('rzip',),
},
'xz': {
'extract': ('xz',),
'list': ('echo',),

View File

@ -41,6 +41,10 @@ def list_lrzip (archive, encoding, cmd, **kwargs):
"""List a LRZIP archive."""
return stripext(cmd, archive)
def list_rzip (archive, encoding, cmd, **kwargs):
"""List a RZIP archive."""
return stripext(cmd, archive)
def stripext (cmd, archive):
"""Echo the name without suffix."""
return [cmd, util.stripext(archive)]

37
patoolib/programs/rzip.py Normal file
View File

@ -0,0 +1,37 @@
# -*- 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 lrzip program."""
import os
from patoolib import util
def extract_rzip (archive, encoding, cmd, **kwargs):
"""Extract a RZIP archive."""
# Since extracted files will be placed in the current directory,
# the cwd argument has to be the output directory.
cmdlist = [cmd, '-d', '-k']
if kwargs['verbose']:
cmdlist.append('-v')
outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(["-o", outfile, os.path.abspath(archive)])
return (cmdlist, {'cwd': kwargs['outdir']})
def create_rzip (archive, encoding, cmd, *args, **kwargs):
"""Create a RZIP archive."""
cmdlist = [cmd, '-k', '-o', archive]
if kwargs['verbose']:
cmdlist.append('-v')
cmdlist.extend(args)
return cmdlist

View File

@ -47,6 +47,7 @@ mimedb.add_type('application/x-arc', '.arc', strict=False)
mimedb.add_type('application/x-lrzip', '.lrz', strict=False)
mimedb.add_type('application/x-lha', '.lha', strict=False)
mimedb.add_type('application/x-lzh', '.lzh', strict=False)
mimedb.add_type('application/x-rzip', '.rz', strict=False)
class PatoolError (StandardError):
@ -205,6 +206,7 @@ FileText2Mime = {
"Zip archive data": "application/zip",
"compress'd data": "application/x-compress",
"lzip compressed data": "application/x-lzip",
"rzip compressed data": "application/x-rzip",
"current ar archive": "application/x-archive",
"LHa ": "application/x-lha",
"ARC archive data": "application/x-arc",

View File

@ -49,9 +49,9 @@ fallback by the archive file extension.
patool supports 7z (.7z), ACE (.ace), ALZIP (.alz), AR (.a), ARC (.arc),
ARJ (.arj), BZIP2 (.bz2), CAB (.cab), compress (.Z), CPIO (.cpio),
DEB (.deb), GZIP (.gz), LRZIP (.lrz), LZH (.lha, .lzh), LZIP (.lz),
LZMA (.lzma), LZOP (.lzo), RPM (.rpm), RAR (.rar), TAR (.tar), XZ (.xz)
and ZIP (.zip, .jar) formats. It relies on helper applications to handle
those archive formats (for example bzip2 for BZIP2 archives).""",
LZMA (.lzma), LZOP (.lzo), RPM (.rpm), RAR (.rar), RZIP (.rz), TAR (.tar),
XZ (.xz) and ZIP (.zip, .jar) formats. It relies on helper applications
to handle those archive formats (for example bzip2 for BZIP2 archives).""",
author = MyName,
author_email = MyEmail,
maintainer = MyName,

View File

@ -94,14 +94,18 @@ class ArchiveTest (unittest.TestCase):
try:
patoolib._handle_archive(archive, 'create', topack, **kwargs)
self.assertTrue(os.path.isfile(archive))
# not all programs can test what they create
# test the created archive
command = 'test'
program = self.program
# special case for programs that cannot 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)
elif self.program == 'rzip':
program = 'echo'
command = 'list'
patoolib._handle_archive(archive, command, program=program)
finally:
os.chdir(basedir)
shutil.rmtree(tmpdir)

BIN
tests/data/t.txt.rz Normal file

Binary file not shown.

BIN
tests/data/t.txt.rz.foo Normal file

Binary file not shown.

View File

@ -115,6 +115,7 @@ class TestArchives (ArchiveTest):
self.archive_list('t.lzma')
self.archive_list('t.txt.lz')
self.archive_list('t.txt.lrz')
self.archive_list('t.txt.rz')
@needs_program('unzip')
def test_unzip (self):
@ -311,3 +312,9 @@ class TestArchives (ArchiveTest):
self.archive_test('t.txt.lrz')
self.archive_extract('t.txt.lrz')
self.archive_create('t.txt.lrz', singlefile=True)
@needs_program('rzip')
def test_rzip (self):
self.program = 'rzip'
self.archive_extract('t.txt.rz')
self.archive_create('t.txt.rz', singlefile=True)

View File

@ -349,10 +349,16 @@ class TestArchives (ArchiveTest):
self.archive_list('t.arc.foo')
self.archive_extract('t.arc.foo')
# file(1) does not recognize .alz files
# file(1) does not recognize .lrz files
#@needs_program('lrzip')
#def test_lrzip (self):
# self.program = 'lrzip'
# self.archive_test('t.txt.lrz.foo')
# self.archive_extract('t.txt.lrz.foo')
# self.archive_create('t.txt.lrz.foo', format="lrzip", singlefile=True)
@needs_program('rzip')
def test_rzip (self):
self.program = 'rzip'
self.archive_extract('t.txt.rz.foo')
self.archive_create('t.txt.rz.foo', format="rzip", singlefile=True)