From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QF2TK-0003Ur-Ut for garchives@archives.gentoo.org; Wed, 27 Apr 2011 10:59:55 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3BDE41C083; Wed, 27 Apr 2011 10:58:43 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id EA9CA1C057 for ; Wed, 27 Apr 2011 10:58:42 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 330801BC014 for ; Wed, 27 Apr 2011 10:58:42 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 89D3D80505 for ; Wed, 27 Apr 2011 10:58:41 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <4c51f94ca343338c0d266fae5c5ab6500df5e258.dol-sen@gentoo> Subject: [gentoo-commits] proj/layman:master commit in: layman/ X-VCS-Repository: proj/layman X-VCS-Files: layman/dbbase.py X-VCS-Directories: layman/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 4c51f94ca343338c0d266fae5c5ab6500df5e258 Date: Wed, 27 Apr 2011 10:58:41 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 22bd0b63dc1ce7aa3dee080ecd5f2d13 commit: 4c51f94ca343338c0d266fae5c5ab6500df5e258 Author: Brian Dolbec gmail com> AuthorDate: Thu Feb 24 06:10:33 2011 +0000 Commit: Brian Dolbec gmail com> CommitDate: Thu Feb 24 06:49:58 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/layman.git;a=3D= commit;h=3D4c51f94c add 2 new functions, add_new & add_from_dict. Modify the __init__ params a bit whitespace additions between functions. --- layman/dbbase.py | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 44 insertions(+), 2 deletions(-) diff --git a/layman/dbbase.py b/layman/dbbase.py index 5d082a0..53c2946 100644 --- a/layman/dbbase.py +++ b/layman/dbbase.py @@ -76,7 +76,9 @@ class BrokenOverlayCatalog(ValueError): class DbBase: ''' Handle a list of overlays.''' =20 - def __init__(self, paths, config, ignore =3D 0, quiet =3D False, ign= ore_init_read_errors=3DFalse): + def __init__(self, config, paths=3DNone, ignore =3D 0, + quiet =3D False, ignore_init_read_errors=3DFalse + ): =20 self.config =3D config self.quiet =3D quiet @@ -97,15 +99,18 @@ class DbBase: except Exception, error: if not ignore_init_read_errors: raise error =20 + def __eq__(self, other): for key in set(self.overlays.keys() + other.overlays.keys()): if self.overlays[key] !=3D other.overlays[key]: return False return True =20 + def __ne__(self, other): return not self.__eq__(other) =20 + def read_file(self, path): '''Read the overlay definition file.''' =20 @@ -118,11 +123,13 @@ class DbBase: =20 self.read(document, origin=3Dpath) =20 + def _broken_catalog_hint(self): this_function_name =3D sys._getframe().f_code.co_name raise NotImplementedError('Method "%s.%s" not implemented' % \ (self.__class__.__name__, this_function_name)) =20 + def read(self, text, origin): ''' Read an xml list of overlays (adding to and potentially overwrit= ing existing entries) @@ -147,11 +154,46 @@ class DbBase: for overlay in overlays: self.output.debug('Parsing overlay entry', 8) try: - ovl =3D Overlay(overlay, self.config, self.ignore, self.= quiet) + ovl =3D Overlay(config=3Dself.config, xml=3Doverlay, + ignore=3Dself.ignore, quiet=3Dself.quiet) + except Exception, error: + raise error + self.output.warn("DbBase(); Error creating overlay insta= nce", 3) + self.output.warn("Original error was: " + str(error), 3) + else: + self.overlays[ovl.name] =3D ovl + return + + + def add_new(self, xml=3DNone, origin=3DNone, from_dict=3DNone): + '''Reads xml text and dictionary definitions and adds + them to the db. + ''' + if xml: + self.read(xml, origin) + if from_dict: + self.output.info("DbBase: add_new() from_dict") + if isinstance(from_dict, dict): + from_dict =3D [from_dict] + self.add_from_dict(from_dict) + + return + + + def add_from_dict(self, overlays=3DNone): + """Add a new overlay from a list of dictionary values + """ + self.output.info("DbBase: add_from_dict()") + for overlay in overlays: + self.output.debug('Parsing overlay entry', 8) + try: + ovl =3D Overlay(self.config, ovl_dict=3Doverlay, + ignore=3Dself.ignore, quiet=3Dself.quiet) except Exception, error: self.output.warn(str(error), 3) else: self.overlays[ovl.name] =3D ovl + return =20 =20 def write(self, path):