Ejemplo n.º 1
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.º 2
0
        except ServerRequestError, err:
            raise TaskExecutionError("Could not create repo %s: %s" %
                                     (repo_id, err[1]))

        self.update("Repository %s created, running sync" % repo_id)

        try:
            repo_utils.sync_foreground(repo_id)
            self.update("Repository %s synced, adding filters" % repo_id)
        except Exception, err:
            self.update("Repository %s failed to sync: %s" % (repo_id, err),
                        state="ERROR")

        repo = repo_utils.get_repo(repo_id)
        errors = []
        if repo_utils.set_filters(repo, filters, errors=errors):
            self.update("Filters added to %s" % repo_id)
        else:
            self.update("Error adding filters to %s: %s" % (repo_id,
                                                            ", ".join(errors)),
                        state="ERROR")

        errors = []
        if not repo_utils.rebalance_sync_schedule(errors):
            for error in errors:
                self.update(error, state="ERROR")

        if self.errors:
            raise TaskExecutionError("Created %s (%s), but encountered errors: "
                                     "%s" %
                                     (name, repo_id, self.errors))