# HG changeset patch # User Jeff Hammel # Date 1333132864 25200 # Node ID 59524b6d25c07f302c45f8b6ebb6aff4df1ad3f6 # Parent c44fb4b6918bbce1c98dff4c5869ee9d82cbfbaf implementing making pypi directory strcuture from a package diff -r c44fb4b6918b -r 59524b6d25c0 paint/package.py --- a/paint/package.py Fri Mar 30 11:07:15 2012 -0700 +++ b/paint/package.py Fri Mar 30 11:41:04 2012 -0700 @@ -4,6 +4,7 @@ import os import pip +import pypi import shutil import subprocess import sys @@ -182,8 +183,27 @@ download packages for a pypi directory structure http://k0s.org/portfolio/pypi.html """ + if not os.path.exists(directory): + os.makedirs(directory) + assert os.path.isdir(directory) tempdir = tempfile.mkdtemp() try: - pass + self.download(tempdir) + for package in os.listdir(tempdir): + + # full path + src = os.path.join(tempdir, package) + + # get destination dirname, filename + dirname, filename = pypi.pypi_path(src) + + # make the directory if it doesn't exist + subdir = os.path.join(directory, dirname) + if not os.path.exists(subdir): + os.path.makedirs(subdir) + assert os.path.isdir(subdir) + + # move the file + shutil.move(src, os.path.join(subdir, filename)) finally: shutil.rmtree(tempdir) diff -r c44fb4b6918b -r 59524b6d25c0 paint/pypi.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paint/pypi.py Fri Mar 30 11:41:04 2012 -0700 @@ -0,0 +1,25 @@ +""" +functions for python package indices +""" + +import os +import pkginfo + +def pypi_path(path): + """ + returns subpath 2-tuple appropriate for pypi path structure: + http://k0s.org/portfolio/pypi.html + """ + sdist = pkginfo.sdist.SDist(path) + + # 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) + return sdist.name, filename