def show(self, o_payloads=False, o_files=False, o_changelog=False, o_json=False): ''' Display image content ''' if o_json: out(dumps(self._metadata)) else: out(u'#light##yellow#Name:#reset# %s' % self.name) out(u'#light##yellow#Version:#reset# %s' % self.version) out(u'#yellow#Date:#reset# %s' % time_rfc2822(self.date)) out(u'#yellow#Description:#reset# %s' % self.description) out(u'#yellow#Author:#reset# %s' % self.author) # field is_build_version is new in version 5. I can be absent. try: out(u'#yellow#IS build version:#reset# %s' % self.is_build_version) except AttributeError: pass # field is_min_version is new in version 5. I can be absent. try: out(u'#yellow#IS minimum version:#reset# %s' % self.is_min_version) except AttributeError: pass out(u'#yellow#Format:#reset# %s' % self.format) out(u'#yellow#MD5:#reset# %s' % self.md5) out(u'#yellow#Payload count:#reset# %s' % len(self.payload)) # display payloads if o_payloads: payloads = self.payload for payload_name in payloads: payload = payloads[payload_name] out(u'#light##yellow#Payload:#reset# %s' % payload_name) out(u' #yellow#Date:#reset# %s' % time_rfc2822(payload.mtime)) out(u' #yellow#Size:#reset# %s' % (human_size(payload.size))) out(u' #yellow#MD5:#reset# %s' % payload.md5) # display image content if o_files: out('#light##yellow#Files:#reset#') self._tarball.list(True) # display changelog if o_changelog: out('#light##yellow#Changelog:#reset#') self.changelog.show(self.version)
def __init__(self, path, fileobj=None, md5name=False): ''' Initialize a package image fileobj must be a seekable fileobj ''' Image.__init__(self) self.path = abspath(path) self.base_path = dirname(self.path) # tarball are named by md5 and not by real name self.md5name = md5name try: if fileobj is None: fileobj = PipeFile(self.path, "r") else: fileobj = PipeFile(mode="r", fileobj=fileobj) memfile = StringIO() fileobj.consume(memfile) # close source fileobj.close() # get downloaded size and md5 self.size = fileobj.read_size self.md5 = fileobj.md5 memfile.seek(0) self._tarball = Tarball.open(fileobj=memfile, mode='r:gz') except Exception as e: raise ISError(u"Unable to open image %s" % path, e) self._metadata = self.read_metadata() # print info arrow(u"Image %s v%s loaded" % (self.name, self.version)) arrow(u"Author: %s" % self.author, 1) arrow(u"Date: %s" % time_rfc2822(self.date), 1) # build payloads info self.payload = {} for pname, pval in self._metadata["payload"].items(): pfilename = u"%s-%s%s" % (self.filename[:-len(Image.extension)], pname, Payload.extension) if self.md5name: ppath = join(self.base_path, self._metadata["payload"][pname]["md5"]) else: ppath = join(self.base_path, pfilename) self.payload[pname] = Payload(pname, pfilename, ppath, **pval)
def show_images(self, patterns, o_json=False, o_long=False, o_md5=False, o_date=False, o_author=False, o_size=False, o_url=False, o_description=False, o_format=False, o_min_version=False): ''' Show images inside manager ''' # get images list images = self.select_images(patterns) # display result if o_json: s = json.dumps(images) else: l = [] for imgp in sorted(images.keys()): img = images[imgp] l.append(u"%s#R#/#l##b#%s#R#:#p#%s#R#" % ( img["repo"], img["name"], img["version"])) if o_md5 or o_long: l[-1] = l[-1] + u" (#y#%s#R#)" % img["md5"] if o_date or o_long: l.append(u" #l#date:#R# %s" % istools.time_rfc2822(img["date"])) if o_author or o_long: l.append(u" #l#author:#R# %s" % img["author"]) if o_size or o_long: l.append(u" #l#size:#R# %s" % istools.human_size(img["size"])) if o_url or o_long: l.append(u" #l#url:#R# %s" % img["url"]) if o_description or o_long: l.append(u" #l#description:#R# %s" % img["description"]) if o_format or o_long: l.append(u" #l#format:#R# %s" % img["format"]) if o_min_version or o_long: l.append(u" #l#is min version:#R# %s" % img["is_min_version"]) s = os.linesep.join(l) if len(s) > 0: out(s)
# -*- python -*- # -*- coding: utf-8 -*- import os import installsystems import installsystems.tools as istools namespace.context.update({'name': image.name, 'version': image.version, 'description': image.description, 'author': image.author, 'md5': image.md5, 'isversion': installsystems.version, 'tbuild': istools.time_rfc2822(image.date), 'tsetup': istools.time_rfc2822(namespace.setuptime)})