Exemplo n.º 1
0
    def _load_requirements(self, requirements_data):
        if requirements_data is None:
            return

        self._validate_requirements_data(requirements_data)
        result = []
        for r in requirements_data:
            versions = r.get('versions', None)
            if versions is None:
                result.append(PackageRelation.from_args((r['name'], )))
            else:
                for version in versions:
                    result.append(
                        PackageRelation.from_args(
                            ([r['name']] + version.split(None, 1))))
        return result
Exemplo n.º 2
0
    def _load_requirements(self, requirements_data):
        if requirements_data is None:
            return

        self._validate_requirements_data(requirements_data)
        result = []
        for r in requirements_data:
            versions = r.get('versions', None)
            if versions is None:
                result.append(PackageRelation.from_args((r['name'],)))
            else:
                for version in versions:
                    result.append(PackageRelation.from_args(
                        ([r['name']] + version.split(None, 1))
                    ))
        return result
Exemplo n.º 3
0
 def test_iter(self):
     it = iter(
         PackageRelation.from_args(("test", "<=", 2), ("test2", ">=", 3)))
     self.assertEqual("test", next(it).name)
     self.assertEqual("test2", next(it).name)
     with self.assertRaises(StopIteration):
         next(it)
Exemplo n.º 4
0
 def test_iter(self):
     it = iter(PackageRelation.from_args(
         ("test", "<=", 2), ("test2", ">=", 3))
     )
     self.assertEqual("test", next(it).name)
     self.assertEqual("test2", next(it).name)
     with self.assertRaises(StopIteration):
         next(it)
Exemplo n.º 5
0
    def _get_provides_from_rpm(self, pkg):
        """Gets the package provides from YumPackage.

        :param pkg: the YumPackage Instance
        :return: list of PackageRelation objects
        """
        provides = self._parse_package_relations(pkg.provides)
        append = provides.append
        for filename in pkg.returnFileEntries('file', True):
            append(PackageRelation(filename))
        return provides
Exemplo n.º 6
0
 def test_from_args(self):
     r = PackageRelation.from_args(("test", "<=", 2), ("test2", ),
                                   ("test3", ))
     self.assertEqual("test", r.name)
     self.assertEqual("<=", r.version.op)
     self.assertEqual(2, r.version.edge)
     self.assertEqual("test2", r.alternative.name)
     self.assertEqual(VersionRange(), r.alternative.version)
     self.assertEqual("test3", r.alternative.alternative.name)
     self.assertEqual(VersionRange(), r.alternative.alternative.version)
     self.assertIsNone(r.alternative.alternative.alternative)
Exemplo n.º 7
0
    def _parse_requirements(requirements):
        """Gets the list of relations from requirements.

        :param requirements: the list of requirement in next format:
                             'name [cmp version]|[alt [cmp version]]'
        """
        if requirements is not None:
            return set(
                PackageRelation.from_args(
                    *(x.split() for x in r.split("|"))) for r in requirements
            )
        return set()
Exemplo n.º 8
0
 def test_from_args(self):
     r = PackageRelation.from_args(
         ("test", "<=", 2), ("test2",), ("test3",)
     )
     self.assertEqual("test", r.name)
     self.assertEqual("<=", r.version.op)
     self.assertEqual(2, r.version.edge)
     self.assertEqual("test2", r.alternative.name)
     self.assertEqual(VersionRange(), r.alternative.version)
     self.assertEqual("test3", r.alternative.alternative.name)
     self.assertEqual(VersionRange(), r.alternative.alternative.version)
     self.assertIsNone(r.alternative.alternative.alternative)
Exemplo n.º 9
0
    def _parse_package_relations(relations):
        """Parses yum package relations.

        :param relations: list of tuples
                          (name, flags, (epoch, version, release))
        :return: list of PackageRelation objects
        """
        return [
            PackageRelation(
                x[0],
                VersionRange(_OPERATORS_MAPPING[x[1]], x[1]
                             and RpmPackageVersion(*x[2]))) for x in relations
        ]
Exemplo n.º 10
0
    def _get_provides_from_xml(self, pkg_tag):
        """Gets the package provides from package tag.

        Tag provides contains virtual packages.
        Tag files contains binary files that is provided by package.

        :param pkg_tag: the xml-tag with package description
        :return: list of PackageRelation objects
        """
        provides = self._get_relations(pkg_tag, "provides")
        files_iter = pkg_tag.iterfind("./main:format/main:file", _NAMESPACES)
        append = provides.append
        for file_tag in files_iter:
            append(PackageRelation(file_tag.text))
        return provides
    def _get_relations(self, dpkg, *names):
        """Gets the package relations.

        :param dpkg: the debian-package object
        :type dpkg: deb822.Packages
        :param names: the relation names
        :return: the list of PackageRelation objects
        """
        relations = list()
        for name in names:
            for variants in dpkg.relations[name]:
                relation = PackageRelation.from_args(
                    *(self._unparse_relation(v) for v in variants))
                if relation is not None:
                    relations.append(relation)
        return relations
Exemplo n.º 12
0
    def _get_relations(self, dpkg, *names):
        """Gets the package relations.

        :param dpkg: the debian-package object
        :type dpkg: deb822.Packages
        :param names: the relation names
        :return: the list of PackageRelation objects
        """
        relations = list()
        for name in names:
            for variants in dpkg.relations[name]:
                relation = PackageRelation.from_args(
                    *(self._unparse_relation(v) for v in variants)
                )
                if relation is not None:
                    relations.append(relation)
        return relations
Exemplo n.º 13
0
    def _get_relations(self, pkg_tag, name):
        """Gets package relations by name from package tag.

        :param pkg_tag: the xml-tag with package description
        :param name: the relations name
        :return: list of PackageRelation objects
        """
        relations = list()
        append = relations.append
        tags_iter = pkg_tag.iterfind("./main:format/rpm:%s/rpm:entry" % name,
                                     _NAMESPACES)
        for elem in tags_iter:
            append(
                PackageRelation.from_args(
                    self._unparse_relation_attrs(elem.attrib)))

        return relations
Exemplo n.º 14
0
    def _get_relations(self, pkg_tag, name):
        """Gets package relations by name from package tag.

        :param pkg_tag: the xml-tag with package description
        :param name: the relations name
        :return: list of PackageRelation objects
        """
        relations = list()
        append = relations.append
        tags_iter = pkg_tag.iterfind(
            "./main:format/rpm:%s/rpm:entry" % name,
            _NAMESPACES
        )
        for elem in tags_iter:
            append(PackageRelation.from_args(
                self._unparse_relation_attrs(elem.attrib)
            ))

        return relations