Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
params = {
"template": location if location else Init._runtime_path(runtime),
"output_dir": output_dir,
"no_input": no_input,
}
Operation("Template: %s" % params["template"]).process()
Operation("Output-Dir: %s" % params["output_dir"]).process()
if name is not None:
params["no_input"] = True
params['extra_context'] = {'project_name': name, 'runtime': runtime, 'namespace': namespace, 'type': type}
Operation("Project-Name: %s" % params['extra_context']["project_name"]).process()
Operation("Type: %s" % params['extra_context']["type"]).process()
Operation("Runtime: %s" % params['extra_context']["runtime"]).process()
try:
cookiecutter(**params)
except exceptions.CookiecutterException as e:
Operation(e, err_msg=traceback.format_exc(), level="ERROR").no_output()
# raise click.Abort()
raise InitException(e)
if runtime in infor.SERVICE_RUNTIME:
Operation("[*] Project initing,please wait.....", fg="green").echo()
zipfile_path = os.path.join(os.path.abspath(output_dir), name, 'node_modules.zip')
zipobj = zipfile.ZipFile(zipfile_path, mode="r")
zipobj.extractall(os.path.join(os.path.abspath(output_dir), name))
zipobj.close()
os.remove(zipfile_path)
Operation("[*] Project initialization is complete", fg="green").echo()
Operation(
"You could 'cd %s', and start this project." % (params['extra_context']["project_name"])).information()
LOG.debug("%s", params)
try:
LOG.debug("Baking a new template with cookiecutter with all parameters")
cookiecutter(**params)
except RepositoryNotFound as e:
# cookiecutter.json is not found in the template. Let's just clone it directly without using cookiecutter
# and call it done.
LOG.debug(
"Unable to find cookiecutter.json in the project. Downloading it directly without treating "
"it as a cookiecutter template"
)
project_output_dir = str(Path(output_dir, name)) if name else output_dir
generate_non_cookiecutter_project(location=params["template"], output_dir=project_output_dir)
except CookiecutterException as e:
raise GenerateProjectFailedError(project=name, provider_error=e)
Raised during cleanup when remove_repo() can't find a generated project
directory inside of a repo.
"""
# unused locally
class ConfigDoesNotExistException(CookiecutterException):
"""
Exception for missing config file.
Raised when get_config() is passed a path to a config file, but no file
is found at that path.
"""
class InvalidConfiguration(CookiecutterException):
"""
Exception for invalid configuration file.
Raised if the global configuration file is not valid YAML or is
badly constructed.
"""
class UnknownRepoType(CookiecutterException):
"""
Exception for unknown repo types.
Raised if a repo's type cannot be determined.
"""
The name of the input directory should always contain a string that is
rendered to something else, so that input_dir != output_dir.
"""
class UnknownTemplateDirException(CookiecutterException):
"""
Exception for ambiguous project template directory.
Raised when Cookiecutter cannot determine which directory is the project
template, e.g. more than one dir appears to be a template dir.
"""
# unused locally
class MissingProjectDir(CookiecutterException):
"""
Exception for missing generated project directory.
Raised during cleanup when remove_repo() can't find a generated project
directory inside of a repo.
"""
# unused locally
class ConfigDoesNotExistException(CookiecutterException):
"""
Exception for missing config file.
Raised when get_config() is passed a path to a config file, but no file
is found at that path.
"""
params = {
"template": location if location else Init._runtime_path(runtime),
"output_dir": output_dir,
"no_input": no_input,
}
click.secho("Template: %s" % params["template"])
click.secho("Output-Dir: %s" % params["output_dir"])
if not location and name is not None:
params["no_input"] = True
params['extra_context'] = {'project_name': name, 'runtime': runtime, 'namespace': namespace}
click.secho("Project-Name: %s" % params['extra_context']["project_name"])
click.secho("Runtime: %s" % params['extra_context']["runtime"])
try:
cookiecutter(**params)
except exceptions.CookiecutterException as e:
click.secho(str(e), fg="red")
raise click.Abort()
click.secho("[*] Project initialization is complete", fg="green")
Exception for existing output directory.
Raised when the output directory of the project exists already.
"""
class InvalidModeException(CookiecutterException):
"""
Exception for incompatible modes.
Raised when cookiecutter is called with both `no_input==True` and
`replay==True` at the same time.
"""
class FailedHookException(CookiecutterException):
"""
Exception for hook failures.
Raised when a hook script fails.
"""
class UndefinedVariableInTemplate(CookiecutterException):
"""
Exception for out-of-scope variables.
Raised when a template uses a variable which is not defined in the
context.
"""
def __init__(self, message, error, context):
template, e.g. more than one dir appears to be a template dir.
"""
# unused locally
class MissingProjectDir(CookiecutterException):
"""
Exception for missing generated project directory.
Raised during cleanup when remove_repo() can't find a generated project
directory inside of a repo.
"""
# unused locally
class ConfigDoesNotExistException(CookiecutterException):
"""
Exception for missing config file.
Raised when get_config() is passed a path to a config file, but no file
is found at that path.
"""
class InvalidConfiguration(CookiecutterException):
"""
Exception for invalid configuration file.
Raised if the global configuration file is not valid YAML or is
badly constructed.
"""
Exception for invalid configuration file.
Raised if the global configuration file is not valid YAML or is
badly constructed.
"""
class UnknownRepoType(CookiecutterException):
"""
Exception for unknown repo types.
Raised if a repo's type cannot be determined.
"""
class VCSNotInstalled(CookiecutterException):
"""
Exception when version control is unavailable.
Raised if the version control system (git or hg) is not installed.
"""
class ContextDecodingException(CookiecutterException):
"""
Exception for failed JSON decoding.
Raised when a project's JSON context file can not be decoded.
"""
class OutputDirExistsException(CookiecutterException):
"""
Exception when version control is unavailable.
Raised if the version control system (git or hg) is not installed.
"""
class ContextDecodingException(CookiecutterException):
"""
Exception for failed JSON decoding.
Raised when a project's JSON context file can not be decoded.
"""
class OutputDirExistsException(CookiecutterException):
"""
Exception for existing output directory.
Raised when the output directory of the project exists already.
"""
class InvalidModeException(CookiecutterException):
"""
Exception for incompatible modes.
Raised when cookiecutter is called with both `no_input==True` and
`replay==True` at the same time.
"""
return (
"{self.message}. "
"Error message: {self.error.message}. "
"Context: {self.context}"
).format(**locals())
class UnknownExtension(CookiecutterException):
"""
Exception for un-importable extention.
Raised when an environment is unable to import a required extension.
"""
class RepositoryNotFound(CookiecutterException):
"""
Exception for missing repo.
Raised when the specified cookiecutter repository doesn't exist.
"""
class RepositoryCloneFailed(CookiecutterException):
"""
Exception for un-cloneable repo.
Raised when a cookiecutter template can't be cloned.
"""
class InvalidZipRepository(CookiecutterException):