diff makeitso/makeitso.py @ 159:cfd4f1e91090

wip
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 30 Jul 2013 15:20:38 -0700
parents 169e02e190ef
children 668b01d04457
line wrap: on
line diff
--- a/makeitso/makeitso.py	Tue Jul 30 11:08:01 2013 -0700
+++ b/makeitso/makeitso.py	Tue Jul 30 15:20:38 2013 -0700
@@ -91,6 +91,7 @@
     f, headers = urllib.urlretrieve(uri) # XXX -> urllib2 for timeout
     return file(f).read()
 
+
 ### things that deal with variables
 
 class MissingVariablesException(Exception):
@@ -118,7 +119,7 @@
 
 class ContentTemplate(tempita.Template):
     """MakeItSo's extension of tempita's Template class"""
-    
+
     defaults = {'include': include}
 
     def __init__(self, content, name=None, interactive=True, variables=None):
@@ -129,7 +130,7 @@
 
         # TODO: automagically tell if the program is interactive or not
         self.interactive = interactive
-        
+
         tempita.Template.__init__(self, content, name=name)
 
     def get_variables(self, **variables):
@@ -163,7 +164,7 @@
                 vars.update(self.read_variables(missing))
             else:
                 raise MissingVariablesException(missing)
-            
+
     def variables(self):
         """return the variables needed for a template"""
         return self.missing()
@@ -188,7 +189,7 @@
 
     def __init__(self, uri, interactive=True, variables=None):
         content = include(uri)
-        
+
         # remove makeitso shebang if it has one
         if shebang_re.match(content):
             content = os.linesep.join(content.splitlines()[1:])
@@ -198,7 +199,7 @@
             variables['here'] = parent_uri(uri)
         # TODO: could add other metadata about the uri,
         # such as last modification time'
-        
+
         ContentTemplate.__init__(self, content, name=uri,
                                  interactive=interactive,
                                  variables=variables)
@@ -228,7 +229,7 @@
 
 class DirectoryTemplate(ContentTemplate):
     """template for a directory structure"""
-    
+
     def __init__(self, directory, interactive=True, variables=None):
         """
         - output : output directory; if None will render in place
@@ -246,7 +247,7 @@
         assert output # must provide output
         if os.path.exists(output):
             assert os.path.isdir(output), "%s: Must be a directory" % self.name
-        
+
     def missing(self, **variables):
         vars = self.defaults.copy()
         vars.update(variables)
@@ -264,7 +265,7 @@
                 missed = ContentTemplate(f).missing(**vars)
                 missing.update(missed)
                 variables.update(dict([(i, '') for i in missed]))
-                
+
                 path = os.path.join(dirpath, f)
                 template = URITemplate(path, interactive=self.interactive)
                 missed = template.missing(**vars)
@@ -284,15 +285,15 @@
         # make output directory if necessary
         if output and not os.path.exists(output):
             os.makedirs(output)
-            
+
         for dirname, dirnames, filenames in os.walk(self.name):
-            
+
             # interpolate directory names
             for d in dirnames:
                 path = os.path.join(dirname, d)
                 interpolated = ContentTemplate(path).substitute(**vars)
                 target = os.path.join(output, interpolated.split(self.name, 1)[-1].strip(os.path.sep))
-                
+
                 if os.path.exists(target):
                     # ensure its a directory
                     # TODO: check this first before interpolation is in progress