view example.py @ 56:6ebd2d10fc03 default tip

stub embedding fetch
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 02 Dec 2011 17:41:12 -0800
parents
children
line wrap: on
line source

#!/usr/bin/env python
"""
http://k0s.org/geekcode                                      tmp/code       file
#https://github.com/mozilla/mozbase/tarball/master#mozprofile tmp/mozprofile tar
#http://k0s.org/mozilla/hg/fetch#fetch.py                     tmp/fetch.py   hg
git://github.com/mozautomation/mozmill.git#jsbridge          tmp/jsbridge   git
"""

# example embedding fetch

def require(url):
    """
    import a module from the web
    url should be like scheme://host.name/path/to/module.py
    """
    import imp
    import os
    import tempfile
    import urllib2
    contents = urllib2.urlopen(url).read()
    filename = url.rsplit('/', 1)[-1]
    module = filename.rsplit('.', 1)[-1]
    dest = tempfile.mkstemp(suffix='.py', prefix=module)
    f = file(dest, 'w')
    f.write(contents)
    f.close()
    return imp.load_source(module, dest)