From 1761d033258fd67649073c989a094e594ebc5395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Dunand?= <aurelien.dunand@smartjog.com> Date: Tue, 26 Jul 2011 10:13:09 +0200 Subject: [PATCH] cat command can display several files files can be a list and/or unix filename pattern --- bin/is | 8 ++++---- installsystems/image.py | 13 ++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/is b/bin/is index 02ff69f..e414eb6 100755 --- a/bin/is +++ b/bin/is @@ -182,7 +182,7 @@ def c_list(parser, args): def c_cat(parser, args): ''' - Display image's file + Display image's file(s) ''' # looks if arguments is a file or image name if istools.pathtype(args.image) == "file" and os.path.isfile(args.image): @@ -191,7 +191,8 @@ def c_cat(parser, args): # get image package repoman = load_repositories(args) pkg = repoman.get(args.image, args.image_version) - pkg.cat(args.file) + for filename in args.files: + pkg.cat(filename) def c_search(parser, args): ''' @@ -298,11 +299,10 @@ p_install.set_defaults(func=c_install, subparser=p_install) # cat command parser p_cat = subparsers.add_parser("cat", help=c_cat.__doc__.lower()) - p_cat.add_argument("-v", "--image-version", type=int, default=None, help="image version") p_cat.add_argument("image", help="image (path or name)") -p_cat.add_argument("file", help="file to cat") +p_cat.add_argument("files", nargs='+', help="files to cat") p_cat.set_defaults(func=c_cat) # get command parser diff --git a/installsystems/image.py b/installsystems/image.py index a1ee0a8..b07f04e 100644 --- a/installsystems/image.py +++ b/installsystems/image.py @@ -17,6 +17,7 @@ import re import cStringIO import shutil import gzip +import fnmatch import installsystems.template as istemplate import installsystems.tools as istools from installsystems.printer import * @@ -454,9 +455,15 @@ class PackageImage(Image): arrowlevel(-1) def cat(self, filename): - fd = self._tarball.extractfile(filename) - arrow(filename) - out(fd.read()) + ''' + Display filename in the tarball + ''' + for filename in fnmatch.filter(self._tarball.getnames(), filename): + fd = self._tarball.extractfile(filename) + if fd is not None: + arrow(filename) + out(fd.read()) + fd.close() def run_parser(self, **kwargs): ''' -- GitLab