# HG changeset patch # User Jeff Hammel # Date 1330047714 28800 # Node ID a7bf894c96c7e98366c0ec7398f7d357764c2873 # Parent 6a6da56314b1acd8b111794efd3b5f77662883fa yet more stubbing diff -r 6a6da56314b1 -r a7bf894c96c7 paint/package.py --- a/paint/package.py Thu Feb 23 17:21:42 2012 -0800 +++ b/paint/package.py Thu Feb 23 17:41:54 2012 -0800 @@ -2,9 +2,14 @@ package model for python PAckage INTrospection """ +import os +import tarfile import tempfile +import urllib2 +import utils class Package(object): + # XXX much of this is generic resource stuff and should be split off def __init__(self, src): self.src = src @@ -12,14 +17,43 @@ def path(self): """filesystem path to package""" + + # return cached copy if it exists + if self._tmppath: + return self._tmppath + + # fetch from the web if a URL + tmpfile = None + src = self.src if utils.isURL(self.src): - if self._tmppath: - return self._tmppath - self.fetch() + tmpfile = self.fetch() return self._tmppath + + # unpack if an archive + if self.is_archive(src): + self.unpack(src) + return self._tmppath + return self.src def fetch(self): """fetch from remote source""" - self._tmppath = tempfile.mkdtemp() - raise NotImplementedError + + fd, filename = tmpfile.mkstemp() + resource = urllib.urlopen(self.src) + os.write(fd, resource.read()) + os.close(fd) + return filename + + def unpack(self, archive): + """unpack the archive to a temporary destination""" + # TODO: should handle zipfile additionally at least + # Ideally, this would be pluggable, etc + assert tarfile.is_tarfile + tarfile.TarFile.open( + + def is_archive(self, path): + """returns if the filesystem path is an archive""" + # TODO: should handle zipfile additionally at least + # Ideally, this would be pluggable, etc + return tarfile.is_tarfile(path) diff -r 6a6da56314b1 -r a7bf894c96c7 paint/utils.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paint/utils.py Thu Feb 23 17:41:54 2012 -0800 @@ -0,0 +1,13 @@ +""" +utility methods for PaInt +""" + +# TODO: in general, these should be upstreamed to +# python's standard library or equivalent methods +# from python's standard library used instead of +# having yet another utils.py file. + +# Until that magical day, we'll put them here + +def isURL(path_spec): + return '://' in path_spec