Mercurial > hg > PaInt
diff 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 |
line wrap: on
line diff
--- a/paint/package.py Fri Mar 30 11:47:28 2012 -0700 +++ b/paint/package.py Fri Mar 30 13:38:33 2012 -0700 @@ -30,8 +30,10 @@ self._tmppath = None self._egg_info_path = None + # TODO: list of temporary files/directories to be deleted + def path(self): - """filesystem path to package""" + """filesystem path to package directory""" # return cached copy if it exists if self._tmppath: @@ -54,12 +56,15 @@ return self.src - def fetch(self): + def fetch(self, filename=None): """fetch from remote source to a temporary file""" + if filename is None: + fd, filename = tempfile.mkstemp() + os.close(fd) + fp = file(filename, 'w') resource = urllib2.urlopen(self.src) - fd, filename = tempfile.mkstemp() - os.write(fd, resource.read()) - os.close(fd) + fp.write(resource.read()) + fp.close() return filename def unpack(self, archive): @@ -171,6 +176,14 @@ return dependencies + def extension(self): + """filename extension""" + + def repackage(self): + """ + repackage the package to ensure its actually in the right form + """ + def download(self, directory): """download a package and all its dependencies using pip""" if not os.path.exists(directory): @@ -194,16 +207,43 @@ # full path src = os.path.join(tempdir, package) - # get destination dirname, filename - dirname, filename = pypi.pypi_path(src) + package = Package(src) + + # # get destination dirname, filename + # try: + # dirname, filename = pypi.pypi_path(src) + # except ValueError: + # # PKG-INFO not found + # pass # TODO - # make the directory if it doesn't exist - subdir = os.path.join(directory, dirname) - if not os.path.exists(subdir): - os.makedirs(subdir) - assert os.path.isdir(subdir) + # # make the directory if it doesn't exist + # subdir = os.path.join(directory, dirname) + # if not os.path.exists(subdir): + # os.makedirs(subdir) + # assert os.path.isdir(subdir) - # move the file - shutil.move(src, os.path.join(subdir, filename)) + # # move the file + # shutil.move(src, os.path.join(subdir, filename)) finally: shutil.rmtree(tempdir) + + def pypi_path(self, path): + """ + returns subpath 2-tuple appropriate for pypi path structure: + http://k0s.org/portfolio/pypi.html + """ + info = self.info() +# sdist = pkginfo.sdist.SDist(path) + + # determine the extension (XXX hacky) + extensions = ('.tar.gz', '.zip', '.tar.bz2') + for ext in extensions: + import pdb; pdb.set_trace() + 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' % (info['name'], ext) + return sdist.name, filename