Mercurial > mozilla > hg > talosnames
view talosnames/require.py @ 31:c6580ad2612f
better formatting of command
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 17 Jul 2012 21:36:05 -0700 |
parents | 1b18b2746e69 |
children | cc0edf61ab21 |
line wrap: on
line source
import imp import os import tempfile import urllib2 def require(url): """ import a module from the web url should be like scheme://host.name/path/to/module.py """ contents = urllib2.urlopen(url).read() filename = url.rsplit('/', 1)[-1] module = filename.rsplit('.', 1)[-1] dest = tempfile.mktemp(suffix='.py', prefix=module) f = file(dest, 'w') f.write(contents) f.close() return imp.load_source(module, dest) # TODO: make an equivalent method for a tarball