Example #1
0
 def mk_tree(self, path, *args, **kwds):
     eclasses = kwds.pop('eclass_cache', None)
     if eclasses is None:
         epath = pjoin(path, 'eclass')
         ensure_dirs(epath)
         eclasses = eclass_cache.cache(epath)
     return repository._UnconfiguredTree(path, eclasses, *args, **kwds)
Example #2
0
    def mk_tree(self, path, *args, **kwds):
        if path != self.dir:
            self.dir_slave = path
            self.dir_master = pjoin(os.path.dirname(path),
                                    os.path.basename(path) + 'master')
            ensure_dirs(self.dir_slave)
            ensure_dirs(self.dir_master)
            ensure_dirs(pjoin(self.dir_slave, 'profiles'))
            ensure_dirs(pjoin(self.dir_master, 'profiles'))

        eclasses = kwds.pop('eclass_cache', None)
        if eclasses is None:
            epath = pjoin(self.dir_master, 'eclass')
            ensure_dirs(epath)
            eclasses = eclass_cache.cache(epath)

        self.master_repo = repository.UnconfiguredTree(self.dir_master,
                                                       eclass_cache=eclasses,
                                                       *args,
                                                       **kwds)
        masters = (self.master_repo, )
        return repository.UnconfiguredTree(self.dir_slave,
                                           eclass_cache=eclasses,
                                           masters=masters,
                                           *args,
                                           **kwds)
Example #3
0
def _sort_eclasses(config, repo_config, eclasses):
    if eclasses:
        return eclasses

    repo_path = repo_config.location
    masters = repo_config.masters
    eclasses = []
    default = config.get_default('repo_config')
    if default is None:
        location = repo_path
    else:
        location = default.location

    if not masters:
        if masters is None:
            # if it's None, that means it's not a standalone, and is PMS, or misconfigured.
            # empty tuple means it's a standalone repository
            if default is None:
                raise Exception(
                    "repository %r named %r wants the default repository "
                    "(gentoo for example), but no repository is marked as the default. "
                    "Fix your configuration." %
                    (repo_path, repo_config.repo_id))
            eclasses = [location]
    else:
        repo_map = {
            r.repo_id: r.location
            for r in config.objects['repo_config'].itervalues()
        }

        missing = set(repo_config.masters).difference(repo_map)
        if missing:
            missing = ', '.join(sorted(missing))
            raise Exception(
                "repo %r at path %r has masters %s; we cannot find "
                "the following repos: %s" %
                (repo_config.repo_id, repo_path, ', '.join(map(
                    repr, masters)), missing))
        eclasses = [repo_map[x] for x in masters]

    # add the repo's eclass directories if it's not specified.
    # do it in this fashion so that the repo's masters can actually interpose
    # this repo's eclasses in between others.
    # admittedly an odd thing to do, but it has some benefits
    if repo_path not in eclasses:
        eclasses.append(repo_path)

    eclasses = [
        eclass_cache_module.cache(pjoin(x, 'eclass'), location=location)
        for x in eclasses
    ]

    if len(eclasses) == 1:
        eclasses = eclasses[0]
    else:
        eclasses = list(reversed(eclasses))
        eclasses = eclass_cache_module.StackedCaches(eclasses,
                                                     location=location,
                                                     eclassdir=location)
    return eclasses
Example #4
0
    def setUp(self):
        TempDirMixin.setUp(self)
        self.loc1 = pjoin(self.dir, "stack1")
        self.loc2 = pjoin(self.dir, "stack2")

        os.mkdir(self.loc1)
        open(pjoin(self.loc1, 'eclass1.eclass'), 'w').close()
        os.utime(pjoin(self.loc1, 'eclass1.eclass'), (100, 100))
        self.ec1 = eclass_cache.cache(self.loc1)

        os.mkdir(self.loc2)
        open(pjoin(self.loc2, 'eclass2.eclass'), 'w').close()
        os.utime(pjoin(self.loc2, 'eclass2.eclass'), (100, 100))
        self.ec2 = eclass_cache.cache(self.loc2)
        self.ec = eclass_cache.StackedCaches([self.ec1, self.ec2])
        self.ec_locs = {"eclass1": self.loc1, "eclass2": self.loc2}
        # make a shadowed file to verify it's not seen
        open(pjoin(self.loc2, 'eclass1.eclass'), 'w').close()
Example #5
0
 def setUp(self):
     TempDirMixin.setUp(self)
     for x, mtime in (("eclass1", 100), ("eclass2", 200)):
         open(pjoin(self.dir, "%s.eclass" % x), "w").close()
         os.utime(pjoin(self.dir, "%s.eclass" % x), (mtime, mtime))
     # insert a crap file to ensure it doesn't grab it.
     open(pjoin(self.dir, 'foon-eclass'), 'w').close()
     self.ec = eclass_cache.cache(self.dir)
     self.ec_locs = {x: self.dir for x in ("eclass1", "eclass2")}
Example #6
0
    def __init__(self, location, *args, **config):
        self.ec = config.pop("eclasses", None)
        if self.ec is None:
            self.ec = eclass_cache.cache(pjoin(location, "eclass"), location)

        config.pop('label', None)
        self.mtime_in_entry = config.pop('mtime_in_entry', True)
        location = pjoin(location, 'metadata', 'cache')
        super().__init__(location, *args, **config)
        self.hardcoded_auxdbkeys_order = tuple(
            (idx, key) for idx, key in enumerate(self.auxdbkeys_order)
            if key in self._known_keys)
        self.hardcoded_auxdbkeys_processing = tuple(
            (key in self._known_keys and key or None)
            for key in self.auxdbkeys_order)
Example #7
0
def _sort_eclasses(config, repo_config):
    repo_path = repo_config.location
    repo_id = repo_config.repo_id
    masters = repo_config.masters
    eclasses = []

    default = config.get_default('repo_config')
    if repo_config._missing_masters and default is not None:
        # use default repo's eclasses for overlays with missing masters
        location = default.location
    else:
        location = repo_path

    if not masters:
        eclasses = [location]
    else:
        repo_map = {
            r.repo_id: r.location
            for r in config.objects['repo_config'].values()
        }
        eclasses = [repo_map[x] for x in masters]

    # add the repo's eclass directories if it's not specified.
    # do it in this fashion so that the repo's masters can actually interpose
    # this repo's eclasses in between others.
    # admittedly an odd thing to do, but it has some benefits
    if repo_path not in eclasses:
        eclasses.append(repo_path)

    eclasses = [
        eclass_cache_mod.cache(pjoin(x, 'eclass'), location=location)
        for x in eclasses
    ]

    if len(eclasses) == 1:
        eclasses = eclasses[0]
    else:
        eclasses = list(reversed(eclasses))
        eclasses = eclass_cache_mod.StackedCaches(eclasses,
                                                  location=location,
                                                  eclassdir=location)
    return eclasses
Example #8
0
    def __init__(self,
                 location,
                 eclass_cache=None,
                 masters=(),
                 cache=(),
                 default_mirrors=None,
                 allow_missing_manifests=False,
                 repo_config=None):
        """
        :param location: on disk location of the tree
        :param cache: sequence of :obj:`pkgcore.cache.template.database` instances
            to use for storing metadata
        :param masters: repo masters this repo inherits from
        :param eclass_cache: If not None, :obj:`pkgcore.ebuild.eclass_cache`
            instance representing the eclasses available,
            if None, generates the eclass_cache itself
        :param default_mirrors: Either None, or sequence of mirrors to try
            fetching from first, then falling back to other uri
        """
        super().__init__()
        self.base = self.location = location
        try:
            if not stat.S_ISDIR(os.stat(self.base).st_mode):
                raise errors.InitializationError(
                    f"base not a dir: {self.base}")
        except OSError as e:
            raise errors.InitializationError(
                f"lstat failed: {self.base}") from e

        if repo_config is None:
            repo_config = repo_objs.RepoConfig(location)
        self.config = repo_config

        # profiles dir is required by PMS
        if not os.path.isdir(self.config.profiles_base):
            raise errors.InvalidRepo(
                f'missing required profiles dir: {self.location!r}')

        # verify we support the repo's EAPI
        if not self.is_supported:
            raise errors.UnsupportedRepo(self)

        if eclass_cache is None:
            eclass_cache = eclass_cache_mod.cache(pjoin(
                self.location, 'eclass'),
                                                  location=self.location)
        self.eclass_cache = eclass_cache

        self.masters = masters
        self.trees = tuple(masters) + (self, )
        self.licenses = repo_objs.Licenses(self.location)
        if masters:
            self.licenses = repo_objs.OverlayedLicenses(*self.trees)

        mirrors = {}
        fp = pjoin(self.location, 'profiles', "thirdpartymirrors")
        try:
            for k, v in read_dict(fp, splitter=None).items():
                v = v.split()
                shuffle(v)
                mirrors[k] = v
        except FileNotFoundError:
            pass

        # use mirrors from masters if not defined in the repo
        for master in masters:
            for k, v in master.mirrors.items():
                if k not in mirrors:
                    mirrors[k] = v

        if isinstance(cache, (tuple, list)):
            cache = tuple(cache)
        else:
            cache = (cache, )

        self.mirrors = mirrors
        self.default_mirrors = default_mirrors
        self.cache = cache
        self._allow_missing_chksums = allow_missing_manifests
        self.package_class = self.package_factory(self, cache,
                                                  self.eclass_cache,
                                                  self.mirrors,
                                                  self.default_mirrors)
        self._shared_pkg_cache = WeakValCache()
        self._masked = RestrictionRepo(repo_id='masked')
Example #9
0
    def __init__(self,
                 location,
                 eclass_cache=None,
                 masters=(),
                 cache=(),
                 default_mirrors=None,
                 ignore_paludis_versioning=False,
                 allow_missing_manifests=False,
                 repo_config=None):
        """
        :param location: on disk location of the tree
        :param cache: sequence of :obj:`pkgcore.cache.template.database` instances
            to use for storing metadata
        :param masters: repo masters this repo inherits from
        :param eclass_cache: If not None, :obj:`pkgcore.ebuild.eclass_cache`
            instance representing the eclasses available,
            if None, generates the eclass_cache itself
        :param default_mirrors: Either None, or sequence of mirrors to try
            fetching from first, then falling back to other uri
        :param ignore_paludis_versioning: If False, fail when -scm is encountered.  if True,
            silently ignore -scm ebuilds.
        """

        prototype.tree.__init__(self)
        self.base = self.location = location
        try:
            if not stat.S_ISDIR(os.stat(self.base).st_mode):
                raise errors.InitializationError("base not a dir: %s" %
                                                 self.base)
        except OSError:
            raise_from(
                errors.InitializationError("lstat failed on base %s" %
                                           (self.base, )))
        if repo_config is None:
            repo_config = repo_objs.RepoConfig(location)
        self.config = repo_config
        if eclass_cache is None:
            eclass_cache = eclass_cache_module.cache(
                pjoin(self.location, 'eclass'))
        self.eclass_cache = eclass_cache

        self.masters = masters
        self.trees = tuple(masters) + (self, )
        self.licenses = repo_objs.Licenses(self.location)
        if masters:
            self.licenses = repo_objs.OverlayedLicenses(*self.trees)

        mirrors = {}
        fp = pjoin(self.location, metadata_offset, "thirdpartymirrors")
        try:
            for k, v in read_dict(fp, splitter=None).iteritems():
                v = v.split()
                shuffle(v)
                mirrors[k] = v
        except EnvironmentError as ee:
            if ee.errno != errno.ENOENT:
                raise

        # use mirrors from masters if not defined in the repo
        for master in masters:
            for k, v in master.mirrors.iteritems():
                if k not in mirrors:
                    mirrors[k] = v

        if isinstance(cache, (tuple, list)):
            cache = tuple(cache)
        else:
            cache = (cache, )

        self.mirrors = mirrors
        self.default_mirrors = default_mirrors
        self.cache = cache
        self.ignore_paludis_versioning = ignore_paludis_versioning
        self._allow_missing_chksums = allow_missing_manifests
        self.package_class = self.package_factory(self, cache,
                                                  self.eclass_cache,
                                                  self.mirrors,
                                                  self.default_mirrors)
        self._shared_pkg_cache = WeakValCache()