comparison paint/package.py @ 31:5fb1844db0b2

back to the drawring broad
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 30 Mar 2012 13:38:33 -0700
parents fe5f282dca9b
children f2e31ac03bb3
comparison
equal deleted inserted replaced
30:fe5f282dca9b 31:5fb1844db0b2
28 28
29 # ephemeral data 29 # ephemeral data
30 self._tmppath = None 30 self._tmppath = None
31 self._egg_info_path = None 31 self._egg_info_path = None
32 32
33 # TODO: list of temporary files/directories to be deleted
34
33 def path(self): 35 def path(self):
34 """filesystem path to package""" 36 """filesystem path to package directory"""
35 37
36 # return cached copy if it exists 38 # return cached copy if it exists
37 if self._tmppath: 39 if self._tmppath:
38 return self._tmppath 40 return self._tmppath
39 41
52 os.remove(tmpfile) 54 os.remove(tmpfile)
53 return self._tmppath 55 return self._tmppath
54 56
55 return self.src 57 return self.src
56 58
57 def fetch(self): 59 def fetch(self, filename=None):
58 """fetch from remote source to a temporary file""" 60 """fetch from remote source to a temporary file"""
61 if filename is None:
62 fd, filename = tempfile.mkstemp()
63 os.close(fd)
64 fp = file(filename, 'w')
59 resource = urllib2.urlopen(self.src) 65 resource = urllib2.urlopen(self.src)
60 fd, filename = tempfile.mkstemp() 66 fp.write(resource.read())
61 os.write(fd, resource.read()) 67 fp.close()
62 os.close(fd)
63 return filename 68 return filename
64 69
65 def unpack(self, archive): 70 def unpack(self, archive):
66 """unpack the archive to a temporary destination""" 71 """unpack the archive to a temporary destination"""
67 # TODO: should handle zipfile additionally at least 72 # TODO: should handle zipfile additionally at least
169 if dep in dependencies: 174 if dep in dependencies:
170 dependencies[dep] = link 175 dependencies[dep] = link
171 176
172 return dependencies 177 return dependencies
173 178
179 def extension(self):
180 """filename extension"""
181
182 def repackage(self):
183 """
184 repackage the package to ensure its actually in the right form
185 """
186
174 def download(self, directory): 187 def download(self, directory):
175 """download a package and all its dependencies using pip""" 188 """download a package and all its dependencies using pip"""
176 if not os.path.exists(directory): 189 if not os.path.exists(directory):
177 os.makedirs(directory) 190 os.makedirs(directory)
178 assert os.path.isdir(directory) 191 assert os.path.isdir(directory)
192 for package in os.listdir(tempdir): 205 for package in os.listdir(tempdir):
193 206
194 # full path 207 # full path
195 src = os.path.join(tempdir, package) 208 src = os.path.join(tempdir, package)
196 209
197 # get destination dirname, filename 210 package = Package(src)
198 dirname, filename = pypi.pypi_path(src) 211
199 212 # # get destination dirname, filename
200 # make the directory if it doesn't exist 213 # try:
201 subdir = os.path.join(directory, dirname) 214 # dirname, filename = pypi.pypi_path(src)
202 if not os.path.exists(subdir): 215 # except ValueError:
203 os.makedirs(subdir) 216 # # PKG-INFO not found
204 assert os.path.isdir(subdir) 217 # pass # TODO
205 218
206 # move the file 219 # # make the directory if it doesn't exist
207 shutil.move(src, os.path.join(subdir, filename)) 220 # subdir = os.path.join(directory, dirname)
221 # if not os.path.exists(subdir):
222 # os.makedirs(subdir)
223 # assert os.path.isdir(subdir)
224
225 # # move the file
226 # shutil.move(src, os.path.join(subdir, filename))
208 finally: 227 finally:
209 shutil.rmtree(tempdir) 228 shutil.rmtree(tempdir)
229
230 def pypi_path(self, path):
231 """
232 returns subpath 2-tuple appropriate for pypi path structure:
233 http://k0s.org/portfolio/pypi.html
234 """
235 info = self.info()
236 # sdist = pkginfo.sdist.SDist(path)
237
238 # determine the extension (XXX hacky)
239 extensions = ('.tar.gz', '.zip', '.tar.bz2')
240 for ext in extensions:
241 import pdb; pdb.set_trace()
242 if sdist.filename.endswith(ext):
243 break
244 else:
245 raise Exception("Extension %s not found: %s" % (extensions, sdist.filename))
246
247 # get the filename destination
248 filename = '%s-%s%s' % (info['name'], ext)
249 return sdist.name, filename