From 2692c7f84f35f1e18199cd03349dcc521f93f2e4 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sat, 6 Mar 2010 11:33:44 +0100 Subject: [PATCH] Remove --force option. --- doc/patool.1 | 6 ------ doc/patool.txt | 3 --- doc/todo.txt | 1 - patool | 3 +-- patoolib/__init__.py | 27 ++++++++++----------------- tests/__init__.py | 1 - 6 files changed, 11 insertions(+), 30 deletions(-) diff --git a/doc/patool.1 b/doc/patool.1 index 60f1f5b..ed9fceb 100644 --- a/doc/patool.1 +++ b/doc/patool.1 @@ -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 diff --git a/doc/patool.txt b/doc/patool.txt index 365852a..0b59db0 100644 --- a/doc/patool.txt +++ b/doc/patool.txt @@ -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). diff --git a/doc/todo.txt b/doc/todo.txt index 3c9423a..c4d958e 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -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. diff --git a/patool b/patool index 2ac7d9a..d0aad5a 100755 --- a/patool +++ b/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 @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') diff --git a/patoolib/__init__.py b/patoolib/__init__.py index 1563740..33f3b6f 100644 --- a/patoolib/__init__.py +++ b/patoolib/__init__.py @@ -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) + return (False, "local file exists") 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) + # check if archive already exists + 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: diff --git a/tests/__init__.py b/tests/__init__.py index e845129..6276e8c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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)