Remove --force option.
This commit is contained in:
parent
702a80dbf0
commit
2692c7f84f
|
@ -46,9 +46,6 @@ first extracting files to a unique (temporary) directory, and
|
||||||
then moving its contents back if possible. This also prevents
|
then moving its contents back if possible. This also prevents
|
||||||
local files from being overwritten by mistake.
|
local files from being overwritten by mistake.
|
||||||
.TP
|
.TP
|
||||||
\fB--force\fP
|
|
||||||
Allow overwriting of local files.
|
|
||||||
.TP
|
|
||||||
\fB\-\-verbose\fP
|
\fB\-\-verbose\fP
|
||||||
Be verbose when extracting (if the helper application supports it).
|
Be verbose when extracting (if the helper application supports it).
|
||||||
.TP
|
.TP
|
||||||
|
@ -65,9 +62,6 @@ Show help for this command.
|
||||||
.SS \fBcreate\fP
|
.SS \fBcreate\fP
|
||||||
Create an archive from given files.
|
Create an archive from given files.
|
||||||
.\" .TP
|
.\" .TP
|
||||||
.\" \fB--force\fP
|
|
||||||
.\" Allow overwriting of local archives.
|
|
||||||
.\" .TP
|
|
||||||
.\" \fB\-\-verbose\fP
|
.\" \fB\-\-verbose\fP
|
||||||
.\" Verbose operation (if the helper application supports it).
|
.\" Verbose operation (if the helper application supports it).
|
||||||
.TP
|
.TP
|
||||||
|
|
|
@ -37,9 +37,6 @@ COMMANDS
|
||||||
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.
|
overwritten by mistake.
|
||||||
|
|
||||||
--force
|
|
||||||
Allow overwriting of local files.
|
|
||||||
|
|
||||||
--verbose
|
--verbose
|
||||||
Be verbose when extracting (if the helper application supports
|
Be verbose when extracting (if the helper application supports
|
||||||
it).
|
it).
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
- Add ability to extract multiple archives.
|
- Add ability to extract multiple archives.
|
||||||
- Remove the --force option. Lesser options make it easier.
|
|
||||||
- Add short option -v for verbosity.
|
- Add short option -v for verbosity.
|
||||||
|
|
3
patool
3
patool
|
@ -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
|
from patoolib import handle_archive, list_formats, baker
|
||||||
|
|
||||||
@baker.command(default=True, params={
|
@baker.command(default=True, params={
|
||||||
"force": "Allow overwriting of local files.",
|
|
||||||
"verbose": "Be verbose when extracting (if the helper application supports it)."
|
"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."""
|
"""Extract files from archives."""
|
||||||
return handle_archive(archive, 'extract')
|
return handle_archive(archive, 'extract')
|
||||||
|
|
||||||
|
|
|
@ -248,7 +248,7 @@ def list_formats ():
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
AllowedConfigKeys = ("verbose", "force", "program")
|
AllowedConfigKeys = ("verbose", "program")
|
||||||
|
|
||||||
def clean_config_keys (kwargs):
|
def clean_config_keys (kwargs):
|
||||||
"""Remove invalid configuration keys from arguments."""
|
"""Remove invalid configuration keys from arguments."""
|
||||||
|
@ -267,7 +267,6 @@ def parse_config (archive, format, encoding, command, **kwargs):
|
||||||
"""
|
"""
|
||||||
config = {
|
config = {
|
||||||
'verbose': False,
|
'verbose': False,
|
||||||
'force': False,
|
|
||||||
}
|
}
|
||||||
config['program'] = find_archive_program(format, command)
|
config['program'] = find_archive_program(format, command)
|
||||||
for key, value in kwargs.items():
|
for key, value in kwargs.items():
|
||||||
|
@ -283,9 +282,9 @@ def parse_config (archive, format, encoding, command, **kwargs):
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
def move_outdir_orphan (outdir, force):
|
def move_outdir_orphan (outdir):
|
||||||
"""Move a single file or directory inside outdir a level up.
|
"""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."""
|
Return (True, outfile) if successful, (False, reason) if not."""
|
||||||
entries = os.listdir(outdir)
|
entries = os.listdir(outdir)
|
||||||
reason = ""
|
reason = ""
|
||||||
|
@ -293,12 +292,7 @@ def move_outdir_orphan (outdir, force):
|
||||||
src = os.path.join(outdir, entries[0])
|
src = os.path.join(outdir, entries[0])
|
||||||
dst = os.path.join(os.path.dirname(outdir), entries[0])
|
dst = os.path.join(os.path.dirname(outdir), entries[0])
|
||||||
if os.path.exists(dst):
|
if os.path.exists(dst):
|
||||||
if not force:
|
return (False, "local file exists")
|
||||||
return (False, "local file exists")
|
|
||||||
if os.path.isdir(dst):
|
|
||||||
shutil.rmtree(dst)
|
|
||||||
else:
|
|
||||||
os.unlink(dst)
|
|
||||||
shutil.move(src, dst)
|
shutil.move(src, dst)
|
||||||
os.rmdir(outdir)
|
os.rmdir(outdir)
|
||||||
return (True, entries[0])
|
return (True, entries[0])
|
||||||
|
@ -315,11 +309,11 @@ def run_archive_cmdlist (archive_cmdlist):
|
||||||
util.run(cmdlist, **runkwargs)
|
util.run(cmdlist, **runkwargs)
|
||||||
|
|
||||||
|
|
||||||
def cleanup_outdir (archive, outdir, force):
|
def cleanup_outdir (archive, outdir):
|
||||||
"""Cleanup outdir after extraction and return target file name."""
|
"""Cleanup outdir after extraction and return target file name."""
|
||||||
if outdir:
|
if outdir:
|
||||||
# move single directory or file in outdir
|
# move single directory or file in outdir
|
||||||
(res, msg) = move_outdir_orphan(outdir, force)
|
(res, msg) = move_outdir_orphan(outdir)
|
||||||
if res:
|
if res:
|
||||||
target = "`%s'" % msg
|
target = "`%s'" % msg
|
||||||
else:
|
else:
|
||||||
|
@ -341,10 +335,9 @@ def _handle_archive (archive, command, *args, **kwargs):
|
||||||
check_archive_command(command)
|
check_archive_command(command)
|
||||||
config_kwargs = clean_config_keys(kwargs)
|
config_kwargs = clean_config_keys(kwargs)
|
||||||
config = parse_config(archive, format, encoding, command, **config_kwargs)
|
config = parse_config(archive, format, encoding, command, **config_kwargs)
|
||||||
if command == 'create':
|
# check if archive already exists
|
||||||
# check if archive already exists
|
if command == 'create' and os.path.exists(archive):
|
||||||
if os.path.exists(archive) and not config['force']:
|
raise util.PatoolError("archive `%s' already exists" % archive)
|
||||||
raise util.PatoolError("archive `%s' already exists, and --force option was not given" % archive)
|
|
||||||
program = config['program']
|
program = config['program']
|
||||||
# get python module for given archive program
|
# get python module for given archive program
|
||||||
key = util.stripext(os.path.basename(program).lower())
|
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)
|
cmdlist = get_archive_cmdlist(archive, encoding, program, *args, **kwargs)
|
||||||
run_archive_cmdlist(cmdlist)
|
run_archive_cmdlist(cmdlist)
|
||||||
if command == 'extract':
|
if command == 'extract':
|
||||||
target = cleanup_outdir(archive, outdir, config['force'])
|
target = cleanup_outdir(archive, outdir)
|
||||||
print "%s: extracted to %s" % (archive, target)
|
print "%s: extracted to %s" % (archive, target)
|
||||||
finally:
|
finally:
|
||||||
if outdir:
|
if outdir:
|
||||||
|
|
|
@ -47,7 +47,6 @@ class ArchiveTest (unittest.TestCase):
|
||||||
os.chdir(tmpdir)
|
os.chdir(tmpdir)
|
||||||
try:
|
try:
|
||||||
patoolib._handle_archive(archive, 'extract', program=self.program)
|
patoolib._handle_archive(archive, 'extract', program=self.program)
|
||||||
patoolib._handle_archive(archive, 'extract', program=self.program, force=True)
|
|
||||||
finally:
|
finally:
|
||||||
os.chdir(basedir)
|
os.chdir(basedir)
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
|
|
Loading…
Reference in New Issue