Пример #1
0
    def _get_packages(self, category):
        cpath = pjoin(self.location, category.lstrip(os.path.sep))
        l = set()
        d = {}
        bad = False
        try:
            for x in listdir_dirs(cpath):
                if x.startswith(".tmp.") or x.endswith(".lockfile") \
                        or x.startswith("-MERGING-"):
                    continue
                try:
                    pkg = versioned_CPV(category + "/" + x)
                except InvalidCPV:
                    bad = True
                if bad or not pkg.fullver:
                    if '-scm' in x:
                        bad = 'scm'
                    elif '-try' in x:
                        bad = 'try'
                    else:
                        raise InvalidCPV("%s/%s: no version component" %
                                         (category, x))
                    logger.error(
                        "merged -%s pkg detected: %s/%s. "
                        "throwing exception due to -%s not being a valid"
                        " version component.  Silently ignoring that "
                        "specific version is not viable either since it "
                        "would result in pkgcore stomping whatever it was "
                        "that -%s version merged.  "
                        "This is why embrace and extend is bad, mm'kay.  "
                        "Use the offending pkg manager that merged it to "
                        "unmerge it.", bad, category, x, bad, bad)
                    raise InvalidCPV("%s/%s: -%s version component is "
                                     "not standard." % (category, x, bad))
                l.add(pkg.package)
                d.setdefault((category, pkg.package), []).append(pkg.fullver)
        except EnvironmentError as e:
            compatibility.raise_from(
                KeyError(
                    "failed fetching packages for category %s: %s" % (pjoin(
                        self.location, category.lstrip(os.path.sep)), str(e))))

        self._versions_tmp_cache.update(d)
        return tuple(l)
Пример #2
0
    def _get_packages(self, category):
        cpath = pjoin(self.location, category.lstrip(os.path.sep))
        l = set()
        d = {}
        bad = False
        try:
            for x in listdir_dirs(cpath):
                if x.startswith(".tmp.") or x.endswith(".lockfile") \
                        or x.startswith("-MERGING-"):
                    continue
                try:
                    pkg = versioned_CPV(f'{category}/{x}')
                except InvalidCPV:
                    bad = True
                if bad or not pkg.fullver:
                    if '-scm' in x:
                        bad = 'scm'
                    elif '-try' in x:
                        bad = 'try'
                    else:
                        raise InvalidCPV(
                            f"{category}/{x}: no version component")
                    logger.error(
                        f'merged -{bad} pkg detected: {category}/{x}. '
                        f'throwing exception due to -{bad} not being a valid'
                        ' version component.  Silently ignoring that '
                        'specific version is not viable either since it '
                        'would result in pkgcore stomping whatever it was '
                        f'that -{bad} version merged.  '
                        'Use the offending pkg manager that merged it to '
                        'unmerge it.')
                    raise InvalidCPV(
                        f"{category}/{x}: -{bad} version component is not standard."
                    )
                l.add(pkg.package)
                d.setdefault((category, pkg.package), []).append(pkg.fullver)
        except EnvironmentError as e:
            category = pjoin(self.location, category.lstrip(os.path.sep))
            raise KeyError(
                f'failed fetching packages for category {category}: {e}'
            ) from e

        self._versions_tmp_cache.update(d)
        return tuple(l)
Пример #3
0
    def _get_packages(self, category):
        cpath = pjoin(self.base, category.lstrip(os.path.sep))
        l = set()
        d = {}
        lext = len(self.extension)
        bad = False
        try:
            for x in listdir_files(cpath):
                # don't use lstat; symlinks may exist
                if (x.endswith(".lockfile") or
                        not x[-lext:].lower() == self.extension or
                        x.startswith(".tmp.")):
                    continue
                pv = x[:-lext]
                try:
                    pkg = versioned_CPV(category+"/"+pv)
                except InvalidCPV:
                    bad = True
                if bad or not pkg.fullver:
                    if '-scm' in pv:
                        bad = 'scm'
                    elif '-try' in pv:
                        bad = 'try'
                    else:
                        raise InvalidCPV(
                            "%s/%s: no version component" %
                            (category, pv))
                    if self.ignore_paludis_versioning:
                        bad = False
                        continue
                    raise InvalidCPV(
                        "%s/%s: -%s version component is "
                        "not standard." % (category, pv, bad))
                l.add(pkg.package)
                d.setdefault((category, pkg.package), []).append(pkg.fullver)
        except EnvironmentError as e:
            raise_from(KeyError(
                "failed fetching packages for category %s: %s" %
                (pjoin(self.base, category.lstrip(os.path.sep)), str(e))))

        self._versions_tmp_cache.update(d)
        return tuple(l)
Пример #4
0
Файл: cpv.py Проект: ulm/pkgcore
    def __init__(self, *a, **kwds):
        """
        Can be called with one string or with three string args.

        If called with one arg that is the cpv string. (See :obj:`parser`
        for allowed syntax).

        If called with three args they are the category, package and
        version components of the cpv string respectively.
        """
        versioned = True
        had_versioned = 'versioned' in kwds
        if had_versioned:
            versioned = kwds.pop("versioned")
        if kwds:
            raise TypeError(f"versioned is the only allowed kwds: {kwds!r}")
        l = len(a)
        if l == 1:
            cpvstr = a[0]
            if not had_versioned:
                raise TypeError(
                    f"single argument invocation requires versioned kwd; {cpvstr!r}"
                )
        elif l == 3:
            for x in a:
                if not isinstance(x, str):
                    raise TypeError(f"all args must be strings, got {a!r}")
            cpvstr = f"{a[0]}/{a[1]}-{a[2]}"
            versioned = True
        else:
            raise TypeError(
                f"CPV takes 1 arg (cpvstr), or 3 (cat, pkg, ver): got {a!r}")
        if not isinstance(cpvstr, str):
            raise TypeError(self.cpvstr)

        try:
            category, pkgver = cpvstr.rsplit("/", 1)
        except ValueError:
            # occurs if the rsplit yields only one item
            raise InvalidCPV(f'{cpvstr}: no package or version components')
        if not isvalid_cat_re.match(category):
            raise InvalidCPV(f'{cpvstr}: invalid category name')
        sf = object.__setattr__
        sf(self, 'category', category)
        sf(self, 'cpvstr', cpvstr)
        pkg_chunks = pkgver.split("-")
        lpkg_chunks = len(pkg_chunks)
        if versioned:
            if lpkg_chunks == 1:
                raise InvalidCPV(f'{cpvstr}: missing package version')
            if isvalid_rev(pkg_chunks[-1]):
                if lpkg_chunks < 3:
                    # needs at least ('pkg', 'ver', 'rev')
                    raise InvalidCPV(
                        f'{cpvstr}: missing package name, version, and/or revision'
                    )
                rev = int(pkg_chunks.pop(-1)[1:])
                if rev == 0:
                    # reset the stored cpvstr to drop -r0+
                    sf(self, 'cpvstr', f"{category}/{'-'.join(pkg_chunks)}")
                sf(self, 'revision', rev)
            else:
                sf(self, 'revision', None)

            if not isvalid_version_re.match(pkg_chunks[-1]):
                raise InvalidCPV(
                    f"{cpvstr}: invalid version '{pkg_chunks[-1]}'")
            sf(self, 'version', pkg_chunks.pop(-1))
            if self.revision:
                sf(self, 'fullver', f"{self.version}-r{self.revision}")
            else:
                sf(self, 'fullver', self.version)

            if not isvalid_pkg_name(pkg_chunks):
                raise InvalidCPV(f'{cpvstr}: invalid package name')
            sf(self, 'package', '-'.join(pkg_chunks))
            sf(self, 'key', f"{category}/{self.package}")
        else:
            if not isvalid_pkg_name(pkg_chunks):
                raise InvalidCPV(f'{cpvstr}: invalid package name')
            sf(self, 'revision', None)
            sf(self, 'fullver', None)
            sf(self, 'version', None)
            sf(self, 'key', cpvstr)
            sf(self, 'package', '-'.join(pkg_chunks))
Пример #5
0
    def __init__(self, *a, **kwds):
        """
        Can be called with one string or with three string args.

        If called with one arg that is the cpv string. (See :obj:`parser`
        for allowed syntax).

        If called with three args they are the category, package and
        version components of the cpv string respectively.
        """
        versioned = True
        had_versioned = 'versioned' in kwds
        if had_versioned:
            versioned = kwds.pop("versioned")
        if kwds:
            raise TypeError("versioned is the only allowed kwds: %r" %
                            (kwds, ))
        l = len(a)
        if l == 1:
            cpvstr = a[0]
            if not had_versioned:
                raise TypeError(
                    "single arguement invocation requires versioned kwd; %r" %
                    (cpvstr, ))
        elif l == 3:
            for x in a:
                if not isinstance(x, basestring):
                    raise TypeError("all args must be strings, got %r" % (a, ))
            cpvstr = "%s/%s-%s" % a
            versioned = True
        else:
            raise TypeError("CPV takes 1 arg (cpvstr), or 3 (cat, pkg, ver):"
                            " got %r" % (a, ))
        if not isinstance(cpvstr, basestring):
            raise TypeError(self.cpvstr)

        try:
            categories, pkgver = cpvstr.rsplit("/", 1)
        except ValueError:
            # occurs if the rsplit yields only one item
            raise InvalidCPV(cpvstr)
        if not isvalid_cat_re.match(categories):
            raise InvalidCPV(cpvstr)
        sf = object.__setattr__
        sf(self, 'category', categories)
        sf(self, 'cpvstr', cpvstr)
        pkg_chunks = pkgver.split("-")
        lpkg_chunks = len(pkg_chunks)
        if versioned:
            if lpkg_chunks == 1:
                raise InvalidCPV(cpvstr)
            if isvalid_rev(pkg_chunks[-1]):
                if lpkg_chunks < 3:
                    # needs at least ('pkg', 'ver', 'rev')
                    raise InvalidCPV(cpvstr)
                rev = int(pkg_chunks.pop(-1)[1:])
                if not rev:
                    rev = None
                    # reset the stored cpvstr to drop -r0+
                    sf(self, 'cpvstr',
                       "%s/%s" % (categories, '-'.join(pkg_chunks)))
                sf(self, 'revision', rev)
            else:
                sf(self, 'revision', None)

            if not isvalid_version_re.match(pkg_chunks[-1]):
                raise InvalidCPV(cpvstr)
            sf(self, 'version', pkg_chunks.pop(-1))
            if self.revision:
                sf(self, 'fullver', "%s-r%s" % (self.version, self.revision))
            else:
                sf(self, 'fullver', self.version)

            if not isvalid_pkg_name(pkg_chunks):
                raise InvalidCPV(cpvstr)
            sf(self, 'package', '-'.join(pkg_chunks))
            sf(self, 'key', "%s/%s" % (categories, self.package))
        else:
            if not isvalid_pkg_name(pkg_chunks):
                raise InvalidCPV(cpvstr)
            sf(self, 'revision', None)
            sf(self, 'fullver', None)
            sf(self, 'version', None)
            sf(self, 'key', cpvstr)
            sf(self, 'package', '-'.join(pkg_chunks))
Пример #6
0
    def __init__(self, *args, versioned=None):
        """
        Can be called with one string or with three string args.

        If called with one arg that is the cpv string. (See :obj:`parser`
        for allowed syntax).

        If called with three args they are the category, package and
        version components of the cpv string respectively.
        """
        for x in args:
            if not isinstance(x, str):
                raise TypeError(f"all args must be strings, got {args!r}")

        l = len(args)
        if l == 1:
            cpvstr = args[0]
            if versioned is None:
                raise TypeError(
                    f"single argument invocation requires versioned kwarg; {cpvstr!r}"
                )
        elif l == 2:
            cpvstr = f"{args[0]}/{args[1]}"
            versioned = False
        elif l == 3:
            cpvstr = f"{args[0]}/{args[1]}-{args[2]}"
            versioned = True
        else:
            raise TypeError(
                f"CPV takes 1 arg (cpvstr), 2 (cat, pkg), or 3 (cat, pkg, ver): got {args!r}"
            )

        try:
            category, pkgver = cpvstr.rsplit("/", 1)
        except ValueError:
            # occurs if the rsplit yields only one item
            raise InvalidCPV(cpvstr, 'no package or version components')
        if not isvalid_cat_re.match(category):
            raise InvalidCPV(cpvstr, 'invalid category name')
        sf = object.__setattr__
        sf(self, 'category', category)
        sf(self, 'cpvstr', cpvstr)
        pkg_chunks = pkgver.split("-")
        lpkg_chunks = len(pkg_chunks)
        if versioned:
            if lpkg_chunks == 1:
                raise InvalidCPV(cpvstr, 'missing package version')
            if isvalid_rev(pkg_chunks[-1]):
                if lpkg_chunks < 3:
                    # needs at least ('pkg', 'ver', 'rev')
                    raise InvalidCPV(
                        cpvstr,
                        'missing package name, version, and/or revision')
                rev = _Revision(pkg_chunks.pop(-1)[1:])
                if rev == 0:
                    # reset stored cpvstr to drop -r0+
                    sf(self, 'cpvstr', f"{category}/{'-'.join(pkg_chunks)}")
                elif rev[0] == '0':
                    # reset stored cpvstr to drop leading zeroes from revision
                    sf(self, 'cpvstr',
                       f"{category}/{'-'.join(pkg_chunks)}-r{int(rev)}")
                sf(self, 'revision', rev)
            else:
                sf(self, 'revision', _Revision(''))

            if not isvalid_version_re.match(pkg_chunks[-1]):
                raise InvalidCPV(cpvstr, f"invalid version '{pkg_chunks[-1]}'")
            sf(self, 'version', pkg_chunks.pop(-1))
            if self.revision:
                sf(self, 'fullver', f"{self.version}-r{self.revision}")
            else:
                sf(self, 'fullver', self.version)

            if not isvalid_pkg_name(pkg_chunks):
                raise InvalidCPV(cpvstr, 'invalid package name')
            sf(self, 'package', '-'.join(pkg_chunks))
            sf(self, 'key', f"{category}/{self.package}")
        else:
            if not isvalid_pkg_name(pkg_chunks):
                raise InvalidCPV(cpvstr, 'invalid package name')
            sf(self, 'revision', None)
            sf(self, 'fullver', None)
            sf(self, 'version', None)
            sf(self, 'key', cpvstr)
            sf(self, 'package', '-'.join(pkg_chunks))