Ejemplo n.º 1
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)
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        repo = kwargs.pop("repo")
        forms.Form.__init__(self, *args, **kwargs)

        self.fields['packages'].choices = []
        for pkg in self.get_packages(repo):
            nevra = repo_utils.get_nevra(pkg, arch=repo['arch'])
            self.fields['packages'].choices.append((pkg['id'], nevra))
Ejemplo n.º 3
0
def demote_ok(request, pid=None):
    pset = PackageSet.objects.get(pk=pid)
    form = DemoteOkayForm(request.POST or None, pset=pset)
    repos = PackageSetRepo.objects.filter(packageset=pset.pk)
    
    if request.method == 'POST':
        repoapi = RepositoryAPI()
        packages = [cPickle.loads(str(p.pkgobj))
                    for p in PackageSetPackage.objects.filter(packageset=pset.pk)]
        success = True
        
        for repo in repos:
            logger.info("Deleting %s from repo %s" %
                        ([repo_utils.get_nevra(p) for p in packages],
                         repo.repoid))
            for package in packages:
                try:
                    if not repoapi.remove_package(repo.repoid,
                                                  pkgobj=[package]):
                        success = False
                        messages.warning(request,
                                         "Failed to remove package %s from %s"
                                         % (repo_utils.get_nevra(package),
                                            repo.name))
                except ServerRequestError, err:
                    success = False
                    messages.error(request,
                                   "Failed to remove package %s from %s: %s" %
                                   (repo_utils.get_nevra(package),
                                    repo.name,
                                    err[1]))

        if success:
            messages.success(request,
                             "Successfully removed %s from %s" %
                             (", ".join([repo_utils.get_nevra(p)
                                         for p in packages]),
                              ", ".join([r.name for r in repos])))
        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)
Ejemplo n.º 4
0
def promote_ok(request, pid=None):
    pset = PackageSet.objects.get(pk=pid)
    repos = PackageSetRepo.objects.filter(packageset=pset.pk)
    form = PromoteOkayForm(request.POST or None, pset=pset)
    if request.POST:
        repoapi = RepositoryAPI()
        packages = \
            [cPickle.loads(str(p.pkgobj))
             for p in PackageSetPackage.objects.filter(packageset=pset.pk)]
        success = True
        logger.info("Promoting %s to repo(s) %s" %
                    ([p['id'] for p in packages], [r.repoid for r in repos]))
        for repo in repos:
            try:
                errors = repoapi.add_package(repo.repoid,
                                             [p['id'] for p in packages])
                for error in errors:
                    if error[4]:
                        success = False
                        messages.warning(request,
                                         "Failed to add package %s to %s: %s" %
                                         (error[2], repo.repoid, error[4]))
            except ServerRequestError, err:
                success = False
                messages.error(request,
                               "Failed to add packages to %s (%s): %s" %
                               (repo.repoid,
                                ", ".join([repo_utils.get_nevra(p)
                                           for p in packages]),
                                err[1]))

        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)
Ejemplo n.º 5
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())
Ejemplo n.º 6
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.º 7
0
def nevra(pkg):
    return repo_utils.get_nevra(pkg)