예제 #1
0
    def __initialize_repo_manager(self):
        if self.repo_manager:
            return
        """ Clean up repo metadata """
        shutil.rmtree(self.creator.cachedir + "/etc", ignore_errors=True)
        shutil.rmtree(self.creator.cachedir + "/solv", ignore_errors=True)
        shutil.rmtree(self.creator.cachedir + "/raw", ignore_errors=True)

        zypp.KeyRing.setDefaultAccept(zypp.KeyRing.ACCEPT_UNSIGNED_FILE
                                      | zypp.KeyRing.ACCEPT_VERIFICATION_FAILED
                                      | zypp.KeyRing.ACCEPT_UNKNOWNKEY
                                      | zypp.KeyRing.TRUST_KEY_TEMPORARILY)
        self.repo_manager_options = zypp.RepoManagerOptions(
            zypp.Pathname(self.creator._instroot))
        self.repo_manager_options.knownReposPath = zypp.Pathname(
            self.creator.cachedir + "/etc/zypp/repos.d")
        self.repo_manager_options.repoCachePath = zypp.Pathname(
            self.creator.cachedir)
        self.repo_manager_options.repoRawCachePath = zypp.Pathname(
            self.creator.cachedir + "/raw")
        self.repo_manager_options.repoSolvCachePath = zypp.Pathname(
            self.creator.cachedir + "/solv")
        self.repo_manager_options.repoPackagesCachePath = zypp.Pathname(
            self.creator.cachedir + "/packages")

        self.repo_manager = zypp.RepoManager(self.repo_manager_options)
예제 #2
0
파일: zypper.py 프로젝트: mzdaniel/salt
def list_repos():
    '''
    Lists all repos.

    CLI Example:

    .. code-block:: bash

       salt '*' pkg.list_repos
    '''
    with _try_zypp():
        ret = {}
        for r in zypp.RepoManager().knownRepositories():
            ret[r.alias()] = get_repo(r.alias())
        return ret
예제 #3
0
파일: zypper.py 프로젝트: mzdaniel/salt
def del_repo(repo, **kwargs):
    '''
    Delete a repo.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.del_repo alias
        salt '*' pkg.del_repo alias
    '''
    r = _get_zypp_repo(repo)
    with _try_zypp():
        zypp.RepoManager().removeRepository(r)
    return 'File {1} containing repo {0!r} has been removed.\n'.format(
        repo, r.path().c_str())
예제 #4
0
파일: zypper.py 프로젝트: mzdaniel/salt
def mod_repo(repo, **kwargs):
    '''
    Modify one or more values for a repo. If the repo does not exist, it will
    be created, so long as the following values are specified:

    repo
        alias by which the zypper refers to the repo
    url or mirrorlist
        the URL for zypper to reference

    Key/Value pairs may also be removed from a repo's configuration by setting
    a key to a blank value. Bear in mind that a name cannot be deleted, and a
    url can only be deleted if a mirrorlist is specified (or vice versa).

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.mod_repo alias alias=new_alias
        salt '*' pkg.mod_repo alias enabled=True
        salt '*' pkg.mod_repo alias url= mirrorlist=http://host.com/
    '''
    # Filter out '__pub' arguments, as well as saltenv
    repo_opts = {}
    for x in kwargs:
        if not x.startswith('__') and x not in ('saltenv',):
            repo_opts[x] = kwargs[x]

    repo_manager = zypp.RepoManager()
    try:
        r = _RepoInfo(repo_manager.getRepositoryInfo(repo))
        new_repo = False
    except RuntimeError:
        r = _RepoInfo()
        r.alias = repo
        new_repo = True
    try:
        r.options = repo_opts
    except ValueError as e:
        raise SaltInvocationError(str(e))
    with _try_zypp():
        if new_repo:
            repo_manager.addRepository(r.zypp)
        else:
            repo_manager.modifyRepository(repo, r.zypp)
    return r.options
예제 #5
0
    def __initialize_zypp(self):
        if self.Z:
            return

        zconfig = zypp.ZConfig_instance()
        """ Set system architecture """
        if self.creator.target_arch:
            zconfig.setSystemArchitecture(zypp.Arch(self.creator.target_arch))

        msger.info("zypp architecture is <%s>" % zconfig.systemArchitecture())
        """ repoPackagesCachePath is corrected by this """
        self.repo_manager = zypp.RepoManager(self.repo_manager_options)
        repos = self.repo_manager.knownRepositories()
        for repo in repos:
            if not repo.enabled():
                continue
            self.repo_manager.loadFromCache(repo)

        self.Z = zypp.ZYppFactory_instance().getZYpp()
        self.Z.initializeTarget(zypp.Pathname(self.creator._instroot))
        self.Z.target().load()
예제 #6
0
    def __init__(self):
        """
        Initialize Zypp and load all enabled repositories.
        """
        self.Z = zypp.ZYppFactory_instance().getZYpp()

        # Load system rooted at "/"...
        self.Z.initializeTarget(zypp.Pathname("/"))
        self.Z.target().load()

        # Load all enabled repositories...
        repoManager = zypp.RepoManager()
        for repo in repoManager.knownRepositories():
            if not repo.enabled():
                continue
            if not repoManager.isCached(repo):
                repoManager.buildCache(repo)
            repoManager.loadFromCache(repo)

        # Now all installed and available items are in the pool:
        log.debug("Known items: %d" % (self.Z.pool().size()))
            "wget",
            "zsh")


if __name__ == "__main__":
    zp = zypp.ZYppFactory_instance().getZYpp()

    # Must init.
    # https://github.com/openSUSE/libzypp/blob/master/zypp/ZYpp.h
    zp.initializeTarget(zypp.Pathname("/"))

    # https://github.com/openSUSE/libzypp/blob/master/zypp/Target.h
    zp.target().load()

    # https://github.com/openSUSE/libzypp/blob/master/zypp/RepoManager.h
    rm = zypp.RepoManager()
    # remove current repos
    remove_repo(rm)

    # add repos
    for name, details in REPOS.iteritems():
        repo = create_repo(
            name, details[0], details[1], details[2], details[3])
        add_repo(rm, repo)

    # Load all enabled repositories
    for repo in rm.knownRepositories():
        if not repo.enabled():
            continue

        if not rm.isCached(repo):
#! /usr/bin/python

import os, sys, types, string, re

try:
    import zypp
except ImportError:
    print 'Dummy Import Error: Unable to import zypp bindings'

print 'Reading repositories...'
Z = zypp.ZYppFactory_instance().getZYpp()
Z.initializeTarget( zypp.Pathname("/") )
Z.target().load();

repoManager = zypp.RepoManager()
repos = repoManager.knownRepositories()

for repo in repos:
    if not repo.enabled():
        continue
    if not repoManager.isCached( repo ):
        repoManager.buildCache( repo )
    repoManager.loadFromCache( repo );
print "Items: %d" % ( Z.pool().size() )

#
# Does not to check and apply updates for the update stack first.
#
Z.resolver().resolvePool()

for item in Z.pool():
예제 #9
0
파일: zypper.py 프로젝트: mzdaniel/salt
def _get_zypp_repo(repo, **kwargs):
    '''
    Get zypp._RepoInfo object by repo alias.
    '''
    with _try_zypp():
        return zypp.RepoManager().getRepositoryInfo(repo)