Mercurial > hg > MakeItSo
comparison makeitso/makeitso.py @ 33:190f310f2f5e
more stubbing of template classes
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Wed, 22 Dec 2010 18:51:08 -0800 |
| parents | 9422d4ad6c2c |
| children | 46c2d0a7335a |
comparison
equal
deleted
inserted
replaced
| 32:9422d4ad6c2c | 33:190f310f2f5e |
|---|---|
| 13 import urllib | 13 import urllib |
| 14 # TODO: may have to use urllib2.urlopen to get reasonable timeouts | 14 # TODO: may have to use urllib2.urlopen to get reasonable timeouts |
| 15 | 15 |
| 16 from optparse import OptionParser | 16 from optparse import OptionParser |
| 17 | 17 |
| 18 # URL of this file | 18 # URL of -this file- |
| 19 location = 'http://k0s.org/mozilla/hg/MakeItSo/raw-file/tip/makeitso/makeitso.py' | 19 location = 'http://k0s.org/mozilla/hg/MakeItSo/raw-file/tip/makeitso/makeitso.py' |
| 20 | |
| 21 ### import tempita | |
| 20 | 22 |
| 21 # URL of tempita | 23 # URL of tempita |
| 22 tempita_location = 'http://bitbucket.org/ianb/tempita/raw-file/tip/tempita/' | 24 tempita_location = 'http://bitbucket.org/ianb/tempita/raw-file/tip/tempita/' |
| 23 | 25 |
| 24 def cleanup(): | 26 def cleanup(): |
| 25 # remove temporary net module directory | 27 # remove temporary net module directory |
| 26 if 'tempdir' in globals(): | 28 if 'tempdir' in globals(): |
| 27 shutil.remove(tempdir) | 29 shutil.remove(tempdir) |
| 28 | |
| 29 try: | 30 try: |
| 30 import tempita | 31 import tempita |
| 31 except ImportError: | 32 except ImportError: |
| 32 | 33 |
| 33 # Get tempita from the net | 34 # Get tempita from the net |
| 88 class MissingVariablesException(Exception): | 89 class MissingVariablesException(Exception): |
| 89 """exception for (non-interactive) missing variables""" | 90 """exception for (non-interactive) missing variables""" |
| 90 def __init__(self, message, missing): | 91 def __init__(self, message, missing): |
| 91 self.missing = missing | 92 self.missing = missing |
| 92 | 93 |
| 93 class ContentTemplate(tempita.Template): | |
| 94 """MakeItSo's extension of tempita's Template class""" | |
| 95 defaults = {'include': include} | |
| 96 def __init__(self): | |
| 97 raise NotImplementedError | |
| 98 | |
| 99 class URITemplate(tempita.Template): | |
| 100 | |
| 101 def __init__(self, interactive=True): | |
| 102 # TODO: automagically tell if the program is interactive or not | |
| 103 raise NotImplementedError | |
| 104 | |
| 105 class DirectoryTemplate(tempita.Template): | |
| 106 def __init__(self): | |
| 107 raise NotImplementedError | |
| 108 | |
| 109 def get_missing(name_error): | 94 def get_missing(name_error): |
| 110 """ | 95 """ |
| 111 This is a horrible hack because python doesn't do the proper thing | 96 This is a horrible hack because python doesn't do the proper thing |
| 112 via eval and return the name of the variable; instead, it just gives | 97 via eval and return the name of the variable; instead, it just gives |
| 113 you a message: | 98 you a message: |
| 118 """ | 103 """ |
| 119 message = name_error.args[0] | 104 message = name_error.args[0] |
| 120 varname = message.split("'")[1] | 105 varname = message.split("'")[1] |
| 121 return varname | 106 return varname |
| 122 | 107 |
| 108 ### template classes | |
| 109 | |
| 110 class ContentTemplate(tempita.Template): | |
| 111 """MakeItSo's extension of tempita's Template class""" | |
| 112 defaults = {'include': include} | |
| 113 def __init__(self, content, interactive=True): | |
| 114 tempita.Template.__init__(self, content) | |
| 115 # TODO: automagically tell if the program is interactive or not | |
| 116 self.interactive = True | |
| 117 raise NotImplementedError | |
| 118 | |
| 119 class URITemplate(tempita.Template): | |
| 120 | |
| 121 def __init__(self, interactive=True): | |
| 122 raise NotImplementedError | |
| 123 | |
| 124 class DirectoryTemplate(tempita.Template): | |
| 125 def __init__(self): | |
| 126 raise NotImplementedError | |
| 127 | |
| 123 def missing_variables(template, variables): | 128 def missing_variables(template, variables): |
| 124 """return additional variables needed""" | 129 """return additional variables needed""" |
| 125 vars = variables.copy() | 130 vars = variables.copy() |
| 126 missing = set([]) | 131 missing = set([]) |
| 127 while True: | 132 while True: |
