Skip to content

Commit

Permalink
mild refactoring
Browse files Browse the repository at this point in the history
 - move event firing into views, factor it away from index.py
  • Loading branch information
whitmo committed Sep 14, 2012
1 parent 150a12d commit 519d74c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions cheeseprism/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def upload(context, request):
dest = path(request.file_root) / utils.secure_filename(fieldstorage.filename)

dest.write_bytes(fieldstorage.file.read())
request.index.update_by_request(request)
pkgdata, _ = request.index.register_archive(dest, registry=request.registry)
request.registry.notify(event.PackageAdded(request.index,
name=pkgdata['name'],
version=pkgdata['version']))
request.response.headers['X-Swalow-Status'] = 'SUCCESS'
return request.response

Expand Down Expand Up @@ -113,7 +116,9 @@ def regenerate_index(context, request):
return {}


@view_config(name='load-requirements', renderer='requirements_upload.html', context=resources.App)
@view_config(name='load-requirements',
renderer='requirements_upload.html',
context=resources.App)
def from_requirements(context, request):
if request.method == "POST":
req_text = request.POST['req_file'].file.read()
Expand All @@ -123,17 +128,20 @@ def from_requirements(context, request):
filename.write_text(req_text)

names = []
requirement_set, finder = pipext.RequirementDownloader.req_set_from_file(filename, request.file_root)
downloader = pipext.RequirementDownloader(requirement_set, finder, seen=set(request.index_data))
rd_class = pipext.RequirementDownloader
requirement_set, finder = rd_class.req_set_from_file(filename, request.file_root)
downloader = rd_class(requirement_set, finder, seen=set(request.index_data))

for pkginfo, outfile in downloader.download_all():
name = pkginfo.name
names.append(name)

index.update_by_request(request)
request.registry.notify(event.IndexUpdate(request.index_data_path, request.index))

flash = request.session.flash
if names:
flash('The following packages were installed from the requirements file: %s' % ", ".join(names))
flash('The following packages were installed'
'from the requirements file: %s' % ", ".join(names))

if downloader.skip:
for dl in (x.filename for x in downloader.skip):
Expand Down

0 comments on commit 519d74c

Please sign in to comment.