def handle_label(self, app_name, directory=None, **options): if directory is None: directory = os.getcwd() #app_name =label app_template = options.get('app_template') or os.path.join(dj_scaffold.__path__[0], 'conf', 'app') app_dir = os.path.join(options.get('parent_path') or directory, app_name) if not os.path.exists(app_template): raise CommandError("The template path, %r, does not exist." % app_template) # Determine the project_name by using the basename of directory, # which should be the full path of the project directory (or the # current directory if no directory was passed). project_name = os.path.basename(directory) if app_name == project_name: raise CommandError("You cannot create an app with the same name" " (%r) as your project." % app_name) # Check that the app_name cannot be imported. try: import_module(app_name) except ImportError: pass else: raise CommandError("%r conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name." % app_name) # Get any boilerplate replacement variables: replace = {} utils.copy_template(app_template, app_dir, replace)
def handle_label(self, app_name, directory=None, **options): if directory is None: directory = os.getcwd() #app_name =label app_template = options.get('app_template') or os.path.join( dj_scaffold.__path__[0], 'conf', 'app') app_dir = os.path.join( options.get('parent_path') or directory, app_name) if not os.path.exists(app_template): raise CommandError("The template path, %r, does not exist." % app_template) # Determine the project_name by using the basename of directory, # which should be the full path of the project directory (or the # current directory if no directory was passed). project_name = os.path.basename(directory) if app_name == project_name: raise CommandError("You cannot create an app with the same name" " (%r) as your project." % app_name) # Check that the app_name cannot be imported. try: import_module(app_name) except ImportError: pass else: raise CommandError( "%r conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name." % app_name) # Get any boilerplate replacement variables: replace = {} utils.copy_template(app_template, app_dir, replace)
def start_project(): """ Copy a project template, replacing boilerplate variables. """ usage = "usage: %prog [options] project_name [base_destination_dir]" parser = optparse.OptionParser(usage=usage) parser.add_option('-t', '--template-dir', dest='src_dir', help='project template directory to use', default=TEMPLATE_DIR) options, args = parser.parse_args() if len(args) not in (1, 2): parser.print_help() sys.exit(1) project_name = args[0] src = options.src_dir if len(args) > 1: base_dest_dir = args[1] else: base_dest_dir = '' dest = os.path.join(base_dest_dir, project_name) # Get any boilerplate replacement variables: replace = {} for var, help, default in utils.get_boilerplate(src, project_name): help = help or var if default is not None: prompt = '%s [%s]: ' % (help, default) else: prompt = '%s: ' % help value = None while not value: value = raw_input(prompt) or default replace[var] = value utils.copy_template(src, dest, replace)