# HG changeset patch # User Jeff Hammel # Date 1291137442 28800 # Node ID 776805790c843592cc42d6d3b1cdb6f2a95bef70 # Parent fc2867bc2ba6e88af8d11b2cad95619b355d2e84 stub out getting tempita from the net; unttested diff -r fc2867bc2ba6 -r 776805790c84 makeitso/makeitso.py --- a/makeitso/makeitso.py Sun Nov 21 12:59:47 2010 -0800 +++ b/makeitso/makeitso.py Tue Nov 30 09:17:22 2010 -0800 @@ -18,20 +18,45 @@ # URL of tempita tempita_location = 'http://bitbucket.org/ianb/tempita/raw-file/tip/tempita/' +def cleanup(): + if 'tempdir' in globals(): + ### TODO: remove it + pass + try: import tempita except ImportError: # Get tempita from the net - def getFiles(url, files): + def getFiles(url, subdir, files): """ fetch files from the internet - url : base url + - subdirectory: to put things in - files : list of files to retrieve returns the location of a temporary directory """ + globals()['tempdir'] = tempfile.mkdtemp() + os.mkdir(subdir) + url = url.rstrip('/') + for filename in files: + f, headers = urllib.urlretrive('%s/%s' % (url, filename)) + content = file(f).read() + outfile = os.path.join(globals()['tempdir'], subdir, filename) + o = file(outfile, 'w') + print >> o, content + return globals()['tempdir'] - raise NotImplementedError + tempita_files = ['__init__.py', '_looper.py', 'compat3.py'] + + try: + t = getFiles(tempita_location, 'tempita', tempita_files) + sys.path.append(t) + import tempita + except: + cleanup() + raise NotImplementedError('This should say something like youre not connected to the net') + # regular expressions for finding the shebang @@ -180,6 +205,9 @@ else: content = sys.stdin.read() print substitute(content, variables=variables) + + # cleanup + cleanup() if __name__ == '__main__': main()