Пример #1
0
class Chanko(object):
    """Top-level object of the chanko"""

    def __init__(self):
        self.base = os.getcwd()
        self.config = os.path.join(self.base, 'config')
        self.architecture = getoutput("dpkg --print-architecture")

        self.trustedkeys = os.path.join(self.config, 'trustedkeys.gpg')
        self.sources_list = os.path.join(self.config, 'sources.list')
        for f in (self.sources_list, self.trustedkeys):
            if not os.path.exists(f):
                raise Error("required file not found: " + f)

        conf = ChankoConfig(os.path.join(self.config, 'chanko.conf'))
        os.environ['CCURL_CACHE'] = conf.ccurl_cache

        self.archives = os.path.join(self.base, 'archives')
        makedirs(os.path.join(self.archives, 'partial'))

        plan_path = os.path.join(self.base, 'plan')
        plan_cpp = conf.plan_cpp.replace("-", " -").strip()
        plan_cpp = plan_cpp.split(" ") if plan_cpp else []
        self.plan = Plan(plan_path, self.architecture, plan_cpp)

        self.local_cache = LocalCache(self)
        self.remote_cache = RemoteCache(self)

    def get_package_candidates(self, packages, nodeps=False):
        if not self.remote_cache.has_lists:
            self.remote_cache.refresh()

        return get_uris(self, self.remote_cache, packages, nodeps)

    def get_packages(self, candidates=None, packages=None, nodeps=False):
        if packages:
            candidates = self.get_package_candidates(packages, nodeps)

        if not candidates:
            return False

        result = download_uris(candidates)
        if result:
            self.local_cache.refresh()

        return result
Пример #2
0
class Chanko(object):
    """Top-level object of the chanko"""
    def __init__(self):
        self.base = os.getcwd()
        self.config = os.path.join(self.base, 'config')
        self.architecture = getoutput("dpkg --print-architecture")

        self.trustedkeys = os.path.join(self.config, 'trustedkeys.gpg')
        self.sources_list = os.path.join(self.config, 'sources.list')
        for f in (self.sources_list, self.trustedkeys):
            if not os.path.exists(f):
                raise Error("required file not found: " + f)

        conf = ChankoConfig(os.path.join(self.config, 'chanko.conf'))
        os.environ['CCURL_CACHE'] = conf.ccurl_cache

        self.archives = os.path.join(self.base, 'archives')
        makedirs(os.path.join(self.archives, 'partial'))

        plan_path = os.path.join(self.base, 'plan')
        plan_cpp = conf.plan_cpp.replace("-", " -").strip()
        plan_cpp = plan_cpp.split(" ") if plan_cpp else []
        self.plan = Plan(plan_path, self.architecture, plan_cpp)

        self.local_cache = LocalCache(self)
        self.remote_cache = RemoteCache(self)

    def get_package_candidates(self, packages, nodeps=False):
        if not self.remote_cache.has_lists:
            self.remote_cache.refresh()

        return get_uris(self, self.remote_cache, packages, nodeps)

    def get_packages(self, candidates=None, packages=None, nodeps=False):
        if packages:
            candidates = self.get_package_candidates(packages, nodeps)

        if not candidates:
            return False

        result = download_uris(candidates)
        if result:
            self.local_cache.refresh()

        return result