def quickly(project_template, project_dir, command_args, shell_completion=False): """Create a new quickly template from an existing one""" # We have nothing for this if shell_completion: return("") project_template = command_args[0] if len(command_args) < 2: cmd = commands_module.get_command('quickly', project_template) templatetools.usage_error(_("No destination template name provided."), cmd=cmd, template=project_template) destination_path = os.path.expanduser("~/quickly-templates/") # create ~/quickly-templates/ if needed if not os.path.exists(destination_path): os.makedirs(destination_path) template_destination_path = destination_path + command_args[1] if os.path.exists(template_destination_path): print _("%s already exists." % template_destination_path) return 1 if not os.path.exists(template_destination_path): print _("Copy %s to create new %s template") % (project_template, template_destination_path) try: template_source_path = tools.get_template_directory(project_template) except tools.template_path_not_found, e: print(e) return 1
def pre_create(command_template, project_template, project_dir, command_args): """Create the project directory before create command call""" if len(command_args) < 1: cmd = commands_module.get_command('create', project_template) templatetools.usage_error(_("No project name specified."), cmd=cmd, template=project_template) path_and_project = command_args[0].split('/') project_name = path_and_project[-1] # if a path is not present, create it if len(path_and_project) > 1: path = str(os.path.sep).join(path_and_project[0:-1]) if not os.path.exists(path): os.makedirs(path) os.chdir(path) # check that project name follow quickly rules and reformat it. try: project_name = templatetools.quickly_name(project_name) except templatetools.bad_project_name, e: print(e) return(4)
def check_for_followed_by_args(cmd, command_args, project_template): if not cmd.followed_by_template and not cmd.followed_by_command: return command_args # nothing to check command = None if cmd.followed_by_template and cmd.followed_by_command: # If no arguments, there is something obviously wrong if len(command_args) == 0: if project_template: templatetools.usage_error(_("No command provided to %s command.") % cmd.name, cmd=cmd, template=project_template) else: templatetools.usage_error(_("No template or command provided to %s command.") % cmd.name, cmd=cmd) # At least one argument. What is it? First check if it's a command if we already have a template if project_template: command = commands.get_command(command_args[0], project_template) if command: command_args.insert(0, project_template) # use default template elif not command and not check_template_exists(command_args[0]): # Wasn't a command or a template name, but we are in the context of a template templatetools.usage_error(_("No %s command found in %s template.") % (command_args[0], project_template), cmd=cmd, template=project_template) if not command: # must be a template name then (or nonsense) if not check_template_exists(command_args[0]): command = commands.get_command(command_args[0]) # did user provid a valid builtin command? if command: command_args.insert(0, 'builtins') elif len(command_args) == 1: templatetools.usage_error(_("%s is neither a template nor a standard command.") % (command_args[0]), cmd=cmd) else: templatetools.usage_error(_("Template %s does not exist.") % (command_args[0]), cmd=cmd, show_templates_for=None) project_template = command_args[0] # OK, we have a template! if len(command_args) < 2: templatetools.usage_error(_("No command provided to %s command.") % cmd.name, cmd=cmd, template=project_template) command = commands.get_command(command_args[1], project_template) if not command: templatetools.usage_error(_("No %s command found in %s template.") % (command_args[1], project_template), cmd=cmd, template=project_template) elif cmd.followed_by_template: if len(command_args) > 0: if check_template_exists(command_args[0]): project_template = command_args[0] if not project_template: templatetools.usage_error(_("No template provided to %s command.") % cmd.name, cmd=cmd) elif cmd.followed_by_command: if len(command_args) > 0: command = commands.get_command(command_args[0], project_template) if not command: templatetools.usage_error(_("No %s command found.") % command_args[0], cmd=cmd, template=project_template) if not command: templatetools.usage_error(_("No command provided to %s command.") % cmd.name, cmd=cmd, template=project_template) return command_args
def check_for_followed_by_args(cmd, command_args, project_template): if not cmd.followed_by_template and not cmd.followed_by_command: return command_args # nothing to check command = None if cmd.followed_by_template and cmd.followed_by_command: # If no arguments, there is something obviously wrong if len(command_args) == 0: if project_template: templatetools.usage_error( _("No command provided to %s command.") % cmd.name, cmd=cmd, template=project_template) else: templatetools.usage_error( _("No template or command provided to %s command.") % cmd.name, cmd=cmd) # At least one argument. What is it? First check if it's a command if we already have a template if project_template: command = commands.get_command(command_args[0], project_template) if command: command_args.insert(0, project_template) # use default template elif not command and not check_template_exists(command_args[0]): # Wasn't a command or a template name, but we are in the context of a template templatetools.usage_error( _("No %s command found in %s template.") % (command_args[0], project_template), cmd=cmd, template=project_template) if not command: # must be a template name then (or nonsense) if not check_template_exists(command_args[0]): command = commands.get_command( command_args[0] ) # did user provid a valid builtin command? if command: command_args.insert(0, 'builtins') elif len(command_args) == 1: templatetools.usage_error( _("%s is neither a template nor a standard command.") % (command_args[0]), cmd=cmd) else: templatetools.usage_error( _("Template %s does not exist.") % (command_args[0]), cmd=cmd, show_templates_for=None) project_template = command_args[0] # OK, we have a template! if len(command_args) < 2: templatetools.usage_error( _("No command provided to %s command.") % cmd.name, cmd=cmd, template=project_template) command = commands.get_command(command_args[1], project_template) if not command: templatetools.usage_error( _("No %s command found in %s template.") % (command_args[1], project_template), cmd=cmd, template=project_template) elif cmd.followed_by_template: if len(command_args) > 0: if check_template_exists(command_args[0]): project_template = command_args[0] if not project_template: templatetools.usage_error( _("No template provided to %s command.") % cmd.name, cmd=cmd) elif cmd.followed_by_command: if len(command_args) > 0: command = commands.get_command(command_args[0], project_template) if not command: templatetools.usage_error(_("No %s command found.") % command_args[0], cmd=cmd, template=project_template) if not command: templatetools.usage_error(_("No command provided to %s command.") % cmd.name, cmd=cmd, template=project_template) return command_args