Bugfixes
This commit is contained in:
25
src/cpl_cli/source_creator/__init__.py
Normal file
25
src/cpl_cli/source_creator/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli.source_creator'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.0rc2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='0rc2')
|
71
src/cpl_cli/source_creator/console_builder.py
Normal file
71
src/cpl_cli/source_creator/console_builder.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import json
|
||||
import os
|
||||
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl.console.console import Console
|
||||
from cpl_cli.source_creator.template_builder import TemplateBuilder
|
||||
from cpl_cli.templates.new.console.appsettings_json import AppsettingsTemplate
|
||||
from cpl_cli.templates.new.console.license import LicenseTemplate
|
||||
from cpl_cli.templates.new.console.readme_py import ReadmeTemplate
|
||||
from cpl_cli.templates.new.console.src.application import ApplicationTemplate
|
||||
from cpl_cli.templates.new.console.src.main import MainWithApplicationHostAndStartupTemplate, \
|
||||
MainWithoutApplicationBaseTemplate, MainWithApplicationBaseTemplate, MainWithDependencyInjection
|
||||
from cpl_cli.templates.new.console.src.startup import StartupTemplate
|
||||
from cpl_cli.templates.new.console.src.tests.init import TestsInitTemplate
|
||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class ConsoleBuilder:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def build(project_path: str, use_application_api: bool, use_startup: bool, use_service_providing: bool,
|
||||
project_name: str, project_settings: dict):
|
||||
"""
|
||||
Builds the console project files
|
||||
:param project_path:
|
||||
:param use_application_api:
|
||||
:param use_startup:
|
||||
:param use_service_providing:
|
||||
:param project_name:
|
||||
:param project_settings:
|
||||
:return:
|
||||
"""
|
||||
if not os.path.isdir(project_path):
|
||||
os.makedirs(project_path)
|
||||
|
||||
with open(os.path.join(project_path, 'cpl.json'), 'w') as project_json:
|
||||
project_json.write(json.dumps(project_settings, indent=2))
|
||||
project_json.close()
|
||||
|
||||
templates: list[TemplateFileABC] = [
|
||||
LicenseTemplate(),
|
||||
ReadmeTemplate(),
|
||||
TestsInitTemplate(),
|
||||
AppsettingsTemplate()
|
||||
]
|
||||
|
||||
if use_application_api:
|
||||
templates.append(ApplicationTemplate())
|
||||
|
||||
if use_startup:
|
||||
templates.append(StartupTemplate())
|
||||
templates.append(MainWithApplicationHostAndStartupTemplate())
|
||||
else:
|
||||
templates.append(MainWithApplicationBaseTemplate())
|
||||
else:
|
||||
if use_service_providing:
|
||||
templates.append(MainWithDependencyInjection())
|
||||
else:
|
||||
templates.append(MainWithoutApplicationBaseTemplate())
|
||||
|
||||
for template in templates:
|
||||
Console.spinner(
|
||||
f'Creating {project_name}/{template.path}{template.name}',
|
||||
TemplateBuilder.build,
|
||||
project_path,
|
||||
template,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
73
src/cpl_cli/source_creator/library_builder.py
Normal file
73
src/cpl_cli/source_creator/library_builder.py
Normal file
@@ -0,0 +1,73 @@
|
||||
import json
|
||||
import os
|
||||
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl.console.console import Console
|
||||
from cpl_cli.source_creator.template_builder import TemplateBuilder
|
||||
from cpl_cli.templates.new.library.appsettings_json import AppsettingsTemplate
|
||||
from cpl_cli.templates.new.library.license import LicenseTemplate
|
||||
from cpl_cli.templates.new.library.readme_py import ReadmeTemplate
|
||||
from cpl_cli.templates.new.library.src.cli.application import ApplicationTemplate
|
||||
from cpl_cli.templates.new.library.src.cli.init import CLIInitTemplate
|
||||
from cpl_cli.templates.new.library.src.cli.main import MainWithApplicationHostAndStartupTemplate, \
|
||||
MainWithoutApplicationBaseTemplate, MainWithApplicationBaseTemplate, MainWithDependencyInjection
|
||||
from cpl_cli.templates.new.library.src.cli.startup import StartupTemplate
|
||||
from cpl_cli.templates.new.library.src.tests.init import TestsInitTemplate
|
||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class LibraryBuilder:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def build(project_path: str, use_application_api: bool, use_startup: bool, use_service_providing: bool,
|
||||
project_name: str, project_settings: dict):
|
||||
"""
|
||||
Builds the library project files
|
||||
:param project_path:
|
||||
:param use_application_api:
|
||||
:param use_startup:
|
||||
:param use_service_providing:
|
||||
:param project_name:
|
||||
:param project_settings:
|
||||
:return:
|
||||
"""
|
||||
if not os.path.isdir(project_path):
|
||||
os.makedirs(project_path)
|
||||
|
||||
with open(os.path.join(project_path, 'cpl.json'), 'w') as project_json:
|
||||
project_json.write(json.dumps(project_settings, indent=2))
|
||||
project_json.close()
|
||||
|
||||
templates: list[TemplateFileABC] = [
|
||||
LicenseTemplate(),
|
||||
ReadmeTemplate(),
|
||||
TestsInitTemplate(),
|
||||
CLIInitTemplate(project_name),
|
||||
AppsettingsTemplate()
|
||||
]
|
||||
|
||||
if use_application_api:
|
||||
templates.append(ApplicationTemplate(project_name))
|
||||
|
||||
if use_startup:
|
||||
templates.append(StartupTemplate(project_name))
|
||||
templates.append(MainWithApplicationHostAndStartupTemplate(project_name))
|
||||
else:
|
||||
templates.append(MainWithApplicationBaseTemplate())
|
||||
else:
|
||||
if use_service_providing:
|
||||
templates.append(MainWithDependencyInjection())
|
||||
else:
|
||||
templates.append(MainWithoutApplicationBaseTemplate())
|
||||
|
||||
for template in templates:
|
||||
Console.spinner(
|
||||
f'Creating {project_name}/{template.path}{template.name}',
|
||||
TemplateBuilder.build,
|
||||
project_path,
|
||||
template,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
24
src/cpl_cli/source_creator/template_builder.py
Normal file
24
src/cpl_cli/source_creator/template_builder.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class TemplateBuilder:
|
||||
|
||||
@staticmethod
|
||||
def build(project_path: str, template: TemplateFileABC):
|
||||
"""
|
||||
Creates template
|
||||
:param project_path:
|
||||
:param template:
|
||||
:return:
|
||||
"""
|
||||
file_path = os.path.join(project_path, template.path, template.name)
|
||||
file_rel_path = os.path.join(project_path, template.path)
|
||||
|
||||
if not os.path.isdir(file_rel_path):
|
||||
os.makedirs(file_rel_path)
|
||||
|
||||
with open(file_path, 'w') as license_file:
|
||||
license_file.write(template.value)
|
||||
license_file.close()
|
Reference in New Issue
Block a user