in src/aaz_dev/cli/controller/az_module_manager.py [0:0]
def create_new_mod(self, mod_name):
mod_path = self.get_mod_path(mod_name)
templates = get_templates()['main']
new_files = {}
# render __init__.py
file_path = os.path.join(mod_path, '__init__.py')
if os.path.exists(file_path):
raise exceptions.ResourceConflict(f"File already exist: '{file_path}'")
tmpl = templates['__init__.py']
new_files[file_path] = tmpl.render(
mod_name=mod_name
)
# render _help.py
file_path = os.path.join(mod_path, '_help.py')
if os.path.exists(file_path):
raise exceptions.ResourceConflict(f"File already exist: '{file_path}'")
tmpl = templates['_help.py']
new_files[file_path] = tmpl.render()
# render _params.py
file_path = os.path.join(mod_path, '_params.py')
if os.path.exists(file_path):
raise exceptions.ResourceConflict(f"File already exist: '{file_path}'")
tmpl = templates['_params.py']
new_files[file_path] = tmpl.render()
# render commands.py
file_path = os.path.join(mod_path, 'commands.py')
if os.path.exists(file_path):
raise exceptions.ResourceConflict(f"File already exist: '{file_path}'")
tmpl = templates['commands.py']
new_files[file_path] = tmpl.render()
# render custom.py
file_path = os.path.join(mod_path, 'custom.py')
if os.path.exists(file_path):
raise exceptions.ResourceConflict(f"File already exist: '{file_path}'")
tmpl = templates['custom.py']
new_files[file_path] = tmpl.render()
# test_folder
t_path = os.path.join(mod_path, 'tests')
t_templates = templates['tests']
# render __init__.py
file_path = os.path.join(t_path, '__init__.py')
if os.path.exists(file_path):
raise exceptions.ResourceConflict(f"File already exist: '{file_path}'")
tmpl = t_templates['__init__.py']
new_files[file_path] = tmpl.render()
profile = Config.CLI_DEFAULT_PROFILE
tp_path = os.path.join(t_path, profile)
tp_templates = t_templates['profile']
# render __init__.py
file_path = os.path.join(tp_path, '__init__.py')
if os.path.exists(file_path):
raise exceptions.ResourceConflict(f"File already exist: '{file_path}'")
tmpl = tp_templates['__init__.py']
new_files[file_path] = tmpl.render()
# render test_*.py
file_path = os.path.join(tp_path, f'test_{self.pkg_name(mod_name)}.py')
if os.path.exists(file_path):
raise exceptions.ResourceConflict(f"File already exist: '{file_path}'")
tmpl = tp_templates['test_.py']
new_files[file_path] = tmpl.render(name=mod_name)
# written files
for path, data in new_files.items():
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, 'w', encoding="utf-8") as f:
f.write(data)
module = CLIModule()
module.name = mod_name
module.folder = self.get_mod_path(mod_name)
module.profiles = {}
for profile_name in Config.CLI_PROFILES:
module.profiles[profile_name] = self._load_view_profile(profile_name, self.get_aaz_path(mod_name))
return module