From 990b0e94152c2ec63629767449a2ecefbaa618e9 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 21 Aug 2011 16:05:58 +0100 Subject: [PATCH] Always create elements with a 'name' attribute --- tests/testselections.py | 2 +- zeroinstall/injector/model.py | 4 ++-- zeroinstall/injector/selections.py | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/testselections.py b/tests/testselections.py index a75af8e..ff83f0a 100755 --- a/tests/testselections.py +++ b/tests/testselections.py @@ -101,7 +101,7 @@ class TestSelections(BaseTest): feed = self.config.iface_cache.get_feed(iface) impl = model.ZeroInstallImplementation(feed, "foo bar=123", local_path = None) impl.version = model.parse_version('1.0') - impl.commands["run"] = model.Command(qdom.Element(namespaces.XMLNS_IFACE, 'command', {'path': 'dummy'}), None) + impl.commands["run"] = model.Command(qdom.Element(namespaces.XMLNS_IFACE, 'command', {'path': 'dummy', 'name': 'run'}), None) impl.add_download_source('http://localhost/bar.tgz', 1000, None) feed.implementations = {impl.id: impl} assert p.need_download() diff --git a/zeroinstall/injector/model.py b/zeroinstall/injector/model.py index dff6662..1ff7189 100644 --- a/zeroinstall/injector/model.py +++ b/zeroinstall/injector/model.py @@ -667,7 +667,7 @@ class Implementation(object): if "run" in self.commands: del self.commands["run"] else: - self.commands["run"] = Command(qdom.Element(XMLNS_IFACE, 'command', {'path': path}), None) + self.commands["run"] = Command(qdom.Element(XMLNS_IFACE, 'command', {'path': path, 'name': 'run'}), None) main = property(_get_main, _set_main) def is_available(self, stores): @@ -1090,7 +1090,7 @@ class ZeroInstallFeed(object): root_commands = {} if main: info("Note: @main on document element is deprecated in %s", self) - root_commands['run'] = Command(qdom.Element(XMLNS_IFACE, 'command', {'path': main}), None) + root_commands['run'] = Command(qdom.Element(XMLNS_IFACE, 'command', {'path': main, 'name': 'run'}), None) process_group(feed_element, root_attrs, [], [], root_commands) def get_distro_feed(self): diff --git a/zeroinstall/injector/selections.py b/zeroinstall/injector/selections.py index 3029ad8..353c3f6 100644 --- a/zeroinstall/injector/selections.py +++ b/zeroinstall/injector/selections.py @@ -111,6 +111,8 @@ class XMLSelection(Selection): assert self.feed def get_command(self, name): + if name not in self.commands: + raise model.SafeException("Command '{name}' not present in selections for {iface}".format(name = name, iface = self.interface)) return self.commands[name] def get_commands(self): @@ -188,7 +190,9 @@ class Selections(object): for aname, avalue in elem.attrs.iteritems(): digests.append('%s=%s' % (aname, avalue)) elif elem.name == 'command': - commands[elem.getAttribute('name')] = Command(elem, None) + name = elem.getAttribute('name') + assert name, "Missing name attribute on " + commands[name] = Command(elem, None) # For backwards compatibility, allow getting the digest from the ID sel_id = selection.attrs['id'] @@ -224,7 +228,7 @@ class Selections(object): root_sel = self.selections[self.interface] main = root_sel.attrs.get('main', None) if main is not None: - root_sel.commands['run'] = Command(Element(XMLNS_IFACE, 'command', {'path': main}), None) + root_sel.commands['run'] = Command(Element(XMLNS_IFACE, 'command', {'path': main, 'name': 'run'}), None) self.command = 'run' elif self.command == '': -- 2.11.4.GIT