Added support for AR (.a) archives.

This commit is contained in:
Bastian Kleineidam 2010-03-06 16:52:13 +01:00
parent 9a04371f07
commit 6cba779475
13 changed files with 93 additions and 16 deletions

View File

@ -7,6 +7,7 @@
* Fix permissions of extracted files: make them readable by the
current user.
* Added support for ACE (.ace) archives.
* Added support for AR (.a) archives.
0.5 "Vanishing Point" (released 4.3.2010)

View File

@ -26,7 +26,7 @@ files without having to remember a myriad of programs and options.
The archive format is determined by the file(1) program and as a fallback
by the archive file extension.
.PP
\fBpatool\fP supports 7z (.7z), ACE (.ace), ZIP (.zip, .jar), GZIP (.gz), compress (.Z),
\fBpatool\fP supports 7z (.7z), ACE (.ace), AR (.a), ZIP (.zip, .jar), GZIP (.gz), compress (.Z),
BZIP2 (.bz2), TAR (.tar), ARJ (.arj), CAB (.cab), CPIO (.cpio),
RPM (.rpm), DEB (.deb), LZIP (.lz), LZOP (.lzo), LZMA (.lzma), RAR (.rar)
and XZ (.xz) formats.

View File

@ -18,11 +18,12 @@ DESCRIPTION
The archive format is determined by the file(1) program and as a fall
back by the archive file extension.
patool supports 7z (.7z), ACE (.ace), ZIP (.zip, .jar), GZIP (.gz),
compress (.Z), BZIP2 (.bz2), TAR (.tar), ARJ (.arj), CAB (.cab), CPIO
(.cpio), RPM (.rpm), DEB (.deb), LZIP (.lz), LZOP (.lzo), LZMA (.lzma),
RAR (.rar) and XZ (.xz) formats. It relies on helper applications to
handle those archive formats (for example bzip2 for BZIP2 archives).
patool supports 7z (.7z), ACE (.ace), AR (.a), ZIP (.zip, .jar), GZIP
(.gz), compress (.Z), BZIP2 (.bz2), TAR (.tar), ARJ (.arj), CAB (.cab),
CPIO (.cpio), RPM (.rpm), DEB (.deb), LZIP (.lz), LZOP (.lzo), LZMA
(.lzma), RAR (.rar) and XZ (.xz) formats. It relies on helper applica
tions to handle those archive formats (for example bzip2 for BZIP2 ar
chives).
EXAMPLES
patool extract archive.zip otherarchive.rar
@ -34,19 +35,19 @@ COMMANDS
Several commands and options are available.
extract
Extract files from an archive. This is the default command if no com
Extract files from an archive. This is the default command if no com
mand was given.
Often one wants to extract all files in an archive to a single subdi
rectory. However, some archives contain multiple files in their root
Often one wants to extract all files in an archive to a single subdi
rectory. However, some archives contain multiple files in their root
directories. The patool program overcomes this problem by first
extracting files to a unique (temporary) directory, and then moving its
contents back if possible. This also prevents local files from being
contents back if possible. This also prevents local files from being
overwritten by mistake.
All extracted files are checked that they are readable by the current
All extracted files are checked that they are readable by the current
user.
-v, --verbose
Be verbose when extracting (if the helper application supports
Be verbose when extracting (if the helper application supports
it).
--help Show help for this command.
@ -60,7 +61,7 @@ COMMANDS
--help Show help for this command.
create
Create an archive from given files. At least on of the given files to
Create an archive from given files. At least on of the given files to
add to the archive has to exist.
-v, --verbose

View File

@ -1,2 +1 @@
- Support ar archives.
- Support lha archives.

View File

@ -23,7 +23,8 @@ ArchiveCommands = ('list', 'extract', 'test', 'create')
# Supported archive formats
ArchiveFormats = ('gzip', 'bzip2', 'tar', 'zip', 'compress', '7z', 'rar',
'cab', 'arj', 'cpio', 'rpm', 'deb', 'lzop', 'lzma', 'xz', 'lzip', 'ace')
'cab', 'arj', 'cpio', 'rpm', 'deb', 'lzop', 'lzma', 'xz', 'lzip', 'ace',
'ar')
# Supported encodings (used with tar for example)
# Note that all encodings must also be archive formats
@ -52,6 +53,7 @@ ArchiveMimetypes = {
'application/x-xz': 'xz',
'application/x-lzip': 'lzip',
'application/x-ace': 'ace',
'application/x-archive': 'ar',
}
# List of programs supporting the given encoding
@ -73,6 +75,9 @@ ArchivePrograms = {
'test': ('unace',),
'list': ('unace',),
},
'ar': {
None: ('ar',),
},
'bzip2': {
'extract': ('pbzip2', 'bzip2', '7z'),
'test': ('pbzip2', 'bzip2', '7z'),

47
patoolib/programs/ar.py Normal file
View File

@ -0,0 +1,47 @@
# -*- 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 ar program."""
def extract_ar (archive, encoding, cmd, **kwargs):
"""Extract a AR archive."""
cmdlist = [cmd]
opts = 'x'
if kwargs['verbose']:
opts += 'v'
cmdlist.extend([opts, archive, kwargs['outdir']])
return cmdlist
def list_ar (archive, encoding, cmd, **kwargs):
"""List a AR archive."""
cmdlist = [cmd]
opts = 't'
if kwargs['verbose']:
opts += 'v'
cmdlist.extend([opts, archive])
return cmdlist
test_ar = list_ar
def create_ar (archive, encoding, cmd, *args, **kwargs):
"""Create a AR archive."""
cmdlist = [cmd]
opts = 'rc'
if kwargs['verbose']:
opts += 'v'
cmdlist.extend([opts, archive])
cmdlist.extend(args)
return cmdlist

View File

@ -40,6 +40,8 @@ mimedb.add_type('application/x-cab', '.cab', strict=False)
mimedb.add_type('application/x-rpm', '.rpm', strict=False)
mimedb.add_type('application/x-debian-package', '.deb', strict=False)
mimedb.add_type('application/x-ace', '.ace', strict=False)
# Since .a is already a common type, strict=True must be used.
mimedb.add_type('application/x-archive', '.a', strict=True)
class PatoolError (StandardError):
@ -190,6 +192,7 @@ FileText2Mime = {
"Zip archive data": "application/zip",
"compress'd data": "application/x-compress",
"lzip compressed data": "application/x-lzip",
"current ar archive": "application/x-archive",
}
def guess_mime_file (file_prog, filename):

View File

@ -76,7 +76,7 @@ class ArchiveTest (unittest.TestCase):
kwargs = dict(
program=self.program,
format=format,
encoding=encoding
encoding=encoding,
)
self._archive_create(filename, topack, kwargs)
kwargs['verbose'] = True

4
tests/data/t.a Normal file
View File

@ -0,0 +1,4 @@
!<arch>
t.txt/ 1266562138 1000 1000 100640 3 `
42

4
tests/data/t.a.foo Normal file
View File

@ -0,0 +1,4 @@
!<arch>
t.txt/ 1266562138 1000 1000 100640 3 `
42

View File

@ -212,6 +212,11 @@ class TestArchives (ArchiveTest):
self.program = 'arj'
self.archive_commands('t.arj')
@needs_program('ar')
def test_ar (self):
self.program = 'ar'
self.archive_commands('t.a', singlefile=True)
@needs_program('cpio')
def test_cpio (self):
self.program = 'cpio'

View File

@ -243,6 +243,12 @@ class TestArchives (ArchiveTest):
self.program = 'arj'
self.archive_commands('t.arj.foo', format="arj")
@needs_program('file')
@needs_program('ar')
def test_ar (self):
self.program = 'ar'
self.archive_commands('t.a.foo', format='ar', singlefile=True)
@needs_program('file')
@needs_program('cpio')
def test_cpio (self):

View File

@ -88,3 +88,5 @@ class TestMime (unittest.TestCase):
self.mime_test("t.zip.foo", "application/zip", None)
self.mime_test("t.ace", "application/x-ace", None)
self.mime_test("t.ace.foo", "application/x-ace", None)
self.mime_test("t.a", "application/x-archive", None)
self.mime_test("t.a.foo", "application/x-archive", None)