Mercurial > hg > MakeItSo
comparison makeitso/template.py @ 58:112bf081148c
make a full CLI class for a single API template
| author | Jeff Hammel <jhammel@mozilla.com> | 
|---|---|
| date | Thu, 06 Jan 2011 15:54:55 -0800 | 
| parents | 728cae02a6ed | 
| children | 30100690ad3f | 
   comparison
  equal
  deleted
  inserted
  replaced
| 57:074a32920f7c | 58:112bf081148c | 
|---|---|
| 12 Undefined = Undefined() # singleton | 12 Undefined = Undefined() # singleton | 
| 13 | 13 | 
| 14 class Variable(object): | 14 class Variable(object): | 
| 15 """variable object for MakeItSo templates""" | 15 """variable object for MakeItSo templates""" | 
| 16 | 16 | 
| 17 def __init__(self, name, default=Undefined, description=None, | 17 def __init__(self, name, description=None, default=Undefined, | 
| 18 cast=None): | 18 cast=None): | 
| 19 self.name = name | 19 self.name = name | 
| 20 self.default = default | 20 self.default = default | 
| 21 self.description = description | 21 self.description = description | 
| 22 | 22 | 
| 61 vars = [] | 61 vars = [] | 
| 62 | 62 | 
| 63 # inspect the templates for more variables | 63 # inspect the templates for more variables | 
| 64 look = False | 64 look = False | 
| 65 | 65 | 
| 66 def __init__(self, output=None, interactive=True, usedefaults=False, **variables): | 66 def __init__(self, output=None, interactive=True, usedefaults=True, | 
| 67 variables=None): | |
| 67 """ | 68 """ | 
| 68 - output : output file or directory | 69 - output : output file or directory | 
| 69 - interactive : whether tointeractively get variables | 70 - interactive : whether tointeractively get variables | 
| 70 - usedefaults : try to use the default values if not specified | 71 - usedefaults : try to use the default values if not specified | 
| 71 """ | 72 """ | 
| 72 | 73 | 
| 73 assert self.templates | 74 assert self.templates | 
| 74 self.output = output | 75 self.output = output | 
| 75 self.interactive = interactive | 76 self.interactive = interactive | 
| 76 self.location = os.path.dirnme(os.path.abspath(__file__)) | 77 self.location = os.path.dirname(os.path.abspath(__file__)) | 
| 77 self.defaults = variables.copy | 78 self.defaults = variables.copy() | 
| 78 | 79 | 
| 79 # make a dictionary of the variables | 80 # make a dictionary of the variables for lookup convenience | 
| 80 self.vardict = {} | 81 self.vardict = {} | 
| 81 for i in self.vars: | 82 for i in self.vars: | 
| 82 self.vardict[i.name] = i | 83 self.vardict[i.name] = i | 
| 83 | 84 | 
| 84 # ensure all of these templates exist | 85 # ensure all of these templates exist | 
