From ac48aab8e05b11f67c19db054ed231311429c4b3 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Sun, 8 Mar 2009 20:51:27 +0000 Subject: [PATCH] Merged from trunk -r12764:12771 | 12765 | Fix failure exit status. Thanks to Brian Harring. | | zmedico | | | 12766 | whitespace cleanup | | zmedico | | | 12767 | Make digraph store a single priority list for each edge | | zmedico | instead of two identical lists. | | 12768 | Send message about unset RESUMECOMMAND to stderr instead of | | zmedico | stdout. | | 12769 | Define __slots__ for classes derived from ObjectProxy. | | zmedico | | | 12770 | Remove unused import. | | zmedico | | | 12771 | Add keyword argument support to LazyItemsDict.update(). | | zmedico | | svn path=/main/branches/prefix/; revision=12786 --- pym/portage/__init__.py | 32 ++++++++++++++++++++++++-------- pym/portage/news.py | 14 +++++++------- pym/portage/tests/runTests | 2 +- pym/portage/util.py | 19 ++++++++++++++++--- 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 8d676b241..4ac8bffc2 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -369,11 +369,11 @@ class digraph(object): self.nodes[parent] = ({}, {}, parent) self.order.append(parent) - priorities = self.nodes[node][1].setdefault(parent, []) - priorities.append(priority) - priorities.sort() - - priorities = self.nodes[parent][0].setdefault(node, []) + priorities = self.nodes[node][1].get(parent) + if priorities is None: + priorities = [] + self.nodes[node][1][parent] = priorities + self.nodes[parent][0][node] = priorities priorities.append(priority) priorities.sort() @@ -561,13 +561,22 @@ class digraph(object): def clone(self): clone = digraph() clone.nodes = {} + memo = {} for children, parents, node in self.nodes.itervalues(): children_clone = {} for child, priorities in children.iteritems(): - children_clone[child] = priorities[:] + priorities_clone = memo.get(id(priorities)) + if priorities_clone is None: + priorities_clone = priorities[:] + memo[id(priorities)] = priorities_clone + children_clone[child] = priorities_clone parents_clone = {} for parent, priorities in parents.iteritems(): - parents_clone[parent] = priorities[:] + priorities_clone = memo.get(id(priorities)) + if priorities_clone is None: + priorities_clone = priorities[:] + memo[id(priorities)] = priorities_clone + parents_clone[parent] = priorities_clone clone.nodes[node] = (children_clone, parents_clone, node) clone.order = self.order[:] return clone @@ -4102,7 +4111,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", "have been defined in\n!!! %s/make.globals.\n") \ % (resumecommand_var, portage.const.GLOBAL_CONFIG_PATH), - noiselevel=-1) + level=logging.ERROR, noiselevel=-1) return 0 if "${FILE}" not in resumecommand: portage.util.writemsg_level( @@ -8005,6 +8014,9 @@ class _LegacyGlobalProxy(proxy.objectproxy.ObjectProxy): Instances of these serve as proxies to global variables that are initialized on demand. """ + + __slots__ = ('_name',) + def __init__(self, name): proxy.objectproxy.ObjectProxy.__init__(self) object.__setattr__(self, '_name', name) @@ -8021,6 +8033,8 @@ class _PortdbProxy(proxy.objectproxy.ObjectProxy): are needed while the portdb is not. """ + __slots__ = () + def _get_target(self): init_legacy_globals() global db, portdb, root, _portdb_initialized @@ -8034,6 +8048,8 @@ class _MtimedbProxy(proxy.objectproxy.ObjectProxy): The mtimedb is independent from the portdb and other globals. """ + __slots__ = ('_name',) + def __init__(self, name): proxy.objectproxy.ObjectProxy.__init__(self) object.__setattr__(self, '_name', name) diff --git a/pym/portage/news.py b/pym/portage/news.py index b20fd422e..750df3dd6 100644 --- a/pym/portage/news.py +++ b/pym/portage/news.py @@ -148,10 +148,10 @@ class NewsManager(object): If update is specified, updateNewsItems( repoid ) will be called to check for new items. """ - + if update: self.updateItems(repoid) - + unread_filename = self._unread_filename(repoid) unread_lock = None try: @@ -182,9 +182,9 @@ class NewsItem(object): Creation of a news item involves passing in the path to the particular news item. """ - + def __init__(self, path, name): - """ + """ For a given news item we only want if it path is a file. """ self.path = path @@ -206,7 +206,7 @@ class NewsItem(object): if not len(self.restrictions): return True # no restrictions to match means everyone should see it - + kwargs = \ { 'vardb' : vardb, 'config' : config, @@ -215,7 +215,7 @@ class NewsItem(object): for restriction in self.restrictions: if restriction.checkRestriction(**kwargs): return True - + return False # No restrictions were met; thus we aren't relevant :( def isValid(self): @@ -301,7 +301,7 @@ class DisplayInstalledRestriction(DisplayRestriction): An Installation restriction where a particular item shall only be displayed if the user has that item installed. """ - + def __init__(self, atom): self.atom = atom diff --git a/pym/portage/tests/runTests b/pym/portage/tests/runTests index ab765b193..3bf8e3d3e 100755 --- a/pym/portage/tests/runTests +++ b/pym/portage/tests/runTests @@ -16,5 +16,5 @@ import portage.tests as tests if __name__ == "__main__": result = tests.main() - if result.failures: + if not result.wasSuccessful(): sys.exit(1) diff --git a/pym/portage/util.py b/pym/portage/util.py index d1032f7b9..9461512e2 100644 --- a/pym/portage/util.py +++ b/pym/portage/util.py @@ -19,7 +19,6 @@ import shlex import stat import string import sys -import types from portage.exception import PortageException, FileNotFound, \ OperationNotPermitted, PermissionDenied, ReadOnlyFileSystem @@ -1086,8 +1085,19 @@ class LazyItemsDict(dict): self.addLazyItem(item_key, self._SingletonWrapper(self, item_key, value_callable, *pargs, **kwargs)) - def update(self, map_obj): - if isinstance(map_obj, LazyItemsDict): + + def update(self, *args, **kwargs): + if len(args) > 1: + raise TypeError( + "expected at most 1 positional argument, got " + \ + repr(len(args))) + if args: + map_obj = args[0] + else: + map_obj = None + if map_obj is None: + pass + elif isinstance(map_obj, LazyItemsDict): for k in map_obj: if k in map_obj.lazy_items: dict.__setitem__(self, k, None) @@ -1096,6 +1106,9 @@ class LazyItemsDict(dict): self.lazy_items.update(map_obj.lazy_items) else: dict.update(self, map_obj) + if kwargs: + dict.update(self, kwargs) + def __getitem__(self, item_key): if item_key in self.lazy_items: value_callable, pargs, kwargs = self.lazy_items[item_key] -- 2.26.2