Mercurial > hg > PaInt
comparison paint/package.py @ 36:f59da9e6be37
this almost works, dammit
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 30 Mar 2012 14:44:12 -0700 |
parents | e8d73f9e99fb |
children | 36e70712fc9a |
comparison
equal
deleted
inserted
replaced
35:e8d73f9e99fb | 36:f59da9e6be37 |
---|---|
1 """ | 1 """ |
2 package model for python PAckage INTrospection | 2 package model for python PAckage INTrospection |
3 """ | 3 """ |
4 | |
5 # TODO: use pkginfo.sdist more | |
4 | 6 |
5 import os | 7 import os |
6 import pip | 8 import pip |
7 import pypi | 9 import pypi |
8 import shutil | 10 import shutil |
189 package = self.package() | 191 package = self.package() |
190 | 192 |
191 # determine the extension (XXX hacky) | 193 # determine the extension (XXX hacky) |
192 extensions = ('.tar.gz', '.zip', '.tar.bz2') | 194 extensions = ('.tar.gz', '.zip', '.tar.bz2') |
193 for ext in extensions: | 195 for ext in extensions: |
194 if package.endsiwth(ext): | 196 if package.endswith(ext): |
195 return ext | 197 return ext |
196 | 198 |
197 raise Exception("Extension %s not found: %s" % (extensions, package)) | 199 raise Exception("Extension %s not found: %s" % (extensions, package)) |
198 | 200 |
199 def package(self, destination=None): | 201 def package(self, destination=None): |
224 | 226 |
225 self._build_path = os.path.join(dist, contents[0]) | 227 self._build_path = os.path.join(dist, contents[0]) |
226 | 228 |
227 # destination | 229 # destination |
228 # use an evil recursive trick | 230 # use an evil recursive trick |
229 return self.repackage(destination=destination) | |
230 if destination: | 231 if destination: |
231 shutil.copy(self._build_path, destination) | 232 return self.package(destination=destination) |
232 return destination | |
233 | 233 |
234 return self._build_path | 234 return self._build_path |
235 | 235 |
236 def download(self, directory): | 236 def download(self, directory): |
237 """download a package and all its dependencies using pip""" | 237 """download a package and all its dependencies using pip""" |
257 src = os.path.join(tempdir, package) | 257 src = os.path.join(tempdir, package) |
258 | 258 |
259 # make a package of the thing | 259 # make a package of the thing |
260 package = Package(src) | 260 package = Package(src) |
261 | 261 |
262 # # get destination dirname, filename | 262 # get destination dirname, filename |
263 # try: | 263 dirname, filename = package.pypi_path() |
264 # dirname, filename = pypi.pypi_path(src) | 264 |
265 # except ValueError: | 265 # make the directory if it doesn't exist |
266 # # PKG-INFO not found | 266 subdir = os.path.join(directory, dirname) |
267 # pass # TODO | 267 if not os.path.exists(subdir): |
268 | 268 os.makedirs(subdir) |
269 # # make the directory if it doesn't exist | 269 assert os.path.isdir(subdir) |
270 # subdir = os.path.join(directory, dirname) | 270 |
271 # if not os.path.exists(subdir): | 271 # move the file |
272 # os.makedirs(subdir) | 272 self.package(destination=os.path.join(subdir, filename)) |
273 # assert os.path.isdir(subdir) | |
274 | |
275 # # move the file | |
276 # shutil.move(src, os.path.join(subdir, filename)) | |
277 finally: | 273 finally: |
278 shutil.rmtree(tempdir) | 274 shutil.rmtree(tempdir) |
279 | 275 |
280 def pypi_path(self, path): | 276 def pypi_path(self): |
281 """ | 277 """ |
282 returns subpath 2-tuple appropriate for pypi path structure: | 278 returns subpath 2-tuple appropriate for pypi path structure: |
283 http://k0s.org/portfolio/pypi.html | 279 http://k0s.org/portfolio/pypi.html |
284 """ | 280 """ |
285 info = self.info() | 281 info = self.info() |
286 # sdist = pkginfo.sdist.SDist(path) | 282 |
287 | 283 # determine the extension |
288 # determine the extension (XXX hacky) | 284 extension = self.extension() |
289 extensions = ('.tar.gz', '.zip', '.tar.bz2') | |
290 for ext in extensions: | |
291 import pdb; pdb.set_trace() | |
292 if sdist.filename.endswith(ext): | |
293 break | |
294 else: | |
295 | |
296 | 285 |
297 # get the filename destination | 286 # get the filename destination |
298 filename = '%s-%s%s' % (info['name'], ext) | 287 name = info['Name'] |
299 return sdist.name, filename | 288 version = info['Version'] |
289 filename = '%s-%s%s' % (name, version, extension) | |
290 return name, filename |