Mercurial > hg > fetch
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 55:2dfdff7549b2 | 56:6ebd2d10fc03 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 """ | |
| 3 http://k0s.org/geekcode tmp/code file | |
| 4 #https://github.com/mozilla/mozbase/tarball/master#mozprofile tmp/mozprofile tar | |
| 5 #http://k0s.org/mozilla/hg/fetch#fetch.py tmp/fetch.py hg | |
| 6 git://github.com/mozautomation/mozmill.git#jsbridge tmp/jsbridge git | |
| 7 """ | |
| 8 | |
| 9 # example embedding fetch | |
| 10 | |
| 11 def require(url): | |
| 12 """ | |
| 13 import a module from the web | |
| 14 url should be like scheme://host.name/path/to/module.py | |
| 15 """ | |
| 16 import imp | |
| 17 import os | |
| 18 import tempfile | |
| 19 import urllib2 | |
| 20 contents = urllib2.urlopen(url).read() | |
| 21 filename = url.rsplit('/', 1)[-1] | |
| 22 module = filename.rsplit('.', 1)[-1] | |
| 23 dest = tempfile.mkstemp(suffix='.py', prefix=module) | |
| 24 f = file(dest, 'w') | |
| 25 f.write(contents) | |
| 26 f.close() | |
| 27 return imp.load_source(module, dest) |
