Exemplo n.º 1
0
 def show_payloads(self, patterns, o_images=False, o_json=False):
     '''
     Show payloads inside manager
     '''
     # get payload list
     payloads = self.select_payloads(patterns)
     # display result
     if o_json:
         s = dumps(payloads)
     else:
         l = []
         for payname in sorted(payloads.keys()):
             pay = payloads[payname]
             l.append(u"#l##y#%s#R#" % payname)
             l.append(u" size: %s" % human_size(pay["size"]))
             l.append(u" directory: %s" % bool(pay["isdir"]))
             l.append(u" image count: %d" % len(pay["images"]))
             l.append(u" names: %s" % ", ".join(set((v["payname"] for v in pay["images"].values()))))
             if o_images:
                 l.append(u" images:")
                 for path, obj in pay["images"].items():
                     l.append(u"   %s#R#/#l##b#%s#R#:#p#%s#R# (%s)" % (
                             obj["repo"], obj["imgname"], obj["imgver"], obj["payname"]))
         s = linesep.join(l)
     if len(s) > 0:
         out(s)
Exemplo n.º 2
0
 def show_all(self):
     '''
     Show changelog for all versions
     '''
     for ver in sorted(self, strvercmp,  reverse=True):
         out(u'-- #purple#version:#reset# %s' % ver)
         out(linesep.join(self[ver]))
Exemplo n.º 3
0
 def diff(repo1, repo2):
     '''
     Compute a diff between two repositories
     '''
     arrow(u"Diff between repositories #y#%s#R# and #g#%s#R#" % (repo1.config.name,
                                                                 repo2.config.name))
     # Get info from databases
     i_dict1 = dict((b[0], b[1:]) for b in repo1.db.ask(
         "SELECT md5, name, version FROM image").fetchall())
     i_set1 = set(i_dict1.keys())
     i_dict2 = dict((b[0], b[1:]) for b in repo2.db.ask(
         "SELECT md5, name, version FROM image").fetchall())
     i_set2 = set(i_dict2.keys())
     p_dict1 = dict((b[0], b[1:]) for b in  repo1.db.ask(
         "SELECT md5, name FROM payload").fetchall())
     p_set1 = set(p_dict1.keys())
     p_dict2 = dict((b[0], b[1:]) for b in repo2.db.ask(
         "SELECT md5, name FROM payload").fetchall())
     p_set2 = set(p_dict2.keys())
     # computing diff
     i_only1 = i_set1 - i_set2
     i_only2 = i_set2 - i_set1
     p_only1 = p_set1 - p_set2
     p_only2 = p_set2 - p_set1
     # printing functions
     pimg = lambda r,c,m,d,: out("#%s#Image only in repository %s: %s v%s (%s)#R#" %
                                 (c, r.config.name, d[m][0], d[m][1], m))
     ppay = lambda r,c,m,d,: out("#%s#Payload only in repository %s: %s (%s)#R#" %
                                 (c, r.config.name, d[m][0], m))
     # printing image diff
     for md5 in i_only1: pimg(repo1, "y", md5, i_dict1)
     for md5 in p_only1: ppay(repo1, "y", md5, p_dict1)
     for md5 in i_only2: pimg(repo2, "g", md5, i_dict2)
     for md5 in p_only2: ppay(repo2, "g", md5, p_dict2)
Exemplo n.º 4
0
 def cat(self, filename):
     '''
     Display filename in the tarball
     '''
     filelist = self._tarball.getnames(glob_pattern=filename, dir=False)
     if len(filelist) == 0:
         warn(u"No file matching %s" % filename)
     for filename in filelist:
         arrow(filename)
         out(self._tarball.get_utf8(filename))
Exemplo n.º 5
0
 def show(self, version=None):
     '''
     Show changelog for a given version
     '''
     assert(isinstance(version, unicode))
     # if no version take the hightest
     if version is None:
         version = max(self, strvercmp)
     # display asked version
     if version in self:
         out(linesep.join(self[version]))
Exemplo n.º 6
0
 def print_tb(self, fd=stderr):
     '''
     Print traceback from embeded exception or current one
     '''
     from installsystems.printer import out
     # coloring
     out("#l##B#", fd=fd, endl="")
     print_exc(file=fd)
     self.print_sub_tb(fd)
     # reset color
     out("#R#", fd=fd, endl="")
Exemplo n.º 7
0
 def show_repositories(self, patterns, local=None, online=None, o_url=False,
                       o_state=False, o_uuid=False, o_json=False, o_version=False):
     '''
     Show repository inside manager
     if :param online: is true, list only online repositories
     if :param online: is false, list only offline repostiories
     if :param online: is None, list both online and offline repostiories.
     if :param local: is true, list only local repositories
     if :param local: is false, list only remote repostiories
     if :param local: is None, list both local and remote repostiories.
     '''
     # build repositories dict
     repos = {}
     for reponame in self.select_repositories(patterns):
         repo = self[reponame]
         if repo.config.offline and online is True:
             continue
         if not repo.config.offline and online is False:
             continue
         if repo.local and local is False:
             continue
         if not repo.local and local is True:
             continue
         repos[reponame] = dict(repo.config.items())
         repos[reponame]["local"] = repo.local
         if not repo.config.offline:
             repos[reponame]["uuid"] = repo.uuid
             repos[reponame]["version"] = repo.version
     # display result
     if o_json:
         s = dumps(repos)
     else:
         l = []
         for name, repo in repos.items():
             ln = ""
             so = "#l##r#Off#R# " if repo["offline"] else "#l##g#On#R#  "
             sl = "#l##y#Local#R#  " if repo["local"] else "#l##c#Remote#R# "
             rc = "#l##r#" if repo["offline"] else "#l##g#"
             if o_state:
                 ln +=  u"%s%s " % (so, sl)
                 rc = "#l##b#"
             ln += u"%s%s#R#"% (rc, name)
             if o_url:
                 ln += u"  (%s)" % repo["path"]
             if not repo["offline"]:
                 if o_version:
                     ln += u"  (#p#v%s#R#)" % repo["version"]
                 if o_uuid and repo["uuid"] is not None:
                     ln += u"  [%s]" % repo["uuid"]
             l.append(ln)
         s = linesep.join(l)
     out(s)
Exemplo n.º 8
0
 def search(self, pattern):
     '''
     Search pattern in a repository
     '''
     images = self.db.ask("SELECT name, version, author, description\
                           FROM image\
                           WHERE name LIKE ? OR\
                           description LIKE ? OR\
                           author LIKE ?",
                          tuple( [u"%%%s%%" % pattern ] * 3)
                          ).fetchall()
     for name, version, author, description in images:
         arrow(u"%s v%s" % (name, version), 1)
         out(u"   #yellow#Author:#reset# %s" % author)
         out(u"   #yellow#Description:#reset# %s" % description)
Exemplo n.º 9
0
 def check(self):
     '''
     Check repository for unreferenced and missing files
     '''
     # Check if the repo is local
     if not self.local:
         raise ISError(u"Repository must be local")
     local_files = set(listdir(self.config.path))
     local_files.remove(self.config.dbname)
     local_files.remove(self.config.lastname)
     db_files = set(self.getallmd5())
     # check missing files
     arrow("Checking missing files")
     missing_files = db_files - local_files
     if len(missing_files) > 0:
         out(linesep.join(missing_files))
     # check unreferenced files
     arrow("Checking unreferenced files")
     unref_files = local_files - db_files
     if len(unref_files) > 0:
         out(linesep.join(unref_files))
     # check corruption of local files
     arrow("Checking corrupted files")
     for f in local_files:
         fo = PipeFile(join(self.config.path, f))
         fo.consume()
         fo.close()
         if fo.md5 != f:
             out(f)
Exemplo n.º 10
0
 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 = 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" % 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" % 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 = linesep.join(l)
     if len(s) > 0:
         out(s)
Exemplo n.º 11
0
 def diff(cls, pkg1, pkg2):
     '''
     Diff two packaged images
     '''
     arrow(u"Difference from images #y#%s v%s#R# to #r#%s v%s#R#:" % (pkg1.name,
                                                                      pkg1.version,
                                                                      pkg2.name,
                                                                      pkg2.version))
     # extract images for diff scripts files
     fromfiles = set(pkg1._tarball.getnames(re_pattern="(parser|setup)/.*"))
     tofiles = set(pkg2._tarball.getnames(re_pattern="(parser|setup)/.*"))
     for f in fromfiles | tofiles:
         # preparing from info
         if f in fromfiles:
             fromfile = join(pkg1.filename, f)
             fromdata = pkg1._tarball.extractfile(f).readlines()
         else:
             fromfile = "/dev/null"
             fromdata = ""
         # preparing to info
         if f in tofiles:
             tofile = join(pkg2.filename, f)
             todata = pkg2._tarball.extractfile(f).readlines()
         else:
             tofile = "/dev/null"
             todata = ""
         # generate diff
         for line in unified_diff(fromdata,
                                  todata,
                                  fromfile=fromfile,
                                  tofile=tofile):
             # coloring diff
             if line.startswith("+"):
                out(u"#g#%s#R#" % line, endl="")
             elif line.startswith("-"):
                out(u"#r#%s#R#" % line, endl="")
             elif line.startswith("@@"):
                out(u"#c#%s#R#" % line, endl="")
             else:
                out(line, endl="")
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
# -*- python -*-
# -*- coding: utf-8 -*-

from installsystems.printer import out

out('*' * 80)

out('Root password: #light##red#%s#reset#' % namespace.passwd)
if namespace.user is not None:
    out('User %s password: #light##yellow#%s#reset#' % (namespace.user,
                                                     namespace.user_passwd))
out('Rsync secret: #light##purple#%s#reset#' % namespace.rsyncd)
out('Mac address: #light##blue#%s#reset#' % namespace.mac)

out('*' * 80)