diff makeitso/makeitso.py @ 44:6e08cca7d656

do API variable reading and stubbing a bit for control flow
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 04 Jan 2011 18:07:18 -0800
parents 73dac34d2692
children 2765a700982e
line wrap: on
line diff
--- a/makeitso/makeitso.py	Tue Jan 04 17:40:21 2011 -0800
+++ b/makeitso/makeitso.py	Tue Jan 04 18:07:18 2011 -0800
@@ -89,7 +89,7 @@
         return os.path.basename(uri)
 
 def include(uri):
-    f, headers = urllib.urlretrieve(uri)
+    f, headers = urllib.urlretrieve(uri) # XXX -> urllib2 for timeout
     return file(f).read()
 
 ### things that deal with variables
@@ -146,6 +146,24 @@
                 missing.add(missed)
                 vars[missed] = ''
         return missing
+
+    def get_variables(self, **variables):
+        vars = self.defaults.copy()
+        vars.update(variables)
+        return vars
+
+    def check_missing(self, vars):
+        """
+        check for missing variables and, if applicable,
+        update them from the command line
+        """
+        missing = self.missing(**vars)
+        if missing:
+            if self.interactive:
+                vars.update(self.read_variables(missing))
+            else:
+                raise MissingVariablesException(missing)
+        
     
     def variables(self):
         """return the variables needed for a template"""
@@ -153,14 +171,8 @@
 
     def substitute(self, **variables):
         """interactive (for now) substitution"""
-        vars = self.defaults.copy()
-        vars.update(variables)
-        missing = self.missing(**vars)
-        if missing:
-            if self.interactive:
-                vars.update(self.read_variables(missing))
-            else:
-                raise MissingVariablesException(missing)
+        vars = self.get_variables()
+        self.check_missing(vars)
         return self._substitute(**vars)
 
     def _substitute(self, **variables):
@@ -294,6 +306,7 @@
         self.templates = []
         self.output = output
         for template in templates:
+            # TODO: check if the template is a [e.g] PasteScript.template entry point
             if os.path.isdir(template):
                 self.templates.append(DirectoryTemplate(template, interactive=self.interactive, output=output, **variables))
             else: