Пример #1
0
    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
Пример #2
0
    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)
                    ]
Пример #3
0
	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)]
Пример #4
0
def add_binary_deps(src_impl, binary_impl):
	# If src_impl contains a template, add those dependencies to the potential binary.
	# Note: probably we should add "include-binary" dependencies here too...

	compile_command = src_impl.commands['compile']

	for elem in compile_command.qdom.childNodes:
		if elem.uri == XMLNS_0COMPILE and elem.name == 'implementation':
			template = elem
			break
	else:
		return	# No template

	for elem in template.childNodes:
		if elem.uri == namespaces.XMLNS_IFACE and elem.name in ('requires', 'restricts', 'runner'):
			dep = model.process_depends(elem, local_feed_dir = None)
			binary_impl.requires.append(dep)
Пример #5
0
	def get_feed(self, master_feed):
		"""Generate a feed containing information about distribution packages.
		This should immediately return a feed containing an implementation for the
		package if it's already installed. Information about versions that could be
		installed using the distribution's package manager can be added asynchronously
		later (see L{fetch_candidates}).
		@param master_feed: feed containing the <package-implementation> elements
		@type master_feed: L{model.ZeroInstallFeed}
		@rtype: L{model.ZeroInstallFeed}"""

		feed = model.ZeroInstallFeed(None)
		feed.url = 'distribution:' + master_feed.url

		for item, item_attrs, depends in master_feed.get_package_impls(self):
			package = item_attrs.get('package', None)
			if package is None:
				raise model.InvalidInterface(_("Missing 'package' attribute on %s") % item)

			new_impls = []

			def factory(id, only_if_missing = False, installed = True):
				assert id.startswith('package:')
				if id in feed.implementations:
					if only_if_missing:
						return None
					logger.warning(_("Duplicate ID '%s' for DistributionImplementation"), id)
				impl = model.DistributionImplementation(feed, id, self, item)
				feed.implementations[id] = impl
				new_impls.append(impl)

				impl.installed = installed
				impl.metadata = item_attrs
				impl.requires = depends

				if 'run' not in impl.commands:
					item_main = item_attrs.get('main', None)
					if item_main:
						if item_main.startswith('/'):
							impl.main = item_main
						else:
							raise model.InvalidInterface(_("'main' attribute must be absolute, but '%s' doesn't start with '/'!") %
										item_main)
				impl.upstream_stability = model.packaged

				return impl

			self.get_package_info(package, factory)

			for impl in new_impls:
				self.fixup(package, impl)
				if impl.installed:
					self.installed_fixup(impl)

		if master_feed.url == _PYTHON_URI and os.name != "nt":
			# Hack: we can support Python on platforms with unsupported package managers
			# by adding the implementation of Python running us now to the list.
			python_version = '.'.join([str(v) for v in sys.version_info if isinstance(v, int)])
			impl_id = 'package:host:python:' + python_version
			assert impl_id not in feed.implementations
			impl = model.DistributionImplementation(feed, impl_id, self, distro_name = 'host')
			impl.installed = True
			impl.version = model.parse_version(python_version)
			impl.main = sys.executable
			impl.upstream_stability = model.packaged
			impl.machine = host_machine	# (hopefully)
			feed.implementations[impl_id] = impl
		elif master_feed.url == 'http://repo.roscidus.com/python/python-gobject' and os.name != "nt":
			# Likewise, we know that there is a native python-gobject available for our Python
			from zeroinstall import gobject
			impl_id = 'package:host:python-gobject:' + '.'.join(str(x) for x in gobject.pygobject_version)
			assert impl_id not in feed.implementations
			impl = model.DistributionImplementation(feed, impl_id, self, distro_name = 'host')
			impl.installed = True
			impl.version = [list(gobject.pygobject_version)]
			impl.upstream_stability = model.packaged
			impl.machine = host_machine	# (hopefully)

			# Requires our version of Python too
			restriction_element = qdom.Element(namespaces.XMLNS_IFACE, 'restricts', {'interface': _PYTHON_URI, 'distribution': 'host'})
			impl.requires.append(model.process_depends(restriction_element, None))

			feed.implementations[impl_id] = impl

		return feed
Пример #6
0
    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!"
Пример #7
0
	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!"