Beispiel #1
0
	def getID(self, digest):
		if self.name in ('sha1new', 'sha256'):
			digest_str = digest.hexdigest()
		else:
			# Base32-encode newer algorithms to make the digest shorter.
			# We can't use base64 as Windows is case insensitive.
			# There's no need for padding (and = characters in paths cause problems for some software).
			digest_str = base64.b32encode(digest.digest()).rstrip(b'=').decode('ascii')
		return format_algorithm_digest_pair(self.name, digest_str)
Beispiel #2
0
 def getID(self, digest):
     if self.name in ('sha1new', 'sha256'):
         digest_str = digest.hexdigest()
     else:
         # Base32-encode newer algorithms to make the digest shorter.
         # We can't use base64 as Windows is case insensitive.
         # There's no need for padding (and = characters in paths cause problems for some software).
         digest_str = base64.b32encode(
             digest.digest()).rstrip(b'=').decode('ascii')
     return format_algorithm_digest_pair(self.name, digest_str)
Beispiel #3
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)"))

		for selection in root.childNodes:
			if selection.uri != XMLNS_IFACE:
				continue
			if selection.name != 'selection':
				continue

			requires = []
			digests = []
			for elem in selection.childNodes:
				if elem.uri != XMLNS_IFACE:
					continue
				elif elem.name == 'manifest-digest':
					for aname, avalue in elem.attrs.items():
						digests.append(zerostore.format_algorithm_digest_pair(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 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, selection.attrs, digests)
			self.selections[iface_uri] = s
Beispiel #4
0
		def process_impl(item, item_attrs, depends, bindings, commands):
			id = item.getAttribute('id')
			if id is None:
				raise InvalidInterface(_("Missing 'id' attribute on %s") % item)
			local_path = item_attrs.get('local-path')
			if local_dir and local_path:
				abs_local_path = os.path.abspath(os.path.join(local_dir, local_path))
				impl = ZeroInstallImplementation(self, id, abs_local_path)
			elif local_dir and (id.startswith('/') or id.startswith('.')):
				# For old feeds
				id = os.path.abspath(os.path.join(local_dir, id))
				impl = ZeroInstallImplementation(self, id, id)
			else:
				impl = ZeroInstallImplementation(self, id, None)
				if '=' in id:
					# In older feeds, the ID was the (single) digest
					impl.digests.append(id)
			if id in self.implementations:
				logger.warn(_("Duplicate ID '%(id)s' in feed '%(feed)s'"), {'id': id, 'feed': self})
			self.implementations[id] = impl

			impl.metadata = item_attrs
			try:
				version_mod = item_attrs.get('version-modifier', None)
				if version_mod:
					item_attrs['version'] += version_mod
					del item_attrs['version-modifier']
				version = item_attrs['version']
			except KeyError:
				raise InvalidInterface(_("Missing version attribute"))
			impl.version = parse_version(version)

			impl.commands = commands

			impl.released = item_attrs.get('released', None)
			impl.langs = item_attrs.get('langs', '').replace('_', '-')

			size = item.getAttribute('size')
			if size:
				impl.size = int(size)
			impl.arch = item_attrs.get('arch', None)
			try:
				stability = stability_levels[str(item_attrs['stability'])]
			except KeyError:
				stab = str(item_attrs['stability'])
				if stab != stab.lower():
					raise InvalidInterface(_('Stability "%s" invalid - use lower case!') % item_attrs.stability)
				raise InvalidInterface(_('Stability "%s" invalid') % item_attrs['stability'])
			if stability >= preferred:
				raise InvalidInterface(_("Upstream can't set stability to preferred!"))
			impl.upstream_stability = stability

			impl.bindings = bindings
			impl.requires = depends

			for elem in item.childNodes:
				if elem.uri != XMLNS_IFACE: continue
				if elem.name == 'archive':
					url = elem.getAttribute('href')
					if not url:
						raise InvalidInterface(_("Missing href attribute on <archive>"))
					size = elem.getAttribute('size')
					if not size:
						raise InvalidInterface(_("Missing size attribute on <archive>"))
					impl.add_download_source(url = url, size = int(size),
							extract = elem.getAttribute('extract'),
							start_offset = _get_long(elem, 'start-offset'),
							type = elem.getAttribute('type'))
				elif elem.name == 'manifest-digest':
					for aname, avalue in elem.attrs.items():
						if ' ' not in aname:
							impl.digests.append(zerostore.format_algorithm_digest_pair(aname, avalue))
				elif elem.name == 'recipe':
					recipe = Recipe()
					for recipe_step in elem.childNodes:
						if recipe_step.uri == XMLNS_IFACE and recipe_step.name == 'archive':
							url = recipe_step.getAttribute('href')
							if not url:
								raise InvalidInterface(_("Missing href attribute on <archive>"))
							size = recipe_step.getAttribute('size')
							if not size:
								raise InvalidInterface(_("Missing size attribute on <archive>"))
							recipe.steps.append(DownloadSource(None, url = url, size = int(size),
									extract = recipe_step.getAttribute('extract'),
									start_offset = _get_long(recipe_step, 'start-offset'),
									type = recipe_step.getAttribute('type')))
						elif recipe_step.uri == XMLNS_IFACE and recipe_step.name == 'rename':
							source = recipe_step.getAttribute('source')
							if not source:
								raise InvalidInterface(_("Missing source attribute on <rename>"))
							dest = recipe_step.getAttribute('dest')
							if not dest:
								raise InvalidInterface(_("Missing dest attribute on <rename>"))
							recipe.steps.append(RenameStep(source=source, dest=dest))
						else:
							logger.info(_("Unknown step '%s' in recipe; skipping recipe"), recipe_step.name)
							break
					else:
						impl.download_sources.append(recipe)
Beispiel #5
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!"
Beispiel #6
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!"