diff paint/package.py @ 29:59524b6d25c0

implementing making pypi directory strcuture from a package
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 30 Mar 2012 11:41:04 -0700
parents c44fb4b6918b
children fe5f282dca9b
line wrap: on
line diff
--- 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)