Ejemplo n.º 1
0
def set_gpgkeys(repo, keys, request=None, errors=None):
    repoapi = RepositoryAPI()
    if errors is None:
        errors = []
    to_remove = [k for k, kurl in repo["keys"].items() if k not in keys]
    try:
        repoapi.rmkeys(repo["id"], to_remove)
        if request:
            messages.debug(request, "Removed GPG keys %s from %s" % (to_remove, repo["name"]))
    except ServerRequestError, err:
        errors.append("Could not remove GPG keys (%s) from %s: %s" % (to_remove, repo["name"], err[1]))
Ejemplo n.º 2
0
def set_filters(repo, filters, request=None, errors=None):
    repoapi = RepositoryAPI()
    if errors is None:
        errors = []
    to_remove = [f for f in repo["filters"] if f not in filters]
    if to_remove:
        try:
            repoapi.remove_filters(repo["id"], to_remove)
            if request:
                messages.debug(request, "Removed filters %s from %s" % (to_remove, repo["id"]))
        except ServerRequestError, err:
            errors.append("Could not remove filters %s from %s: %s" % (to_remove, repo["id"], err[1]))
Ejemplo n.º 3
0
def set_groups(repo, groups, request=None, errors=None):
    repoapi = RepositoryAPI()
    if errors is None:
        errors = []
    for group in repo["groupid"]:
        if group not in groups:
            try:
                repoapi.remove_group(repo["id"], group)
                if request:
                    messages.debug(request, "Removed group %s from %s" % (group, repo["id"]))
            except ServerRequestError, err:
                errors.append("Could not remove group %s from %s: %s" % (group, repo["id"], err[1]))
Ejemplo n.º 4
0
def view(request, repo_id=None):
    repoapi = RepositoryAPI()
    repo = repo_utils.get_repo(repo_id)
    packages = repoapi.packages(repo_id)
    for pkg in packages:
        pkg['nevra'] = repo_utils.get_nevra(pkg, repo['arch'])
    editform = RepoEditForm(request.POST or None, repo=repo)
    diffform = DiffSelectForm(request.POST or None, repo=repo)
    if request.method == 'POST' and "repoedit" in request.POST:
        if editform.is_valid():
            success = True
            if editform.cleaned_data['name'] != repo['name']:
                try:
                    repoapi.update(repo['id'],
                                   dict(name=editform.cleaned_data['name'],
                                        checksum_type=editform.cleaned_data['cksum']))
                    messages.debug(request,
                                   "Updated repository name for %s" %
                                   repo['id'])
                except ServerRequestError, err:
                    success = False
                    messages.error(request,
                                   "Could not update repository info for %s: "
                                   "%s" % (repo['id'], err[1]))

            groups = filter(lambda s: s != '',
                            editform.cleaned_data['groups'] + \
                            re.split(r'\s*,\s*',
                                     editform.cleaned_data['newgroups']))
            success &= repo_utils.set_groups(repo, groups, request=request)

            success &= repo_utils.set_gpgkeys(repo,
                                              editform.cleaned_data['gpgkeys'].splitlines(),
                                              request=request)
            success &= repo_utils.set_filters(repo,
                                              editform.cleaned_data['filters'],
                                              request=request)

            if success:
                messages.success(request, "Updated repository %s" % repo['id'])
            else:
                messages.warning(request,
                                 "Errors encountered while updating repository "
                                 "%s" % repo['id'])
            repo = repo_utils.reload_repo(repo['id'])
Ejemplo n.º 5
0
        errors = []
    for group in repo["groupid"]:
        if group not in groups:
            try:
                repoapi.remove_group(repo["id"], group)
                if request:
                    messages.debug(request, "Removed group %s from %s" % (group, repo["id"]))
            except ServerRequestError, err:
                errors.append("Could not remove group %s from %s: %s" % (group, repo["id"], err[1]))

    for group in groups:
        if group not in repo["groupid"]:
            try:
                repoapi.add_group(repo["id"], group)
                if request:
                    messages.debug(request, "Added group %s to %s" % (group, repo["id"]))
            except ServerRequestError, err:
                errors.append("Could not add group %s to %s: %s" % (group, repo["id"], err[1]))

    reload_repo(repo["id"])
    if errors:
        if request:
            for err in errors:
                messages.error(request, err)
        return False
    else:
        return True


def set_filters(repo, filters, request=None, errors=None):
    repoapi = RepositoryAPI()