diff --git a/doc/patool.1 b/doc/patool.1 index 657bc26..2f202e9 100644 --- a/doc/patool.1 +++ b/doc/patool.1 @@ -54,6 +54,17 @@ Verbose archive listing (if the helper application supports it). .TP \fB\-\-help\fP Show help for this command. +.SS \fBcreate\fP +Create an archive from given files. +.TP +\fB--force\fP +Allow overwriting of local archives. +.TP +\fB\-\-verbose\fP +Verbose operation (if the helper application supports it). +.TP +\fB\-\-help\fP +Show help for this command. .SS \fBformats\fP Show all supported archive formats. .TP @@ -81,7 +92,7 @@ Supported archive formats are listed by the \fBformats\fP command. .TP \fImode\fP\fB=/usr/bin/mycommand\fP Set the application to handle the archive format for given mode. -\fImode\fP can be one of \fBextract\fP, \fBlist\fP. +\fImode\fP can be one of (\fBextract\fP, \fBlist\fP, \fBcreate\fP). .SH FILES \fB/etc/patool.conf\fP, \fB~/.patool.conf\fP - configuration files diff --git a/doc/todo.txt b/doc/todo.txt index 1e99398..e749024 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,3 +1,2 @@ -- add project to github - add create mode? - add test mode? diff --git a/patool b/patool index 26e1d50..3b8d07d 100755 --- a/patool +++ b/patool @@ -36,10 +36,10 @@ def list (archive, verbose=False): return patoolib.handle_archive(archive, 'list') -#@baker.command -#def create (archive, *args): -# """Create an archive from given files.""" -# return patoolib.handle_archive(archive, 'create', *args) +@baker.command +def create (archive, *args): + """Create an archive from given files.""" + return patoolib.handle_archive(archive, 'create', *args) @baker.command diff --git a/patoolib/__init__.py b/patoolib/__init__.py index da470c4..0edd99d 100644 --- a/patoolib/__init__.py +++ b/patoolib/__init__.py @@ -19,7 +19,7 @@ from distutils.spawn import find_executable from . import util # Supported archive commands -ArchiveCommands = ('list', 'extract') +ArchiveCommands = ('list', 'extract', 'create') # Supported archive formats ArchiveFormats = ('gzip', 'bzip2', 'tar', 'zip', 'compress', '7z', 'rar', @@ -254,8 +254,10 @@ def cleanup_outdir (archive, outdir, force): return target -def _handle_archive (archive, command, **kwargs): - util.check_filename(archive) +def _handle_archive (archive, command, *args, **kwargs): + if command != 'create': + # check that archive is a regular file + util.check_filename(archive) encoding = None format, encoding = get_archive_format(archive) check_archive_format(format, encoding) @@ -288,10 +290,10 @@ def _handle_archive (archive, command, **kwargs): pass -def handle_archive (archive, command, **kwargs): +def handle_archive (archive, command, *args, **kwargs): """Handle archive file command.""" try: - _handle_archive(archive, command, **kwargs) + _handle_archive(archive, command, *args, **kwargs) res = 0 except util.PatoolError, msg: util.log_error(msg) diff --git a/patoolib/tar.py b/patoolib/tar.py index 832eda0..1e8d0d9 100644 --- a/patoolib/tar.py +++ b/patoolib/tar.py @@ -34,3 +34,7 @@ def list_tar (archive, encoding, cmd, **kwargs): cmdlist.append('--verbose') cmdlist.extend(["--file", archive]) return cmdlist + +def create_tar (archive, encoding, cmd, **kwargs): + """Create a TAR archive.""" + print "XXX create", archive, encoding, cmd, kwargs