Skip to content

Commit

Permalink
Starts 'showfiles' command: for pack files
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Sep 4, 2014
1 parent 0e0f4c5 commit f8083e4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
9 changes: 8 additions & 1 deletion reprounzip/reprounzip/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import sys

from reprounzip.common import setup_logging
from reprounzip.pack_info import print_info
from reprounzip.pack_info import print_info, showfiles


__version__ = '0.4'
Expand Down Expand Up @@ -73,6 +73,13 @@ def main():
help="Pack to read")
parser_info.set_defaults(func=lambda args: print_info(args, unpackers))

parser_showfiles = subparsers.add_parser(
'showfiles', parents=[options],
help="Prints out input and output file names")
parser_showfiles.add_argument('pack', nargs=1,
help="Pack or directory to read from")
parser_showfiles.set_defaults(func=showfiles)

# Loads commands from plugins
for entry_point in iter_entry_points('reprounzip.unpackers'):
setup_function = entry_point.load()
Expand Down
40 changes: 40 additions & 0 deletions reprounzip/reprounzip/pack_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import platform
from rpaths import Path
import sys
import tarfile

from reprounzip.unpackers.common import load_config, COMPAT_OK, COMPAT_MAYBE, \
Expand Down Expand Up @@ -153,3 +154,42 @@ def print_info(args, unpackers):
print(" %s (%s)" % (upk_name, msg))
else:
print(" %s" % upk_name)


def showfiles(args):
"""Writes out the input and output files.
Works both for a pack file and for an extracted directory.
"""
pack = Path(args.pack[0])

if not pack.exists():
logging.critical("Pack or directory %s does not exist" % pack)
sys.exit(1)

if pack.is_dir():
logging.critical("Not yet implemented")
sys.exit(1)
else: # pack.is_file()
# Reads info from a pack file
runs, packages, other_files = load_config(pack)

print("Input files:")
for i, run in enumerate(runs):
if len(runs) > 1:
print(" Run %d:" % i)
for input_name, path in iteritems(run['input_files']):
if args.verbosity >= 2:
print(" %s (%s)" % (input_name, path))
else:
print(" %s" % input_name)

print("Output files:")
for i, run in enumerate(runs):
if len(runs) > 1:
print(" Run %d:" % i)
for output_name, path in iteritems(run['output_files']):
if args.verbosity >= 2:
print(" %s (%s)" % (output_name, path))
else:
print(" %s" % output_name)

0 comments on commit f8083e4

Please sign in to comment.