diff makeitso/makeitso.py @ 23:776805790c84

stub out getting tempita from the net; unttested
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 30 Nov 2010 09:17:22 -0800
parents fc2867bc2ba6
children 1b802678b341
line wrap: on
line diff
--- 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()