Esempio n. 1
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)
Esempio n. 2
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'])
Esempio n. 3
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)
Esempio n. 4
0
 def process_request(self, request):
     if (request.path != self.require_login_path and
         request.user.is_anonymous()):
         if request.POST:
             return login(request)
         else:
             return redirect_to_login(request.path, self.require_login_path)
     elif not request.user.is_anonymous():
         try:
             pulpserver = get_pulp_server(user=request.user.username)
         except (BIOError, server.ServerRequestError), err:
             logger.warning("Session for %s expired" %
                            request.user.username)
             logout(request)
             messages.warning(request, "Your session has expired")
             return redirect_to_login(request.path, self.require_login_path)
         except IOError, err:
             logger.info(err)
             logout(request)
             return redirect_to_login(request.path, self.require_login_path)