Ejemplo n.º 1
0
class base(object):
    """
    Maintains the cache information about eclasses available to an ebuild.
    """

    def __init__(self, portdir=None, eclassdir=None):
        self._eclass_data_inst_cache = WeakValCache()
        # generate this.
        # self.eclasses = {} # {"Name": ("location", "_mtime_")}
        self.portdir = portdir
        self.eclassdir = eclassdir

    def get_eclass_data(self, inherits):
        """Return the cachable entries from a list of inherited eclasses.

        Only make get_eclass_data calls for data you know came from
        this eclass_cache, otherwise be ready to catch a KeyError
        exception for any eclass that was requested, but not known to
        this cache.
        """

        keys = tuple(sorted(inherits))
        o = self._eclass_data_inst_cache.get(keys)
        if o is None:
            o = ImmutableDict((k, self.eclasses[k]) for k in keys)
            self._eclass_data_inst_cache[keys] = o
        return o

    def get_eclass(self, eclass):
        o = self.eclasses.get(eclass)
        if o is None:
            return None
        return local_source(o.path)

    eclasses = jit_attr_ext_method("_load_eclasses", "_eclasses")

    def rebuild_cache_entry(self, entry_eclasses):
        """Check if eclass data is still valid.

        Given a dict as returned by get_eclass_data, walk it comparing
        it to internal eclass view.

        :return: a boolean representing whether that eclass data is still
            up to date, or not
        """
        ec = self.eclasses
        d = {}

        for eclass, chksums in entry_eclasses:
            data = ec.get(eclass)
            if any(val != getattr(data, chf, None) for chf, val in chksums):
                return None
            d[eclass] = data

        return d
Ejemplo n.º 2
0
class Values(optparse.Values, object):

    """Values with an autoloaded config property.

    If you do not want the config autoloaded you can set the _config
    attribute like this:

     >>> parser = OptionParser()
     >>> vals = parser.get_default_values()
     >>> vals._config = my_custom_central
     >>> parser.parse_args(args, vals)
    """

    def __init__(self, defaults=None):
        optparse.Values.__init__(self, defaults)
        self.new_config = {}
        self.add_config = {}

    def load_config(self):
        """Override this if you need a different way of loading config."""
        # This makes mixing --new-config and --add-config sort of
        # work. Not sure if that is a good thing, but detecting and
        # erroring is about as much work as making it mostly work :)
        new_config = {
            name: basics.ConfigSectionFromStringDict(val)
            for name, val in self.new_config.iteritems()}
        add_config = {}
        for name, config in self.add_config.iteritems():
            config.setdefault('inherit', name)
            add_config[name] = basics.ConfigSectionFromStringDict(config)
        # Triggers failures if these get mucked with after this point
        # (instead of silently ignoring).
        self.add_config = self.new_config = None
        return load_config(
            debug=self.debug, append_sources=(new_config, add_config),
            skip_config_files=self.empty_config)

    def load_domain(self):
        """Override this if you need to change the default domain logic."""
        domain = self.config.get_default('domain')
        if domain is None:
            self._raise_error(
                'No default domain found, fix your configuration '
                'or pass --domain (valid domains: %s)' % (
                ', '.join(self.config.domain),))
        return domain

    config = klass.jit_attr_ext_method("load_config", "_config",
        uncached_val=None)
    domain = klass.jit_attr_ext_method("load_domain", "_domain",
        uncached_val=None)

    def get_pkgset(self, err, setname, config=None):
        if config is None:
            config = self.config
        try:
            return config.pkgset[setname]
        except KeyError:
            if err:
                err.write('No set called %r!\nknown sets: %r' %
                         (setname, sorted(config.pkgset.keys())))
            return None