def test_versioned(self): astr = "app-arch/tarsync" le_cpv = CPV.versioned("%s-0" % astr) eq_cpv = CPV.versioned("%s-1.1-r2" % astr) ge_cpv = CPV.versioned("%s-2" % astr) # <, =, > ops = (-1, 0, 1) for ops, ver in ((-1, "1.0"), (-1, "1.1"), (0, "1.1-r2"), (1, "1.1-r3"), (1, "1.2")): if not isinstance(ops, (list, tuple)): ops = (ops,) a = self.make_atom(astr, ops, ver) if -1 in ops: self.assertMatch(a, ge_cpv) self.assertMatch(a, eq_cpv) self.assertNotMatch(a, le_cpv) if 0 in ops: self.assertTrue(a.match(eq_cpv)) if ops == (0,): self.assertNotMatch(a, le_cpv) self.assertNotMatch(a, ge_cpv) if 1 in ops: self.assertNotMatch(a, ge_cpv) self.assertMatch(a, eq_cpv) self.assertMatch(a, le_cpv)
def test_versioned(self): astr = "app-arch/tarsync" le_cpv = CPV.versioned(f"{astr}-0") eq_cpv = CPV.versioned(f"{astr}-1.1-r2") ge_cpv = CPV.versioned(f"{astr}-2") # <, =, > ops = (-1, 0, 1) for ops, ver in ((-1, "1.0"), (-1, "1.1"), (0, "1.1-r2"), (1, "1.1-r3"), (1, "1.2")): if not isinstance(ops, (list, tuple)): ops = (ops,) a = self.make_atom(astr, ops, ver) if -1 in ops: self.assertMatch(a, ge_cpv) self.assertMatch(a, eq_cpv) self.assertNotMatch(a, le_cpv) if 0 in ops: self.assertTrue(a.match(eq_cpv)) if ops == (0,): self.assertNotMatch(a, le_cpv) self.assertNotMatch(a, ge_cpv) if 1 in ops: self.assertNotMatch(a, ge_cpv) self.assertMatch(a, eq_cpv) self.assertMatch(a, le_cpv)
def test_pkg_provided(self): self.assertEqual(self.klass(pjoin(self.dir, self.profile)).pkg_provided, ((), ())) self.parsing_checks("package.provided", "pkg_provided") self.write_file("package.provided", "-dev-util/diffball-1.0") self.assertEqual( self.klass(pjoin(self.dir, self.profile)).pkg_provided, ((CPV.versioned("dev-util/diffball-1.0"),), ()) ) self.write_file("package.provided", "dev-util/diffball-1.0") self.assertEqual( self.klass(pjoin(self.dir, self.profile)).pkg_provided, ((), (CPV.versioned("dev-util/diffball-1.0"),)) )
def test_norev(self): astr = "app-arch/tarsync" a = self.kls(f"~{astr}-1") self.assertMatch(a, CPV.versioned(f"{astr}-1")) self.assertMatch(a, CPV.versioned(f"{astr}-1-r1")) self.assertMatch(a, CPV.versioned(f"{astr}-1-r0")) self.assertNotMatch(a, CPV.versioned(f"{astr}-2")) self.assertRaises(errors.MalformedAtom, self.kls, "~{astr}-r1") self.assertRaises(errors.MalformedAtom, self.kls, "~{astr}-r2") # special case- yes -r0 effectively is None, but -r shouldn't be used # with ~ self.assertRaises(errors.MalformedAtom, self.kls, "~{astr}-r0")
def test_norev(self): astr = "app-arch/tarsync" a = self.kls("~%s-1" % astr) self.assertMatch(a, CPV.versioned("%s-1" % astr)) self.assertMatch(a, CPV.versioned("%s-1-r1" % astr)) self.assertMatch(a, CPV.versioned("%s-1-r0" % astr)) self.assertNotMatch(a, CPV.versioned("%s-2" % astr)) self.assertRaises(errors.MalformedAtom, self.kls, "~%s-r1" % astr) self.assertRaises(errors.MalformedAtom, self.kls, "~%s-r2" % astr) # special case- yes -r0 effectively is None, but -r shouldn't be used # with ~ self.assertRaises(errors.MalformedAtom, self.kls, "~%s-r0" % astr)
def test_norev(self): astr = "app-arch/tarsync" a = self.kls("~%s-1" % astr) self.assertTrue(a.match(CPV.versioned("%s-1" % astr))) self.assertTrue(a.match(CPV.versioned("%s-1-r1" % astr))) self.assertTrue(a.match(CPV.versioned("%s-1-r0" % astr))) self.assertFalse(a.match(CPV.versioned("%s-2" % astr))) self.assertRaises(errors.MalformedAtom, self.kls, "~%s-r1" % astr) self.assertRaises(errors.MalformedAtom, self.kls, "~%s-r2" % astr) # special case- yes -r0 effectively is None, but -r shouldn't be used # with ~ self.assertRaises(errors.MalformedAtom, self.kls, "~%s-r0" % astr)
def update_pkg_desc_index(repo, observer): """Update a repo's package description cache (metadata/pkg_desc_index)""" ret = 0 pkg_desc_index = pjoin(repo.location, "metadata", "pkg_desc_index") f = None try: f = AtomicWriteFile(pkg_desc_index) for cat, pkgs in sorted(repo.packages.items()): for pkg in sorted(pkgs): cpvs = sorted(CPV(cat, pkg, v) for v in repo.versions[(cat, pkg)]) # get the most recent pkg description, skipping bad pkgs for cpv in reversed(cpvs): try: desc = repo[(cat, pkg, cpv.fullver)].description versions = ' '.join(x.fullver for x in cpvs) f.write(f"{cat}/{pkg} {versions}: {desc}\n") break except MetadataException as e: # should be caught and outputted already by cache regen ret = 1 f.close() except IOError as e: observer.error( f"Unable to update pkg_desc_index file {pkg_desc_index!r}: {e.strerror}") ret = os.EX_IOERR finally: if f is not None: f.discard() return ret
def __init__(self, cpvstr, data=None, shared=None, repo=None): if data is None: data = {} for x in ("DEPEND", "RDEPEND", "PDEPEND", "IUSE", "LICENSE"): data.setdefault(x, "") data.setdefault("KEYWORDS", ' '.join(default_arches)) cpv = CPV(cpvstr, versioned=True) super().__init__(shared, repo, cpv.category, cpv.package, cpv.fullver) object.__setattr__(self, "data", data)
def __init__(self, parent_repository, pkg, data, cpvstr): """ :param cpvstr: cpv for the new pkg :param parent_repository: actual repository that this pkg should claim it belongs to :param pkg: parent pkg that is generating this pkg :param data: mapping of data to push to use in __getattr__ access """ c = CPV.unversioned(cpvstr) if c.fullver is None: cpvstr = cpvstr + "-" + pkg.fullver metadata.package.__init__(self, parent_repository, cpvstr) sfunc = object.__setattr__ sfunc(self, "data", IndeterminantDict(lambda *a: str(), data)) sfunc(self, "_orig_data", data) sfunc(self, "provider", pkg.versioned_atom)
def __init__(self, parent_repository, pkg, data, cpvstr): """ :param cpvstr: cpv for the new pkg :param parent_repository: actual repository that this pkg should claim it belongs to :param pkg: parent pkg that is generating this pkg :param data: mapping of data to push to use in __getattr__ access """ c = CPV.unversioned(cpvstr) if c.fullver is None: cpvstr = cpvstr + "-" + pkg.fullver metadata.package.__init__(self, parent_repository, cpvstr) sfunc = object.__setattr__ sfunc(self, "data", IndeterminantDict(lambda *a: str(), data)) sfunc(self, "_orig_data", data) sfunc(self, "provider", pkg.versioned_atom) sfunc(self, "eapi_obj", get_eapi("0"))
def test_nonversioned(self): a = self.kls("kde-base/kde") self.assertMatch(a, CPV.unversioned("kde-base/kde")) self.assertNotMatch(a, CPV.unversioned("kde-base/kde2")) self.assertMatch(a, CPV.versioned("kde-base/kde-3"))
def __init__(self, repo, *a, **kw): CPV.__init__(self, *a, **kw) object.__setattr__(self, 'repo', repo)
def test_nonversioned(self): a = self.kls("kde-base/kde") self.assertTrue(a.match(CPV.unversioned("kde-base/kde"))) self.assertFalse(a.match(CPV.unversioned("kde-base/kde2"))) self.assertTrue(a.match(CPV.versioned("kde-base/kde-3")))