Skip to content

Commit

Permalink
Add new option --non-interactive.
Browse files Browse the repository at this point in the history
  • Loading branch information
wummel committed Dec 6, 2015
1 parent 8446298 commit a546db1
Show file tree
Hide file tree
Showing 53 changed files with 283 additions and 200 deletions.
9 changes: 9 additions & 0 deletions doc/patool.1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ installed.
Display more info about what patool does, and display the output
of helper applications. Can be given multiple times to increase
the output even more.
.TP
\fB\-\-non\-interactive\fP
Try to prevent any interactive user input (ie. prompting for passwords
or for overwriting duplicate files). Use this option with care since
overwriting files or ignoring password prompts could lead to unintended
consequences.
.br
This only works for programs that allow preventing user prompts. Currently
those are \fBarj\fP, \fB7z\fP and \fBrar\fP.
.SH COMMANDS
The following rules apply to all commands:
.IP "\(bu" 4
Expand Down
49 changes: 29 additions & 20 deletions doc/patool.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,23 @@ GLOBAL OPTIONS
the output of helper applications. Can be given multiple
times to increase the output even more.

--non-interactive
Try to prevent any interactive user input (ie. prompting
for passwords or for overwriting duplicate files). Use
this option with care since overwriting files or ignor‐
ing password prompts could lead to unintended conse‐
quences.
This only works for programs that allow preventing user
prompts. Currently those are arj, 7z and rar.

COMMANDS
The following rules apply to all commands:

· Existing files are never overwritten.

· The original archive will never be removed.

· Files outside the output directory will never be created.
· Files outside the output directory will never be created.
This relies on archive program options to prevent unpacking
of files with an absolute path name (eg. --no-abso‐
lute-filenames for cpio(1)).
Expand All @@ -67,22 +76,22 @@ COMMANDS
extract
patool extract [--outdir directory] <archive>...

Extract files from given archives. The original archives will
Extract files from given archives. The original archives will
never be removed and are left as is.

--outdir directory
Extract to the given output directory. Default is to
Extract to the given output directory. Default is to
extract to the current working directory.

If the archive contains exactly one file or directory, the ar‐
chive contents are extracted directly to the output directory.
If the archive contains exactly one file or directory, the ar‐
chive contents are extracted directly to the output directory.
Else the files are extracted in a newly created subdirectory of
the output directory. The new directory is named after the ar‐
the output directory. The new directory is named after the ar‐
chive filename without the extension.
This prevents cluttering the output directory with a lot of
This prevents cluttering the output directory with a lot of
files from the extracted archive.

All extracted files are ensured that they are readable by the
All extracted files are ensured that they are readable by the
current user.

list
Expand All @@ -93,16 +102,16 @@ COMMANDS
create
patool create <archive> <file-or-directory>...

Create an archive from given files. All of the given files to
add to the archive must be readable by the current user. The
format of the archive to create is determined by the archive
file extension. If the archive program has options to maximize
Create an archive from given files. All of the given files to
add to the archive must be readable by the current user. The
format of the archive to create is determined by the archive
file extension. If the archive program has options to maximize
file compression, patool uses those options.

test
patool test <archive>...

Test the given archives. If the helper application does not
Test the given archives. If the helper application does not
support testing, the archive contents are listed instead.

diff
Expand All @@ -114,37 +123,37 @@ COMMANDS
search
patool search <pattern> <archive>

Search in archive contents for given pattern using the grep(1)
program. The grep options used are -r; additional options can
Search in archive contents for given pattern using the grep(1)
program. The grep options used are -r; additional options can
be supplied with the GREP_OPTIONS environment variable.

repack
patool repack <archive> <archive_new>

Repackage archive to a different format. The target archive
Repackage archive to a different format. The target archive
format is determined by the file extension of archive_new.

recompress
patool recompress <archive>

Recompress archive to a smaller file size. If the resulting
Recompress archive to a smaller file size. If the resulting
file is not smaller, the archive is left unchanged.

formats
patool formats

Show all supported archive formats (ie. which helper applica‐
Show all supported archive formats (ie. which helper applica‐
tions are available).

HELP OPTION
Specifying the help option displays help for patool itself, or
Specifying the help option displays help for patool itself, or
a command.
For example:
patool --help - display help for patool
patool extract --help - display help for the extract command

SHELL ALIASES
When running under a Unix shell the following aliases can be
When running under a Unix shell the following aliases can be
defined to save some typing:
alias pl='patool list'
alias px='patool extract'
Expand Down
19 changes: 11 additions & 8 deletions patool
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def run_extract(args):
res = 0
for archive in args.archive:
try:
patoolib.extract_archive(archive, verbosity=args.verbosity, outdir=args.outdir)
patoolib.extract_archive(archive, verbosity=args.verbosity, interactive=args.interactive, outdir=args.outdir)
except PatoolError as msg:
log_error("error extracting %s: %s" % (archive, msg))
res += 1
Expand All @@ -43,7 +43,8 @@ def run_list(args):
for archive in args.archive:
try:
# increase default verbosity since the listing output should be visible
patoolib.list_archive(archive, verbosity=args.verbosity + 1)
verbosity = args.verbosity + 1
patoolib.list_archive(archive, verbosity=verbosity, interactive=args.interactive)
except PatoolError as msg:
log_error("error listing %s: %s" % (archive, msg))
res += 1
Expand All @@ -55,7 +56,7 @@ def run_test(args):
res = 0
for archive in args.archive:
try:
patoolib.test_archive(archive, verbosity=args.verbosity)
patoolib.test_archive(archive, verbosity=args.verbosity, interactive=args.interactive)
except PatoolError as msg:
log_error("error testing %s: %s" % (archive, msg))
res += 1
Expand All @@ -66,7 +67,7 @@ def run_create(args):
"""Create an archive from given files."""
res = 0
try:
patoolib.create_archive(args.archive, args.filename, verbosity=args.verbosity)
patoolib.create_archive(args.archive, args.filename, verbosity=args.verbosity, interactive=args.interactive)
except PatoolError as msg:
log_error("error creating %s: %s" % (args.archive, msg))
res = 1
Expand All @@ -76,7 +77,7 @@ def run_create(args):
def run_diff(args):
"""Show differences between two archives."""
try:
res = patoolib.diff_archives(args.archive1, args.archive2, verbosity=args.verbosity)
res = patoolib.diff_archives(args.archive1, args.archive2, verbosity=args.verbosity, interactive=args.interactive)
except PatoolError as msg:
log_error("error showing differences between %s and %s: %s" % (args.archive1, args.archive2, msg))
res = 2
Expand All @@ -86,7 +87,7 @@ def run_diff(args):
def run_search(args):
"""Search for pattern in given archive."""
try:
res = patoolib.search_archive(args.pattern, args.archive, verbosity=args.verbosity)
res = patoolib.search_archive(args.pattern, args.archive, verbosity=args.verbosity, interactive=args.interactive)
except PatoolError as msg:
log_error("error searching %s: %s" % (args.archive, msg))
res = 2
Expand All @@ -97,7 +98,7 @@ def run_repack(args):
"""Repackage one archive in another format."""
res = 0
try:
patoolib.repack_archive(args.archive_src, args.archive_dst, verbosity=args.verbosity)
patoolib.repack_archive(args.archive_src, args.archive_dst, verbosity=args.verbosity, interactive=args.interactive)
except PatoolError as msg:
log_error("error repacking %s: %s" % (args.archive_src, msg))
res = 1
Expand All @@ -108,7 +109,7 @@ def run_recompress(args):
"""Recompress an archive to smaller size."""
res = 0
try:
patoolib.recompress_archive(args.archive, verbosity=args.verbosity)
patoolib.recompress_archive(args.archive, verbosity=args.verbosity, interactive=args.interactive)
except PatoolError as msg:
log_error("error recompressing %s: %s" % (args.archive, msg))
res = 1
Expand Down Expand Up @@ -157,6 +158,8 @@ def create_argparser():
parser = ArgumentParser(description="An archive file manager.",
epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('--verbose', '-v', action='count', default=0, dest='verbosity', help="verbose operation; can be given multiple times")
parser.add_argument('--non-interactive', dest='interactive', default=True, action='store_false',
help="don't query for user input (ie. passwords or when overwriting duplicate files); use with care since overwriting files or ignoring passwords could be unintended")
subparsers = parser.add_subparsers(help='the archive command; type "patool COMMAND -h" for command-specific help', dest='command')
# extract
parser_extract = subparsers.add_parser('extract', help='extract one or more archives')
Expand Down
Loading

0 comments on commit a546db1

Please sign in to comment.