Пример #1
0
def promote_package(request, repo_id=None, package=None):
    repo = repo_utils.get_repo(repo_id)
    pkgid = package
    package = repo_utils.get_package(repo, id=pkgid)
    if len(repo['children']) > 1:
        children = [(r['id'], r['name']) for r in repo['children']]
        form = PromoteRepoSelectionForm(request.POST or None, repos=children)
        if request.method == 'POST':
            pset = PackageSet.objects.create(stype="promote")
            pset.save()
            for prid in form.cleaned_data['repos']:
                prepo = repo_utils.get_repo(prid)
                psrepo = PackageSetRepo.objects.create(packageset=pset,
                                                       repoid=prepo['id'],
                                                       name=prepo['name'])
                psrepo.save()
            pkg = \
                PackageSetPackage.objects.create(packageset=pset,
                                                 packageid=package['id'],
                                                 pkgobj=cPickle.dumps(package))
        pkg.save()
        return dict(repo=repo, package=package, form=form)
    else:
        pset = PackageSet.objects.create(stype="promote")
        pset.save()
        prepo = PackageSetRepo.objects.create(packageset=pset,
                                              repoid=repo['children'][0]['id'],
                                              name=repo['name'])
        prepo.save()
        pkg = PackageSetPackage.objects.create(packageset=pset,
                                               packageid=package['id'],
                                               pkgobj=cPickle.dumps(package))
        pkg.save()
        return HttpResponseRedirect(reverse("sponge.views.repos.promote_ok",
                                            kwargs=dict(pid=pset.pk)))
Пример #2
0
def diff(request, repo_id=None, repo_id2=None):
    repoapi = RepositoryAPI()
    if request.GET:
        mode = request.GET.get("mode", "all")
    else:
        mode = "all"
    
    repo1 = repo_utils.get_repo(repo_id)
    repo2 = repo_utils.get_repo(repo_id2)
    packages1 = dict([("%s.%s" % (p['name'], p['arch']), p)
                      for p in repoapi.packages(repo_id)])
    packages2 = dict([("%s.%s" % (p['name'], p['arch']), p)
                      for p in repoapi.packages(repo_id2)])
    pkg_names = set(packages1.keys() + packages2.keys())
    allpackages = dict()
    for pkg in pkg_names:
        if pkg in packages1:
            nevra1 = repo_utils.get_nevra(packages1[pkg])
        else:
            nevra1 = None
        if pkg in packages2:
            nevra2 = repo_utils.get_nevra(packages2[pkg])
        else:
            nevra2 = None
        if nevra1 == nevra2 and mode == "diff":
            continue
        
        allpackages[pkg] = dict()
        allpackages[pkg]["repo1"] = nevra1
        allpackages[pkg]["repo2"] = nevra2

    return dict(repo1=repo1, repo2=repo2, mode=mode,
                packages1=packages1, packages2=packages2,
                allpackages=allpackages)
Пример #3
0
def demote_package(request, repo_id=None, package=None):
    repo = repo_utils.get_repo(repo_id)
    pkgid = package
    package = repo_utils.get_package(repo, id=pkgid)
    pset = PackageSet.objects.create(stype="demote")
    pset.save()
    prepo = PackageSetRepo.objects.create(packageset=pset,
                                          repoid=repo['id'],
                                          name=repo['name'])
    prepo.save()
    pkg = PackageSetPackage.objects.create(packageset=pset,
                                           packageid=package['id'],
                                           pkgobj=cPickle.dumps(package))
    pkg.save()
    return HttpResponseRedirect(reverse("sponge.views.repos.demote_ok",
                                        kwargs=dict(pid=pset.pk)))
Пример #4
0
def delete(request, repo_id=None):
    repo = repo_utils.get_repo(repo_id)
    form = DeleteOkayForm(request.POST or None, dict(id=repo_id))
    if request.method == 'POST':
        if form.is_valid():
            repoapi = RepositoryAPI()
            try:
                repoapi.delete(repo_id)
                messages.success(request,
                                 "Deleted repository %s (%s)" %
                                 (repo['name'], repo['id']))
                return \
                    HttpResponseRedirect(reverse('sponge.views.repos.list'))
            except ServerRequestError, err:
                messages.error(request,
                               "Failed to delete repository %s (%s): %s"
                               (repo['name'], repo['id'], err[1]))
Пример #5
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'])
Пример #6
0
    def __init__(self, *args, **kwargs):
        if "pset" in kwargs:
            pset = kwargs.pop("pset")
            packages = dict()
            for pspkg in PackageSetPackage.objects.filter(packageset=pset.pk):
                pkg = cPickle.loads(str(pspkg.pkgobj))
                packages[pkg['id']] = repo_utils.get_nevra(pkg)
        elif "repo" in kwargs and "package" in kwargs:
            repo = repo_utils.get_repo(kwargs.pop("repo"))
            package = kwargs.pop("package")
            packages = {package['id']: repo_utils.get_nevra(package)}
                
        forms.Form.__init__(self, *args, **kwargs)
        self.label_suffix = ''

        for packageid, nevra in packages.items():
            self.fields[packageid] = forms.BooleanField(label=nevra,
                                                        initial=True,
                                                        widget=LabelWidget())
Пример #7
0
def promote_select(request, repo_id=None):
    repo = repo_utils.get_repo(repo_id)
    form = PromotePackageSelectionForm(request.POST or None, repo=repo)
    if request.method == 'POST' and form.is_valid():
        repoapi = RepositoryAPI()
        pset = PackageSet.objects.create(stype="promote")
        pset.save()
        prepo = PackageSetRepo.objects.create(packageset=pset,
                                              repoid=repo['id'],
                                              name=repo['name'])
        prepo.save()
        packages = []
        for pkg in repoapi.packages(repo['parent']['id']):
            if pkg['id'] in form.cleaned_data['packages']:
                packages.append(pkg)
                pspkg = \
                    PackageSetPackage.objects.create(packageset=pset,
                                                     packageid=pkg['id'],
                                                     pkgobj=cPickle.dumps(pkg))
                pspkg.save()

        deps = repo_utils.resolve_deps(packages,
                                       [repo['parent']['id']],
                                       pkgfilter=repoapi.packages(repo['id']))
        for pkg in deps:
            pspkg = PackageSetPackage.objects.create(packageset=pset,
                                                     packageid=pkg['id'],
                                                     pkgobj=cPickle.dumps(pkg))
            pspkg.save()
        return HttpResponseRedirect(reverse('sponge.views.repos.promote_ok',
                                            kwargs=dict(pid=pset.pk)))
    packages = repo_utils.get_updates(repo)
    if packages:
        return dict(repo=repo, form=form)
    else:
        messages.info(request,
                      "No packages available to be promoted from %s to %s" %
                      (repo['parent']['name'], repo['name']))
        return HttpResponseRedirect(reverse('sponge.views.repos.list'))
Пример #8
0
def clone(request, repo_id=None):
    repo = repo_utils.get_repo(repo_id)
    form = RepoCloneForm(request.POST or None, repo=repo)
    if request.method == 'POST':
        if form.is_valid():
            groups = filter(lambda s: s != '',
                            form.cleaned_data['groups'] + \
                            re.split(r'\s*,\s*',
                                     form.cleaned_data['newgroups']))

            clone_id = "%s-%s" % (form.cleaned_data["clone_id"],
                                  repo_utils.get_branch_id(repo))
            clone_name = "%s: %s" % (form.cleaned_data["clone_name"],
                                     repo_utils.get_branch_name(repo))
            CloneRepo.delay(clone_id,
                            parent=repo,
                            name=clone_name,
                            groups=groups,
                            filters=form.cleaned_data['filters'],
                            user=request.user.username)
            return HttpResponseRedirect(reverse('sponge.views.repos.list'))
    return dict(repo=repo, form=form)
Пример #9
0
def demote_select(request, repo_id=None):
    repo = repo_utils.get_repo(repo_id)
    form = DemotePackageSelectionForm(request.POST or None, repo=repo)
    if request.method == 'POST' and form.is_valid():
        pset = PackageSet.objects.create(stype="demote")
        pset.save()
        prepo = PackageSetRepo.objects.create(packageset=pset,
                                              repoid=repo['id'],
                                              name=repo['name'])
        prepo.save()
        repoapi = RepositoryAPI()
        for pkg in repoapi.packages(repo['id']):
            if pkg['id'] in form.cleaned_data['packages']:
                pspkg = \
                    PackageSetPackage.objects.create(packageset=pset,
                                                     packageid=pkg['id'],
                                                     pkgobj=cPickle.dumps(pkg))
                pspkg.save()
        return HttpResponseRedirect(reverse('sponge.views.repos.demote_ok',
                                            kwargs=dict(pid=pset.pk)))
    else:
        packages = repo_utils.get_updates(repo)
        return dict(repo=repo, form=form)
Пример #10
0
                           gpgkeys=keylist,
                           checksum_type=cksum)
        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: "
Пример #11
0
        if success:
            messages.success(request,
                             "Successfully added packages to repo(s) %s: %s" %
                             (",".join([r.name for r in repos]),
                              ", ".join([repo_utils.get_nevra(p)
                                         for p in packages])))
        pset.delete()
        if len(repos) == 1:
            nexturl = reverse("sponge.views.repos.view",
                              kwargs=dict(repo_id=repos[0].repoid))
        else:
            nexturl = reverse("sponge.views.repos.list")
        return HttpResponseRedirect(nexturl)

    return dict(form=form,
                repos=[repo_utils.get_repo(r.repoid) for r in repos])

@template("promote_select_repos.html")
def promote_package(request, repo_id=None, package=None):
    repo = repo_utils.get_repo(repo_id)
    pkgid = package
    package = repo_utils.get_package(repo, id=pkgid)
    if len(repo['children']) > 1:
        children = [(r['id'], r['name']) for r in repo['children']]
        form = PromoteRepoSelectionForm(request.POST or None, repos=children)
        if request.method == 'POST':
            pset = PackageSet.objects.create(stype="promote")
            pset.save()
            for prid in form.cleaned_data['repos']:
                prepo = repo_utils.get_repo(prid)
                psrepo = PackageSetRepo.objects.create(packageset=pset,