def testOverlay(self): for xml, expected in [('<overlay/>', '<overlay . on />'), ('<overlay src="usr"/>', '<overlay usr on />'), ('<overlay src="package" mount-point="/usr/games"/>', '<overlay package on /usr/games>')]: e = qdom.parse(StringIO(xml)) ol = model.process_binding(e) self.assertEquals(expected, str(ol)) doc = minidom.parseString('<doc/>') new_xml = str(ol._toxml(doc).toxml()) new_e = qdom.parse(StringIO(new_xml)) new_ol = model.process_binding(new_e) self.assertEquals(expected, str(new_ol))
def testOverlay(self): for xml, expected in [(b'<overlay/>', '<overlay . on />'), (b'<overlay src="usr"/>', '<overlay usr on />'), (b'<overlay src="package" mount-point="/usr/games"/>', '<overlay package on /usr/games>')]: e = qdom.parse(BytesIO(xml)) ol = model.process_binding(e) self.assertEqual(expected, str(ol)) doc = minidom.parseString('<doc/>') new_xml = ol._toxml(doc, None).toxml(encoding = 'utf-8') new_e = qdom.parse(BytesIO(new_xml)) new_ol = model.process_binding(new_e) self.assertEqual(expected, str(new_ol))
def _init_from_qdom(self, root): """Parse and load a selections document. @param root: a saved set of selections.""" self.interface = root.getAttribute('interface') assert self.interface for selection in root.childNodes: if selection.uri != XMLNS_IFACE: continue if selection.name != 'selection': continue requires = [] bindings = [] for dep_elem in selection.childNodes: if dep_elem.uri != XMLNS_IFACE: continue if dep_elem.name in binding_names: bindings.append(process_binding(dep_elem)) elif dep_elem.name == 'requires': dep = process_depends(dep_elem) requires.append(dep) s = Selection(requires, bindings, selection.attrs) self.selections[selection.attrs['interface']] = s
def _init_from_qdom(self, root): """Parse and load a selections document. @param root: a saved set of selections.""" self.interface = root.getAttribute('interface') assert self.interface self.commands = [] for selection in root.childNodes: if selection.uri != XMLNS_IFACE: continue if selection.name != 'selection': if selection.name == 'command': self.commands.append(Command(selection, None)) continue requires = [] bindings = [] digests = [] for dep_elem in selection.childNodes: if dep_elem.uri != XMLNS_IFACE: continue if dep_elem.name in binding_names: bindings.append(process_binding(dep_elem)) elif dep_elem.name == 'requires': dep = process_depends(dep_elem, None) requires.append(dep) elif dep_elem.name == 'manifest-digest': for aname, avalue in dep_elem.attrs.iteritems(): digests.append('%s=%s' % (aname, avalue)) # For backwards compatibility, allow getting the digest from the ID sel_id = selection.attrs['id'] local_path = selection.attrs.get("local-path", None) if (not digests and not local_path) and '=' in sel_id: alg = sel_id.split('=', 1)[0] if alg in ('sha1', 'sha1new', 'sha256'): digests.append(sel_id) iface_uri = selection.attrs['interface'] s = XMLSelection(requires, bindings, selection.attrs, digests) self.selections[iface_uri] = s if not self.commands: # Old-style selections document; use the main attribute if iface_uri == self.interface: root_sel = self.selections[self.interface] main = root_sel.attrs.get('main', None) if main is not None: self.commands = [ Command( Element(XMLNS_IFACE, 'command', {'path': main}), None) ]
def _init_from_qdom(self, root): """Parse and load a selections document. @param root: a saved set of selections.""" self.interface = root.getAttribute('interface') assert self.interface self.commands = [] for selection in root.childNodes: if selection.uri != XMLNS_IFACE: continue if selection.name != 'selection': if selection.name == 'command': self.commands.append(Command(selection, None)) continue requires = [] bindings = [] digests = [] for dep_elem in selection.childNodes: if dep_elem.uri != XMLNS_IFACE: continue if dep_elem.name in binding_names: bindings.append(process_binding(dep_elem)) elif dep_elem.name == 'requires': dep = process_depends(dep_elem, None) requires.append(dep) elif dep_elem.name == 'manifest-digest': for aname, avalue in dep_elem.attrs.iteritems(): digests.append('%s=%s' % (aname, avalue)) # For backwards compatibility, allow getting the digest from the ID sel_id = selection.attrs['id'] local_path = selection.attrs.get("local-path", None) if (not digests and not local_path) and '=' in sel_id: alg = sel_id.split('=', 1)[0] if alg in ('sha1', 'sha1new', 'sha256'): digests.append(sel_id) iface_uri = selection.attrs['interface'] s = XMLSelection(requires, bindings, selection.attrs, digests) self.selections[iface_uri] = s if not self.commands: # Old-style selections document; use the main attribute if iface_uri == self.interface: root_sel = self.selections[self.interface] main = root_sel.attrs.get('main', None) if main is not None: self.commands = [Command(Element(XMLNS_IFACE, 'command', {'path': main}), None)]
def _init_from_qdom(self, root): """Parse and load a selections document. @param root: a saved set of selections. @type root: L{Element}""" self.interface = root.getAttribute('interface') self.command = root.getAttribute('command') if self.interface is None: raise model.SafeException( _("Not a selections document (no 'interface' attribute on root)" )) old_commands = [] for selection in root.childNodes: if selection.uri != XMLNS_IFACE: continue if selection.name != 'selection': if selection.name == 'command': old_commands.append(Command(selection, None)) continue requires = [] bindings = [] digests = [] commands = {} for elem in selection.childNodes: if elem.uri != XMLNS_IFACE: continue if elem.name in binding_names: bindings.append(process_binding(elem)) elif elem.name == 'requires': dep = process_depends(elem, None) requires.append(dep) elif elem.name == 'manifest-digest': for aname, avalue in elem.attrs.items(): digests.append( zerostore.format_algorithm_digest_pair( aname, avalue)) elif elem.name == 'command': name = elem.getAttribute('name') assert name, "Missing name attribute on <command>" commands[name] = Command(elem, None) # For backwards compatibility, allow getting the digest from the ID sel_id = selection.attrs['id'] local_path = selection.attrs.get("local-path", None) if (not local_path) and '=' in sel_id: alg = sel_id.split('=', 1)[0] if alg in ('sha1', 'sha1new', 'sha256'): if sel_id not in digests: digests.append(sel_id) iface_uri = selection.attrs['interface'] s = XMLSelection(requires, bindings, selection.attrs, digests, commands) self.selections[iface_uri] = s if self.command is None: # Old style selections document if old_commands: # 0launch 0.52 to 1.1 self.command = 'run' iface = self.interface for command in old_commands: command.qdom.attrs['name'] = 'run' self.selections[iface].commands['run'] = command runner = command.get_runner() if runner: iface = runner.interface else: iface = None else: # 0launch < 0.51 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, 'name': 'run' }), None) self.command = 'run' elif self.command == '': # New style, but no command requested self.command = None assert not old_commands, "<command> list in new-style selections document!"
def _init_from_qdom(self, root): """Parse and load a selections document. @param root: a saved set of selections.""" self.interface = root.getAttribute('interface') self.command = root.getAttribute('command') assert self.interface old_commands = [] for selection in root.childNodes: if selection.uri != XMLNS_IFACE: continue if selection.name != 'selection': if selection.name == 'command': old_commands.append(Command(selection, None)) continue requires = [] bindings = [] digests = [] commands = {} for elem in selection.childNodes: if elem.uri != XMLNS_IFACE: continue if elem.name in binding_names: bindings.append(process_binding(elem)) elif elem.name == 'requires': dep = process_depends(elem, None) requires.append(dep) elif elem.name == 'manifest-digest': for aname, avalue in elem.attrs.items(): digests.append(zerostore.format_algorithm_digest_pair(aname, avalue)) elif elem.name == 'command': name = elem.getAttribute('name') assert name, "Missing name attribute on <command>" commands[name] = Command(elem, None) # For backwards compatibility, allow getting the digest from the ID sel_id = selection.attrs['id'] local_path = selection.attrs.get("local-path", None) if (not digests and not local_path) and '=' in sel_id: alg = sel_id.split('=', 1)[0] if alg in ('sha1', 'sha1new', 'sha256'): digests.append(sel_id) iface_uri = selection.attrs['interface'] s = XMLSelection(requires, bindings, selection.attrs, digests, commands) self.selections[iface_uri] = s if self.command is None: # Old style selections document if old_commands: # 0launch 0.52 to 1.1 self.command = 'run' iface = self.interface for command in old_commands: command.qdom.attrs['name'] = 'run' self.selections[iface].commands['run'] = command runner = command.get_runner() if runner: iface = runner.interface else: iface = None else: # 0launch < 0.51 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, 'name': 'run'}), None) self.command = 'run' elif self.command == '': # New style, but no command requested self.command = None assert not old_commands, "<command> list in new-style selections document!"