# HG changeset patch # User Jeff Hammel # Date 1294778588 28800 # Node ID fbd4a34d8e42928d187dcaa98140f377c02d4ec2 # Parent e8dabfd24c42f9d00c2baf4e528c5167be9c3fb0 make project creation template work diff -r e8dabfd24c42 -r fbd4a34d8e42 autobot/template.py --- 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 ' 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()