comparison 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
comparison
equal deleted inserted replaced
28:c44fb4b6918b 29:59524b6d25c0
2 package model for python PAckage INTrospection 2 package model for python PAckage INTrospection
3 """ 3 """
4 4
5 import os 5 import os
6 import pip 6 import pip
7 import pypi
7 import shutil 8 import shutil
8 import subprocess 9 import subprocess
9 import sys 10 import sys
10 import tarfile 11 import tarfile
11 import tempfile 12 import tempfile
180 def pypi(self, directory): 181 def pypi(self, directory):
181 """ 182 """
182 download packages for a pypi directory structure 183 download packages for a pypi directory structure
183 http://k0s.org/portfolio/pypi.html 184 http://k0s.org/portfolio/pypi.html
184 """ 185 """
186 if not os.path.exists(directory):
187 os.makedirs(directory)
188 assert os.path.isdir(directory)
185 tempdir = tempfile.mkdtemp() 189 tempdir = tempfile.mkdtemp()
186 try: 190 try:
187 pass 191 self.download(tempdir)
192 for package in os.listdir(tempdir):
193
194 # full path
195 src = os.path.join(tempdir, package)
196
197 # get destination dirname, filename
198 dirname, filename = pypi.pypi_path(src)
199
200 # make the directory if it doesn't exist
201 subdir = os.path.join(directory, dirname)
202 if not os.path.exists(subdir):
203 os.path.makedirs(subdir)
204 assert os.path.isdir(subdir)
205
206 # move the file
207 shutil.move(src, os.path.join(subdir, filename))
188 finally: 208 finally:
189 shutil.rmtree(tempdir) 209 shutil.rmtree(tempdir)