From d34dbcf6150ac8b759985084129a1658ad1ce535 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 14 Nov 2010 11:23:06 +0000 Subject: [PATCH] Show command dependencies in GUI and --show output --- tests/testlaunch.py | 8 ++++++++ tests/testselections.py | 7 +++++++ zeroinstall/0launch-gui/iface_browser.py | 18 ++++++++++++------ zeroinstall/injector/cli.py | 13 +++++++++---- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/tests/testlaunch.py b/tests/testlaunch.py index 3da9573..f59b132 100755 --- a/tests/testlaunch.py +++ b/tests/testlaunch.py @@ -13,6 +13,8 @@ from zeroinstall.injector import autopolicy, model, cli, namespaces, qdom, selec from zeroinstall.zerostore import Store; Store._add_with_helper = lambda *unused: False from zeroinstall.support import basedir +mydir = os.path.abspath(os.path.dirname(__file__)) + class SilenceLogger(logging.Filter): def filter(self, record): return 0 @@ -221,5 +223,11 @@ class TestLaunch(BaseTest): finally: os.dup2(copy, 1) + def testShow(self): + command_feed = os.path.join(mydir, 'Command.xml') + out, err = self.run_0launch(['--show', command_feed]) + self.assertEquals("", err) + assert 'Local.xml' in out, out + if __name__ == '__main__': unittest.main() diff --git a/tests/testselections.py b/tests/testselections.py index 02c2415..4330dad 100755 --- a/tests/testselections.py +++ b/tests/testselections.py @@ -110,6 +110,10 @@ class TestSelections(BaseTest): assert impl.id == 'c' assert impl.main == 'baz' + dep_impl_uri = impl.commands['run'].requires[0].interface + dep_impl = p.solver.selections[iface_cache.iface_cache.get_interface(dep_impl_uri)] + assert dep_impl.id == 'sha1=256' + s1 = selections.Selections(p) assert s1.command.path == 'baz' xml = s1.toDOM().toxml("utf-8") @@ -124,5 +128,8 @@ class TestSelections(BaseTest): custom_element = s2.command.qdom.childNodes[0] assert custom_element.name == 'child' + dep_impl = s2.selections[dep_impl_uri] + assert dep_impl.id == 'sha1=256' + if __name__ == '__main__': unittest.main() diff --git a/zeroinstall/0launch-gui/iface_browser.py b/zeroinstall/0launch-gui/iface_browser.py index b638de1..595b0b9 100644 --- a/zeroinstall/0launch-gui/iface_browser.py +++ b/zeroinstall/0launch-gui/iface_browser.py @@ -323,7 +323,7 @@ class InterfaceBrowser: self.model.clear() parent = None - def add_node(parent, iface): + def add_node(parent, iface, command = None): if iface in done: return done[iface] = True @@ -334,8 +334,9 @@ class InterfaceBrowser: self.model[iter][InterfaceBrowser.SUMMARY] = iface.summary self.model[iter][InterfaceBrowser.ICON] = self.get_icon(iface) or self.default_icon - impl = self.policy.implementation.get(iface, None) - if impl: + sel = self.policy.solver.selections.selections.get(iface.uri, None) + if sel: + impl = sel.impl old_impl = self.original_implementation.get(iface, None) version_str = impl.get_version() if old_impl is not None and old_impl.id != impl.id: @@ -343,9 +344,11 @@ class InterfaceBrowser: self.model[iter][InterfaceBrowser.VERSION] = version_str self.model[iter][InterfaceBrowser.DOWNLOAD_SIZE] = utils.get_fetch_info(self.policy, impl) - children = self.policy.solver.requires[iface] - for child in children: + deps = sel.dependencies + if command: + deps += command.requires + for child in deps: if isinstance(child, model.InterfaceDependency): add_node(iter, iface_cache.get_interface(child.interface)) else: @@ -356,7 +359,7 @@ class InterfaceBrowser: self.model[child_iter][InterfaceBrowser.ICON] = self.default_icon else: self.model[iter][InterfaceBrowser.VERSION] = _('(choose)') - add_node(None, self.root) + add_node(None, self.root, self.policy.solver.selections.command) self.tree_view.expand_all() def show_popup_menu(self, iface, bev): @@ -406,6 +409,9 @@ class InterfaceBrowser: """Called at regular intervals while there are downloads in progress, and once at the end. Also called when things are added to the store. Update the TreeView with the interfaces.""" + + # A download may be for a feed, an interface or an implementation. + # Create the reverse mapping (item -> download) hints = {} for dl in self.policy.handler.monitored_downloads.values(): if dl.hint: diff --git a/zeroinstall/injector/cli.py b/zeroinstall/injector/cli.py index 7fa76b8..b4290e3 100644 --- a/zeroinstall/injector/cli.py +++ b/zeroinstall/injector/cli.py @@ -313,7 +313,7 @@ def _get_selections(sels, options): if options.show: from zeroinstall import zerostore done = set() # detect cycles - def print_node(uri, indent): + def print_node(uri, command, indent): if uri in done: return done.add(uri) impl = sels.selections.get(uri, None) @@ -329,14 +329,19 @@ def _get_selections(sels, options): path = "(not cached)" print indent + " Path:", path indent += " " - for child in impl.dependencies: + deps = impl.dependencies + if command: + deps += command.requires + for child in deps: if isinstance(child, model.InterfaceDependency): - print_node(child.interface, indent) + print_node(child.interface, None, indent) else: print indent + " No selected version" - print_node(sels.interface, "") + uri = sels.interface + print_node(uri, sels.command, "") + else: doc = sels.toDOM() doc.writexml(sys.stdout) -- 2.11.4.GIT