コード例 #1
0
ファイル: engine.py プロジェクト: shen390s/pkgcore
    def regenerate_csets(self):
        """Internal function, reset non preserverd csets.

        Used in transitioning between hook points
        """
        self.csets = StackedDict(self.preserved_csets,
            LazyValDict(self.cset_sources, self._get_cset_source))
コード例 #2
0
    def __init__(self,
                 mode,
                 tempdir,
                 hooks,
                 csets,
                 preserves,
                 observer,
                 offset=None,
                 disable_plugins=False,
                 parallelism=None):
        if observer is None:
            observer = observer_mod.repo_observer(observer_mod.null_output)
        self.observer = observer
        self.mode = mode
        if tempdir is not None:
            tempdir = normpath(tempdir) + '/'
        self.tempdir = tempdir

        self.parallelism = parallelism if parallelism is not None else cpu_count(
        )
        self.hooks = ImmutableDict((x, []) for x in hooks)

        self.preserve_csets = []
        self.cset_sources = {}
        # instantiate these separately so their values are preserved
        self.preserved_csets = LazyValDict(self.preserve_csets,
                                           self._get_cset_source)
        for k, v in csets.items():
            if isinstance(v, str):
                v = getattr(self, v, v)
            if not callable(v):
                raise TypeError(
                    "cset values must be either the string name of "
                    f"existing methods, or callables (got {v})")

            if k in preserves:
                self.add_preserved_cset(k, v)
            else:
                self.add_cset(k, v)

        if offset is None:
            offset = "/"
        self.offset = offset

        if not disable_plugins:
            # merge in default triggers first.
            for trigger in get_plugins('triggers'):
                t = trigger()
                t.register(self)

        # merge in overrides
        for hook, triggers in hooks.items():
            for trigger in triggers:
                self.add_trigger(hook, trigger)

        self.regenerate_csets()
        for x in hooks:
            setattr(self, x, partial(self.execute_hook, x))
コード例 #3
0
from pkgcore.fetch import base, fetchable, errors
from pkgcore.test import TestCase

repeating_str = 'asdf'
data = repeating_str * 4000
handlers = get_handlers()

from snakeoil.mappings import LazyValDict


def _callback(chf):
    return handlers[chf](data_source.data_source(data))


chksums = LazyValDict(frozenset(handlers.iterkeys()), _callback)

# get a non size based chksum
known_chksum = [x for x in handlers.iterkeys() if x != "size"][0]


class TestFetcher(TempDirMixin, TestCase):
    def setUp(self):
        TempDirMixin.setUp(self)
        self.fp = os.path.join(self.dir, "test")
        self.obj = fetchable(self.fp, chksums=chksums)
        self.fetcher = base.fetcher()

    def write_data(self, data=data):
        with open(self.fp, "w") as f:
            f.write(data)
コード例 #4
0
ファイル: livefs.py プロジェクト: shen390s/pkgcore
def gen_chksums(handlers, location):
    def f(key):
        return handlers[key](location)

    return LazyValDict(handlers, f)