From 2205eeb0acd81662bf9439aba8fcecf3fbf0b5f8 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 5 Jul 2011 09:51:17 +0100 Subject: [PATCH] Display a deprecation warning if Selections(Policy) is used --- tests/testselections.py | 8 ++++---- zeroinstall/0launch-gui/bugs.py | 4 ++-- zeroinstall/0launch-gui/mainwindow.py | 2 +- zeroinstall/cmd/select.py | 2 +- zeroinstall/helpers.py | 2 +- zeroinstall/injector/selections.py | 6 ++++-- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/testselections.py b/tests/testselections.py index 90b5e14..7fbf4cc 100755 --- a/tests/testselections.py +++ b/tests/testselections.py @@ -68,7 +68,7 @@ class TestSelections(BaseTest): self.assertEquals(["sha1=345"], sels[0].digests) - s1 = selections.Selections(p) + s1 = p.solver.selections s1.selections['http://foo/Source.xml'].attrs['http://namespace foo'] = 'bar' assertSel(s1) @@ -85,7 +85,7 @@ class TestSelections(BaseTest): p = policy.Policy(iface, config = self.config) p.need_download() assert p.ready - s1 = selections.Selections(p) + s1 = p.solver.selections xml = s1.toDOM().toxml("utf-8") # Reload selections and check they're the same @@ -104,7 +104,7 @@ class TestSelections(BaseTest): feed.implementations = {impl.id: impl} assert p.need_download() assert p.ready, p.solver.get_failure_reason() - s1 = selections.Selections(p) + s1 = p.solver.selections xml = s1.toDOM().toxml("utf-8") root = qdom.parse(StringIO(xml)) s2 = selections.Selections(root) @@ -128,7 +128,7 @@ class TestSelections(BaseTest): dep_impl = p.solver.selections[self.config.iface_cache.get_interface(dep_impl_uri)] assert dep_impl.id == 'sha1=256' - s1 = selections.Selections(p) + s1 = p.solver.selections assert s1.commands[0].path == 'runnable/missing' xml = s1.toDOM().toxml("utf-8") root = qdom.parse(StringIO(xml)) diff --git a/zeroinstall/0launch-gui/bugs.py b/zeroinstall/0launch-gui/bugs.py index 62806a5..f4e80d9 100644 --- a/zeroinstall/0launch-gui/bugs.py +++ b/zeroinstall/0launch-gui/bugs.py @@ -58,7 +58,7 @@ def report_bug(policy, iface): text += '\nSystem without uname()\n' if policy.solver.ready: - sels = selections.Selections(policy) + sels = policy.solver.selections text += "\n" + sels.toDOM().toprettyxml(encoding = 'utf-8') reporter = BugReporter(policy, iface, text) @@ -191,7 +191,7 @@ class BugReporter(dialog.Dialog): return from zeroinstall.injector import selections - sels = selections.Selections(self.policy) + sels = self.policy.solver.selections doc = sels.toDOM() self.hide() diff --git a/zeroinstall/0launch-gui/mainwindow.py b/zeroinstall/0launch-gui/mainwindow.py index b1a5f50..4e0c30f 100644 --- a/zeroinstall/0launch-gui/mainwindow.py +++ b/zeroinstall/0launch-gui/mainwindow.py @@ -121,7 +121,7 @@ class MainWindow: dialog.alert(self.window, _('Not all downloads succeeded; cannot run program.\n\nFailed to get:') + '\n- ' + missing) else: from zeroinstall.injector import selections - sels = selections.Selections(self.policy) + sels = self.policy.solver.selections doc = sels.toDOM() reply = doc.toxml('utf-8') sys.stdout.write(('Length:%8x\n' % len(reply)) + reply) diff --git a/zeroinstall/cmd/select.py b/zeroinstall/cmd/select.py index 4d6dd31..787f3eb 100644 --- a/zeroinstall/cmd/select.py +++ b/zeroinstall/cmd/select.py @@ -131,7 +131,7 @@ def get_selections(config, options, iface_uri, select_only, download_only, test_ select_only = select_only) if downloaded: tasks.wait_for_blocker(downloaded) - sels = selections.Selections(policy) + sels = policy.solver.selections return sels diff --git a/zeroinstall/helpers.py b/zeroinstall/helpers.py index 81ef23d..c40000c 100644 --- a/zeroinstall/helpers.py +++ b/zeroinstall/helpers.py @@ -123,4 +123,4 @@ def ensure_cached(uri, command = 'run', config = None): done = p.solve_and_download_impls() tasks.wait_for_blocker(done) - return selections.Selections(p) + return p.solver.selections diff --git a/zeroinstall/injector/selections.py b/zeroinstall/injector/selections.py index 9f13c6d..7c02f43 100644 --- a/zeroinstall/injector/selections.py +++ b/zeroinstall/injector/selections.py @@ -113,7 +113,7 @@ class Selections(object): def __init__(self, source): """Constructor. @param source: a map of implementations, policy or selections document - @type source: {str: L{Selection}} | L{Policy} | L{Element} + @type source: L{Element} """ self.selections = {} @@ -121,11 +121,13 @@ class Selections(object): self.commands = [] # (Solver will fill everything in) elif isinstance(source, Policy): + import warnings + warnings.warn("Use policy.solver.selections instead", DeprecationWarning, 2) self._init_from_policy(source) elif isinstance(source, Element): self._init_from_qdom(source) else: - raise Exception(_("Source not a Policy or qdom.Element!")) + raise Exception(_("Source not a qdom.Element!")) def _init_from_policy(self, policy): """Set the selections from a policy. -- 2.11.4.GIT