Mercurial > hg > autobot
changeset 68:fbd4a34d8e42
make project creation template work
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 11 Jan 2011 12:43:08 -0800 |
parents | e8dabfd24c42 |
children | 849bbc2e5572 |
files | autobot/template.py |
diffstat | 1 files changed, 39 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/autobot/template.py Tue Jan 11 10:55:52 2011 -0800 +++ b/autobot/template.py Tue Jan 11 12:43:08 2011 -0800 @@ -5,6 +5,7 @@ """ import os +import string import sys from makeitso.cli import MakeItSoCLI from makeitso.template import assemble @@ -105,8 +106,7 @@ """ name = 'autobot-project' templates = [os.path.join('projects', 'project.template')] - vars = [Variable('project', 'name of the project'), - Variable('description'), + vars = [Variable('description'), Variable('repo', 'repository location of the project')] # CLI front end class @@ -140,17 +140,48 @@ # call the parent return MakeItSoCLI.parse(self, args, parser, options) + class ProjectTemplateCLI(MakeItSoCLI): + """CLI front end for project template""" + def __init__(self): + self.usage = '%prog [options] project <output>' MakeItSoCLI.__init__(self, ProjectTemplate) + def parse(self, args=None, parser=None, options=None): - if not args: - # deploy to the correct place + + # parse the arguments + parser = self.parser() + options, args = parser.parse_args(args=args) + + if not(args): + parser.print_usage() + parser.exit() + + # deploy to the correct place + if len(args) not in (1,2): + parser.error("Please provide a single project") + project = args[0].lower() + + # ensure the argument is a python path + assert set(project).issubset(string.letters) + + # get the variables + variables = self.get_variables(options) + variables['project'] = project + + # get the output or use the location in the source + if len(args) == 2: + output = args[1] + else: here = os.path.dirname(os.path.abspath(__file__)) - args = [os.path.join(here, 'projects')] - print args[0] - + projectdir = os.path.join(here, 'projects', project) + if os.path.exists(projectdir): + assert os.path.isdir(projectdir) + output = os.path.join(projectdir, '__init__.py') + assert not os.path.exists(output), "Project '%s' already exists" % project + return variables, output ### console_script front-ends @@ -168,6 +199,7 @@ def create_project(args=sys.argv[1:]): cli = ProjectTemplateCLI() + cli(*args) if __name__ == '__main__': create_master()