def index(request): form = AddProfileForm() if request.method == 'POST': form = AddProfileForm(request.POST) if form.is_valid(): profile = Profile() profile.user = request.user profile.name = form.cleaned_data['name'] profile.desc = form.cleaned_data['desc'] profile.arch = form.cleaned_data['arch'] while True: pid = profile.generate_pid() if not utils.check_pid(pid): profile.pid = pid break profile.save() path = utils.get_path(profile.pid) utils.prepare_profile_dir(path) utils.configure_profile(path, arch=profile.arch) return redirect(show, pid) profiles = Profile.objects.filter(user=request.user) return render_to_response('profile/index.html', {'form': form, 'profiles': profiles}, context_instance=RequestContext(request))
def search(id, packages): profile = Profile.objects.get(pk=id) path = utils.get_path(profile.pid) pkgs, ret, out, err = apt.search(path, packages) return pkgs, ret, out, err
def update(id): profile = Profile.objects.get(pk=id) path = utils.get_path(profile.pid) ret, out, err = apt.update(path) profile.repo_updated = datetime.now() profile.tid_update = None profile.save()
def upgrade(id, type='upgrade'): profile = Profile.objects.get(pk=id) path = utils.get_path(profile.pid) if type == 'dist-upgrade': ret, out, err = apt.dist_upgrade(path) else: ret, out, err = apt.upgrade(path) return type, ret, out, err
def sources(request, profile): form = SourcesForm(request.POST) if form.is_valid(): sources = form.cleaned_data['sources'] path = utils.get_path(profile.pid) utils.update_sources(path, sources) profile.sources_updated = datetime.now() profile.repo_updated = None profile.save() return redirect(show, profile.pid) else: print "invalid" print form.as_p() return HttpResponse('sources pid=%d' % profile.pid)
def handle_uploaded_status(profile, file): # FIXME file size should be checked and limited path = utils.get_path(profile.pid) status = file.temporary_file_path() tmp = None if file.name.endswith('.gz') or file.name.endswith('.bz2'): tmp = _decompress(file.name, file.temporary_file_path()) utils.update_status(path, tmp) os.unlink(tmp) else: utils.update_status(path, status) return path
def show(request, profile): upload_form = UploadStatusForm() path = utils.get_path(profile.pid) sources = utils.get_repo(path) sources_form = SourcesForm({'sources': sources}) install_form = InstallForm() search_form = SearchForm() return render_to_response('profile/show.html', {'profile': profile, 'upload': upload_form, 'sources': sources_form, 'install': install_form, 'search': search_form}, context_instance=RequestContext(request))
def info(request, profile, pkg): format = request.GET.get('format', 'html') if not format in ['html', 'json']: format = 'html' path = utils.get_path(profile.pid) pkg, code, out, err = apt.show(path, pkg) if code == 100: # Not found raise Http404() info, keys = parse_apt_show(out) if info is None: pkg = None sdesc = '' desc = '' data = [] else: sdesc = info['Description'].split("\n")[0] desc = "\n".join(info['Description'].split("\n")[1:]) data = [] for key in keys: data.append((key, info[key])) if format == 'html': return render_to_response('profile/info.html', {'pkg': pkg, 'desc': desc, 'sdesc': sdesc, 'data': data}) elif format == 'json': data = {'stat': 'ok', 'type': 'pkgshow', 'data': {'package': pkg, 'desc': desc, 'sdesc': sdesc, 'data': data}} jdata = json.dumps(data) return render_to_response('profile/json', {'json': jdata}, mimetype='application/json')