Mercurial > hg > simpypi
changeset 38:ee29001674af
begin to make a temporary copy (though itd be better to work in memory, ideally)
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 01 Mar 2012 10:02:31 -0800 |
parents | 1bdece293671 |
children | 619b7612c7e9 |
files | simpypi/wsgi.py |
diffstat | 1 files changed, 27 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/simpypi/wsgi.py Thu Mar 01 09:30:41 2012 -0800 +++ b/simpypi/wsgi.py Thu Mar 01 10:02:31 2012 -0800 @@ -4,7 +4,9 @@ """ import os -#from handlers import Index +import pkginfo +import shutil +import tempfile from webob import Request, Response, exc here = os.path.dirname(os.path.abspath(__file__)) @@ -47,15 +49,31 @@ """handle posting a package""" # get the package - package = request.POST.get('package') + try: + package = request.POST['package'] + except KeyError: + # sanity check: does the field exist? + return exc.HTTPBadRequest() + + # sanity check: is it a file? (TODO) + if not hasattr(package, 'file') or not hastattr(package, 'filename'): + return exc.HTTPBadRequest() + + # successful response + response = exc.HTTPSeeOther(add_slash=True) - # sanity check: - # - does the field exist? - # - is it a file? - # TODO - + # make a temporary copy for pkginfo + # (or PaInt?) + tmpdir = tempfile.mkdtemp() + try: + path = os.path.join(tmpdir, filename) + f = file(path, 'w') + import pdb; pdb.set_trace() + f.close() # put the package in the right place + finally: + # cleanup + shutil.rmtree(tmpdir) # redirect to the main page - return exc.HTTPSeeOther(add_slash=True) - + return response