Remove --force option.

This commit is contained in:
Bastian Kleineidam 2010-03-06 11:33:44 +01:00
parent 702a80dbf0
commit 2692c7f84f
6 changed files with 11 additions and 30 deletions

View File

@ -46,9 +46,6 @@ first extracting files to a unique (temporary) directory, and
then moving its contents back if possible. This also prevents
local files from being overwritten by mistake.
.TP
\fB--force\fP
Allow overwriting of local files.
.TP
\fB\-\-verbose\fP
Be verbose when extracting (if the helper application supports it).
.TP
@ -65,9 +62,6 @@ 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

View File

@ -37,9 +37,6 @@ COMMANDS
contents back if possible. This also prevents local files from being
overwritten by mistake.
--force
Allow overwriting of local files.
--verbose
Be verbose when extracting (if the helper application supports
it).

View File

@ -1,3 +1,2 @@
- Add ability to extract multiple archives.
- Remove the --force option. Lesser options make it easier.
- Add short option -v for verbosity.

3
patool
View File

@ -23,10 +23,9 @@ if not hasattr(sys, "version_info") or sys.version_info < (2, 4, 0, "final", 0):
from patoolib import handle_archive, list_formats, baker
@baker.command(default=True, params={
"force": "Allow overwriting of local files.",
"verbose": "Be verbose when extracting (if the helper application supports it)."
})
def extract (archive, verbose=False, force=False):
def extract (archive, verbose=False):
"""Extract files from archives."""
return handle_archive(archive, 'extract')

View File

@ -248,7 +248,7 @@ def list_formats ():
return 0
AllowedConfigKeys = ("verbose", "force", "program")
AllowedConfigKeys = ("verbose", "program")
def clean_config_keys (kwargs):
"""Remove invalid configuration keys from arguments."""
@ -267,7 +267,6 @@ def parse_config (archive, format, encoding, command, **kwargs):
"""
config = {
'verbose': False,
'force': False,
}
config['program'] = find_archive_program(format, command)
for key, value in kwargs.items():
@ -283,9 +282,9 @@ def parse_config (archive, format, encoding, command, **kwargs):
return config
def move_outdir_orphan (outdir, force):
def move_outdir_orphan (outdir):
"""Move a single file or directory inside outdir a level up.
Overwrite files if force evaluates True.
Never overwrite files.
Return (True, outfile) if successful, (False, reason) if not."""
entries = os.listdir(outdir)
reason = ""
@ -293,12 +292,7 @@ def move_outdir_orphan (outdir, force):
src = os.path.join(outdir, entries[0])
dst = os.path.join(os.path.dirname(outdir), entries[0])
if os.path.exists(dst):
if not force:
return (False, "local file exists")
if os.path.isdir(dst):
shutil.rmtree(dst)
else:
os.unlink(dst)
shutil.move(src, dst)
os.rmdir(outdir)
return (True, entries[0])
@ -315,11 +309,11 @@ def run_archive_cmdlist (archive_cmdlist):
util.run(cmdlist, **runkwargs)
def cleanup_outdir (archive, outdir, force):
def cleanup_outdir (archive, outdir):
"""Cleanup outdir after extraction and return target file name."""
if outdir:
# move single directory or file in outdir
(res, msg) = move_outdir_orphan(outdir, force)
(res, msg) = move_outdir_orphan(outdir)
if res:
target = "`%s'" % msg
else:
@ -341,10 +335,9 @@ def _handle_archive (archive, command, *args, **kwargs):
check_archive_command(command)
config_kwargs = clean_config_keys(kwargs)
config = parse_config(archive, format, encoding, command, **config_kwargs)
if command == 'create':
# check if archive already exists
if os.path.exists(archive) and not config['force']:
raise util.PatoolError("archive `%s' already exists, and --force option was not given" % archive)
if command == 'create' and os.path.exists(archive):
raise util.PatoolError("archive `%s' already exists" % archive)
program = config['program']
# get python module for given archive program
key = util.stripext(os.path.basename(program).lower())
@ -362,7 +355,7 @@ def _handle_archive (archive, command, *args, **kwargs):
cmdlist = get_archive_cmdlist(archive, encoding, program, *args, **kwargs)
run_archive_cmdlist(cmdlist)
if command == 'extract':
target = cleanup_outdir(archive, outdir, config['force'])
target = cleanup_outdir(archive, outdir)
print "%s: extracted to %s" % (archive, target)
finally:
if outdir:

View File

@ -47,7 +47,6 @@ class ArchiveTest (unittest.TestCase):
os.chdir(tmpdir)
try:
patoolib._handle_archive(archive, 'extract', program=self.program)
patoolib._handle_archive(archive, 'extract', program=self.program, force=True)
finally:
os.chdir(basedir)
shutil.rmtree(tmpdir)