Example #1
0
def rebuild_metadata(request, repo_id=None):
    RebuildMetadata.delay(repo_id, user=request.user.username)
    messages.success(request, "Rebuild of metadata for %s started" % repo_id)
    if request.GET and request.GET['next']:
        return HttpResponseRedirect(request.GET['next'])
    else:
        return HttpResponseRedirect(reverse('sponge.views.repos.list'))
Example #2
0
def add(request):
    form = RepoAddForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            repo_id = "%s-%s-%s-%s" % (form.cleaned_data['os'],
                                       form.cleaned_data['version'],
                                       form.cleaned_data['arch'],
                                       form.cleaned_data['repo'])

            if form.cleaned_data['name']:
                name = form.cleaned_data['name']
            else:
                name = "%s %s %s - %s" % (form.cleaned_data['os'].title(),
                                          form.cleaned_data['version'],
                                          form.cleaned_data['arch'],
                                          form.cleaned_data['repo'])
            
            groups = filter(lambda s: s != '',
                            form.cleaned_data['groups'] + \
                            re.split(r'\s*,\s*',
                                     form.cleaned_data['newgroups']))
            CreateRepo.delay(repo_id,
                             groups=groups,
                             name=name,
                             arch=form.cleaned_data['arch'],
                             url=form.cleaned_data['url'],
                             gpgkeys=form.cleaned_data['gpgkeys'].splitlines(),
                             cksum=form.cleaned_data['cksum'],
                             filters=form.cleaned_data['filters'],
                             user=request.user.username)
            messages.success(request,
                             "Creation of repository %s enqueued" % repo_id)
            return HttpResponseRedirect(reverse('sponge.views.repos.list'))
    return dict(form=form)
Example #3
0
def add(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            userapi = UserAPI()
            roleapi = RoleAPI()
            try:
                userapi.create(data['login'],
                               password=data['password'],
                               name=data['name'])
                messages.success(request,
                                 "Created user %s (%s)" %
                                 (data['name'], data['login']))
            except ServerRequestError, err:
                messages.error(request,
                               "Failed to create user %s (%s): %s" %
                               (data['name'], data['login'], err[1]))
                return dict(form=form)

            for role in data['roles']:
                try:
                    roleapi.add_user(role, data['login'])
                    messages.success(request,
                                     "Added role %s to user %s" %
                                     (role, data['name']))
                except ServerRequestError, err:
                    messages.error(request,
                                   "Failed to add role %s to user %s: %s" %
                                   (role, data['name'], err[1]))
            
            return HttpResponseRedirect(reverse('sponge.views.users.list'))
Example #4
0
def sync(request, repo_id=None):
    SyncRepo.delay(repo_id, user=request.user.username)
    messages.success(request, "Sync of %s started" % repo_id)
    if request.GET and request.GET['next']:
        return HttpResponseRedirect(request.GET['next'])
    else:
        return HttpResponseRedirect(reverse('sponge.views.repos.list'))
Example #5
0
def configure(request):
    form = ConfigForm(request.POST or None)
    if request.POST:
        if form.is_valid():
            for name, value in form.cleaned_data.items():
                config_utils.set(name, value)
            messages.success(request, "Configuration options set")
            #set_rebalance_schedule()
            RebalanceSyncSchedule.delay(user=request.user.username)
    return dict(form=form)
Example #6
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]))
Example #7
0
def delete(request, login=None):
    userapi = UserAPI()
    user = userapi.user(login)
    if request.method == 'POST':
        form = DeleteOkayForm(request.POST)
        if form.is_valid():
            try:
                userapi.delete(login=login)
                messages.success(request,
                                 "Deleted user %s (%s)" %
                                 (user['name'], user['login']))
                return \
                    HttpResponseRedirect(reverse('sponge.views.users.list'))
            except ServerRequestError, err:
                messages.error(request,
                               "Failed to delete user %s (%s): %s"
                               (user['name'], user['login'], err[1]))
Example #8
0
def delete(request, filter_id=None):
    filterapi = FilterAPI()
    fltr = filterapi.filter(filter_id)
    if request.method == 'POST':
        form = DeleteOkayForm(request.POST)
        if form.is_valid():
            try:
                filterapi.delete(filter_id)
                messages.success(request,
                                 "Deleted filter %s (%s)" %
                                 (fltr['description'], fltr['id']))
                return \
                    HttpResponseRedirect(reverse('sponge.views.filters.list'))
            except ServerRequestError, err:
                messages.error(request,
                               "Failed to delete filter %s (%s): %s" %
                               (fltr['description'], fltr['id'], err[1]))
Example #9
0
    def process_request(self, request):
        tasklist = CeleryTaskTracker.objects.filter(owner=request.user.username)
        for task in tasklist:
            tclass = getattr(tasks, task.taskclass)
            status = tclass.AsyncResult(task.taskid)
            if status.info:
                if status.failed() or status.state == "ERROR":
                    messages.error(request, str(status.info))
                    task.delete()
                elif status.state == "PROGRESS":
                    messages.info(request, status.info)
                elif status.state == "SUCCESS":
                    messages.success(request, status.info)
                    task.delete()
            status.forget()

        return None
Example #10
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)
Example #11
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'])
Example #12
0
def view(request, filter_id=None):
    filterapi = FilterAPI()
    fltr = filter_utils.get_filter(filter_id)
    if request.method == 'POST':
        form = FilterForm(request.POST, filter=fltr)
        if form.is_valid():
            orig = [p
                    for p in form.cleaned_data['orig_patterns'].splitlines()
                    if p]
            new = [p for p in form.cleaned_data['patterns'].splitlines() if p]
            to_remove = [p for p in orig if p not in new]
            success = True
            if to_remove:
                try:
                    filterapi.remove_packages(filter_id, to_remove)
                    messages.success(request,
                                     "Removed patterns from filter %s: %s" %
                                     (fltr['description'],
                                      ", ".join(to_remove)))
                except ServerRequestError, err:
                    success = False
                    messages.error(request,
                                   "Failed to remove %d patterns (%s) from "
                                   "filter %s: %s" %
                                   (len(to_remove), ", ".join(to_remove),
                                    fltr['description'], err[1]))
            to_add = [p for p in new if p not in orig]
            if to_add:
                try:
                    filterapi.add_packages(filter_id, to_add)
                    messages.success(request,
                                     "Added patterns to filter %s: %s" %
                                     (fltr['description'],
                                      ", ".join(to_add)))
                except ServerRequestError, err:
                    success = False
                    messages.error(request,
                                   "Failed to add %d patterns (%s) to filter "
                                   "%s: %s" %
                                   (len(to_add), ", ".join(to_add),
                                    fltr['description'], err[1]))

            if success:
                return \
                    HttpResponseRedirect(reverse('sponge.views.filters.list'))
Example #13
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)
Example #14
0
def add(request):
    if request.method == 'POST':
        form = FilterForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            filterapi = FilterAPI()
            try:
                filterapi.create(data['f_id'],
                                 data['f_type'],
                                 description=data['desc'],
                                 package_list=data['patterns'].splitlines())
                messages.success(request,
                                 "Created filter %s (%s)" %
                                 (data['desc'], data['f_id']))
                return \
                    HttpResponseRedirect(reverse('sponge.views.filters.list'))
            except ServerRequestError, err:
                messages.error(request,
                               "Failed to create filter %s (%s): %s" %
                               (data['desc'], data['f_id'], err[1]))
Example #15
0
def delete(request, task_id=None):
    # figure out if this is a pulp task or a sponge task
    taskapi = TaskAPI()
    task = taskapi.info(task_id)
    if task is not None:
        command = task['method_name'].lstrip("_")
        if task['scheduler'] == 'interval':
            command = "Scheduled %s" % command
        
        if request.method == 'POST':
            form = DeleteOkayForm(request.POST)
            if form.is_valid():
                taskapi.cancel(task_id)
                messages.success(request,
                                 "Deleted task %s (%s)" % (task_id, command))
            return HttpResponseRedirect(reverse('sponge.views.tasks.list'))
        return dict(task_id=task_id,
                    command=command,
                    form=DeleteOkayForm(dict(id=task_id)))
    else:
        # must be a sponge task
        task = CeleryTaskTracker.objects.get(taskid=task_id)
        if request.method == 'POST':
            form = DeleteOkayForm(request.POST)
            if form.is_valid():
                tclass = getattr(tasks, task.taskclass)
                status = tclass.AsyncResult(task.taskid)
                task.delete()
                status.forget()
                messages.success(request,
                                 "Deleted task %s (%s)" % (task.taskid,
                                                           task.taskclass))
            return HttpResponseRedirect(reverse('sponge.views.tasks.list'))
        return dict(task_id=task.taskid,
                    command=task.taskclass,
                    form=DeleteOkayForm(dict(id=task_id)))
Example #16
0
def view(request, login=None):
    userapi = UserAPI()
    user = user_utils.get_user(login)
    if request.method == 'POST':
        form = UserForm(request.POST, user=user)
        if form.is_valid():
            success = True
            delta = dict(name=form.cleaned_data['name'])
            if form.cleaned_data['password']:
                delta['password'] = form.cleaned_data['password']
            try:
                userapi.update(login, delta)
                messages.success(request,
                                 "Updated user information for %s" %
                                  user['name'])
            except ServerRequestError, err:
                success = False
                messages.error(request,
                               "Failed to update user information for %s: %s" %
                               (user['name'], err[1]))
            
            roleapi = RoleAPI()
            orig = [r
                    for r in form.cleaned_data['orig_roles'].splitlines()
                    if r]
            new = [r for r in form.cleaned_data['roles'] if r]
            to_remove = [r for r in orig if r not in new]
            for role in to_remove:
                try:
                    roleapi.remove_user(role, login)
                    messages.success(request,
                                     "Removed role %s from user %s" %
                                     (role, user['name']))
                except ServerRequestError, err:
                    success = False
                    messages.error(request,
                                   "Failed to remove role %s from user %s: %s"
                                   % (role, user['name'], err[1]))
            to_add = [r for r in new if r not in orig]
            for role in to_add:
                try:
                    roleapi.add_user(role, login)
                    messages.success(request,
                                     "Added role %s to user %s" %
                                     (role, user['name']))
                except ServerRequestError, err:
                    success = False
                    messages.error(request,
                                   "Failed to add role %s to user %s: %s" %
                                   (role, user['name'], err[1]))