# HG changeset patch # User Jeff Hammel # Date 1330627408 28800 # Node ID c934505fa098aeded7011bba1668120f7f7384d4 # Parent bb69b82ddd17fb59ec8be2178beb3c82e8603efd sketch out quick + dirty solution; tests do not pass diff -r bb69b82ddd17 -r c934505fa098 simpypi/wsgi.py --- a/simpypi/wsgi.py Thu Mar 01 10:16:12 2012 -0800 +++ b/simpypi/wsgi.py Thu Mar 01 10:43:28 2012 -0800 @@ -59,21 +59,60 @@ if not hasattr(package, 'file') or not hasattr(package, 'filename'): return exc.HTTPBadRequest() - # successful response + # successful response: redirect to the main page response = exc.HTTPSeeOther(add_slash=True) # make a temporary copy for pkginfo # (or PaInt?) tmpdir = tempfile.mkdtemp() try: - path = os.path.join(tmpdir, filename) + path = os.path.join(tmpdir, package.filename) f = file(path, 'w') - import pdb; pdb.set_trace() + f.write(package.file.read()) f.close() - # put the package in the right place + + # get package data + sdist = pkginfo.sdist.SDist(path) + + # put the package in the right place + self.add_package(sdist) + except: + # something bad happen + response = exc.HTTPBadRequest() finally: # cleanup shutil.rmtree(tmpdir) - # redirect to the main page return response + + ### API + + def add_package(self, sdist, move=True): + """ + add a package to the directory + """ + + # make a directory for the package + directory = os.path.join(self.directory, sdist.name) + if not os.path.exists(directory): + os.makedir(directory) + assert os.path.isdir(directory) + + # determine the extension (XXX hacky) + extensions = ('.tar.gz', '.zip', '.tar.bz2') + for ext in extensions: + if sdist.filename.endswith(ext): + break + else: + raise Exception("Extension %s not found: %s" % (extensions, sdist.filename)) + + # get the filename destination + filename = '%s-%s%s' % (sdist.name, sdist.version, ext) + filename = os.path.join(directory, filename) + + if move: + # move the file + shutil.move(sdist.filename, filename) + else: + # copy the file + shutil.copy(sdist.filename, filename)