def get_templates(): c_path = get_user_config().get('cookiecutters_dir') template_list = listdir(c_path) resutl = [] for template in template_list: if "cookiecutter.json" in listdir(path.join(c_path,template)): resutl.append(template) return sorted(resutl)
def create(self, template, verbose, overwrite, **config): if verbose: log.configure_logger('DEBUG') if not self.logger.handlers: self.logger.addHandler(logging.StreamHandler()) self.logger.setLevel(logging.DEBUG) with tempfile.NamedTemporaryFile() as cc_yaml_config: cc_config = self.read_user_config() cc_yaml_config.write( yaml.dump(cc_config, default_style='"', default_flow_style=False).encode('utf-8')) cc_yaml_config.flush() cc_yaml_config_name = cc_yaml_config.name if cc_config else None cc_config = main.get_user_config(config_file=cc_yaml_config_name) template = repository.expand_abbreviations( template, cc_config['abbreviations']) url = list(urlparse.urlsplit(template)) if url[0]: url[4], path = '', url[4] path = path.strip('/') template = urlparse.urlunsplit(url) else: path = None if (os.sep not in template) and not os.path.exists(template): template = find_templates()[template] if template is not None: template = template.get_location() print('Generating project from `{}`\n'.format(template)) try: main.cookiecutter(template, overwrite_if_exists=overwrite, config_file=cc_yaml_config_name, **config) except exceptions.RepositoryNotFound as e: if not path: raise repo_dir = e.args[0].splitlines()[-1] template = os.path.basename(repo_dir) main.cookiecutter(os.path.join(template, path), overwrite_if_exists=overwrite, config_file=cc_yaml_config_name, **config) return 0
def list(self, template, **config): print('Available abbreviations:') user_config = self.read_user_config() default_config = main.get_user_config(default_config=True) abbreviations = dict(default_config['abbreviations'], **user_config['abbreviations']) padding = len(max(abbreviations, key=len)) for abbr, url in sorted(abbreviations.items()): print(' - {}: {}'.format(abbr.ljust(padding), url)) print('') print('Available templates:') templates = find_templates() if not templates: print(' <No registered templates>') else: default = templates.get('default') if default is not None: del templates['default'] if template and (template in templates): templates = {template: templates[template]} padding = len(max(templates, key=len)) for name in sorted(templates): print(' - {}: {}'.format(name.ljust(padding), templates[name].DESC)) if default is not None: print('') print(' * default: ' + default.DESC) return 0
"{}.json".format(repo.active_branch.commit.hexsha)) code = api.test_model(model, filename, pytest_args=pytest_args, skip=skip, exclusive=exclusive, custom=custom) else: code = api.test_model(model, pytest_args=pytest_args, skip=skip, exclusive=exclusive, custom=custom) sys.exit(code) @cli.command(context_settings=CONTEXT_SETTINGS) @click.help_option("--help", "-h") @click.option("--replay", is_flag=True, help="Create a memote repository using the exact same answers " "as before. This will not overwrite existing directories. If " "you want to adjust the answers, edit the template " "'{}'.".format(join(get_user_config()["replay_dir"], "cookiecutter-memote.json"))) @click.option("--directory", type=click.Path(exists=True, file_okay=False, writable=True), envvar="MEMOTE_DIRECTORY", help="Create a new model repository in the given directory.") def new(directory, replay): """ Create a suitable model repository structure from a template. By using a cookiecutter template, memote will ask you a couple of questions and set up a new directory structure that will make your life easier. The new directory will be placed in the current directory or respect the given --directory option. """ if directory is None:
"chore: add result for {}".format(previous_cmt.hexsha)) if is_branch: previous.checkout() else: repo.commit(previous_cmt) @cli.command(context_settings=CONTEXT_SETTINGS) @click.help_option("--help", "-h") @click.option("--replay", is_flag=True, help="Create a memote repository using the exact same answers " "as before. This will not overwrite existing directories. If " "you want to adjust the answers, edit the template " "'{}'.".format( join(get_user_config()["replay_dir"], "cookiecutter-memote.json"))) @click.option("--directory", type=click.Path(exists=True, file_okay=False, writable=True), help="Create a new model repository in the given directory.") def new(directory, replay): """ Create a suitable model repository structure from a template. By using a cookiecutter template, memote will ask you a couple of questions and set up a new directory structure that will make your life easier. The new directory will be placed in the current directory or respect the given --directory option. """ callbacks.git_installed()
def Command(path=None, template=None, flavor=None, prompt=False, author=None, license_years=None, module_version=None, website=None): """Initialise a module by populating a directory Will populate specified path (or current path if not specified) with OpenERP/Odoo modules files and directory structure. Usage: %(std_usage)s %(surcmd)s [PATH] [--template=TEMPLATE] [--flavor=FLAVOR] [--prompt|-p] [--author=AUTHOREMAIL] [--license-years=YEARS] [--module-version VERSION] [--website WEBSITE] Options: %(std_options)s PATH If not specified, equivalent to "." --template TEMPLATE Advanced cookiecutter template. --flavor FLAVOR Target template version (ie: 8.0, 7.0) (default: master) --prompt, -p Prompt for all values, except those provided on the command line. And values from config files. --author AUTHOREMAIL Author name and email. Default taken in config. (ie: 'Robert Dubois <*****@*****.**>') --license-years YEARS License applicable years. (ie: 2010-2012, 2013) (defaults to current year) --module-version VERSION Starting version number --website WEBSITE Website of the module. """ cfg = kids.cfg.load() path = os.getcwd() if path is None else os.path.abspath(path) root = common.find_root(path) if root: msg.die("Module %r already initialized." % root) name = os.path.basename(path) output_dir = os.path.dirname(path) if not os.path.isdir(output_dir): msg.die("Destination directory %r doesn't exists." % (output_dir, )) if template is None: template = mdict(cfg).get("init.template", DEFAULT_TEMPLATE) ## Command line provided values cli_values = {"name": name} default_values = {} dct = default_values if author is None else cli_values if author is None: author = mdict(cfg).get("author") if author is None and not os.environ.get("NO_GIT_CONFIG", ""): author = get_git_author(path) if author is None: msg.die( "No author found on command line nor in config files.\n" "Please provide an author with '--author=', for instance:\n\n" " oem init --author='Robert Dubois <*****@*****.**>'" "\n\nor set a default author in your config file before " "running this command:\n\n" " oem config set author 'Robert Dubois <*****@*****.**>'" "\n\nor set a default author in your git config like this:" "\n\n" " git config --global user.name 'Robert Dubois'\n" " git config --global user.email '*****@*****.**'\n") match = AUTHOR_REGEX.search(author) if not match: msg.die("Your value %r for 'author' doesn't match specs.\n" "You should try to match this example:\n\n" " Robert Dubois <*****@*****.**>" % (author, )) match = match.groupdict() dct["author"] = match["name"].strip() dct["email"] = match["email"] if license_years is None: license_years = sact.epoch.Time.now().strftime('%Y') default_values["license_years"] = license_years else: cli_values["license_years"] = license_years if module_version is None: module_version = '0.1' default_values["version"] = module_version else: cli_values["version"] = module_version if website is not None: cli_values["website"] = website ## A big part of the following code comes directly from ## cookiecutter, and I would be glad that some of the ## functionality I implemented would come in a way or another ## in cookiecutter itslef. # Get user config from ~/.cookiecutterrc or equivalent # If no config file, sensible defaults from config.DEFAULT_CONFIG are used config_dict = cc.get_user_config() template = cc.expand_abbreviations(template, config_dict) # TODO: find a better way to tell if it's a repo URL if 'git@' in template or 'https://' in template: repo_dir = cc.clone(repo_url=template, checkout=flavor, clone_to_dir=config_dict['cookiecutters_dir'], no_input=True) else: # If it's a local repo, no need to clone or copy to your # cookiecutters_dir repo_dir = template context_file = cc.find_cfg_file(repo_dir) default_context = config_dict.get('default_context', {}) if default_values: default_context.update(default_values) context = cc.generate_context( context_file=context_file, default_context=default_context, extra_context=config_dict, ) context = cc.prompt_for_config(context, no_input=False, values=cli_values, only_missing=not prompt, with_optional=prompt) ## XXXvlab: missing no-overwrite mode # Create project from local context and project template. if not os.environ.get("OEM_DRY_RUN", ""): cc.generate_files(repo_dir=repo_dir, context=context, output_dir=output_dir)
['git', 'commit', '-m', "chore: add result for {}".format(previous_cmt.hexsha)] ) if is_branch: previous.checkout() else: repo.commit(previous_cmt) @cli.command(context_settings=CONTEXT_SETTINGS) @click.help_option("--help", "-h") @click.option("--replay", is_flag=True, help="Create a memote repository using the exact same answers " "as before. This will not overwrite existing directories. If " "you want to adjust the answers, edit the template " "'{}'.".format(join(get_user_config()["replay_dir"], "cookiecutter-memote.json"))) @click.option("--directory", type=click.Path(exists=True, file_okay=False, writable=True), help="Create a new model repository in the given directory.") def new(directory, replay): """ Create a suitable model repository structure from a template. By using a cookiecutter template, memote will ask you a couple of questions and set up a new directory structure that will make your life easier. The new directory will be placed in the current directory or respect the given --directory option. """ callbacks.git_installed()