Skip to content
Snippets Groups Projects
Commit 1761d033 authored by Aurélien Dunand's avatar Aurélien Dunand Committed by Seblu
Browse files

cat command can display several files

files can be a list and/or unix filename pattern
parent dad43b37
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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):
'''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment