2021.4.1 #11
4
cpl.json
4
cpl.json
@ -31,9 +31,7 @@
|
|||||||
"Main": "cpl_cli.main",
|
"Main": "cpl_cli.main",
|
||||||
"EntryPoint": "cpl",
|
"EntryPoint": "cpl",
|
||||||
"IncludePackageData": "False",
|
"IncludePackageData": "False",
|
||||||
"Included": [
|
"Included": [],
|
||||||
"src/cpl_cli/templates/new/console/src/tests/"
|
|
||||||
],
|
|
||||||
"Excluded": [
|
"Excluded": [
|
||||||
"*/__pycache__",
|
"*/__pycache__",
|
||||||
"*/logs",
|
"*/logs",
|
||||||
|
@ -92,7 +92,7 @@ class Logger(LoggerABC):
|
|||||||
if self._level.value >= LoggingLevel.TRACE.value:
|
if self._level.value >= LoggingLevel.TRACE.value:
|
||||||
self._append_log(output)
|
self._append_log(output)
|
||||||
|
|
||||||
# check if message can be shown in console
|
# check if message can be shown in console_old
|
||||||
if self._console.value >= LoggingLevel.TRACE.value:
|
if self._console.value >= LoggingLevel.TRACE.value:
|
||||||
Console.set_foreground_color(ForegroundColor.green)
|
Console.set_foreground_color(ForegroundColor.green)
|
||||||
Console.write_line(output)
|
Console.write_line(output)
|
||||||
@ -105,7 +105,7 @@ class Logger(LoggerABC):
|
|||||||
if self._level.value >= LoggingLevel.DEBUG.value:
|
if self._level.value >= LoggingLevel.DEBUG.value:
|
||||||
self._append_log(output)
|
self._append_log(output)
|
||||||
|
|
||||||
# check if message can be shown in console
|
# check if message can be shown in console_old
|
||||||
if self._console.value >= LoggingLevel.DEBUG.value:
|
if self._console.value >= LoggingLevel.DEBUG.value:
|
||||||
Console.set_foreground_color(ForegroundColor.green)
|
Console.set_foreground_color(ForegroundColor.green)
|
||||||
Console.write_line(output)
|
Console.write_line(output)
|
||||||
@ -118,7 +118,7 @@ class Logger(LoggerABC):
|
|||||||
if self._level.value >= LoggingLevel.INFO.value:
|
if self._level.value >= LoggingLevel.INFO.value:
|
||||||
self._append_log(output)
|
self._append_log(output)
|
||||||
|
|
||||||
# check if message can be shown in console
|
# check if message can be shown in console_old
|
||||||
if self._console.value >= LoggingLevel.INFO.value:
|
if self._console.value >= LoggingLevel.INFO.value:
|
||||||
Console.set_foreground_color(ForegroundColor.green)
|
Console.set_foreground_color(ForegroundColor.green)
|
||||||
Console.write_line(output)
|
Console.write_line(output)
|
||||||
@ -131,7 +131,7 @@ class Logger(LoggerABC):
|
|||||||
if self._level.value >= LoggingLevel.WARN.value:
|
if self._level.value >= LoggingLevel.WARN.value:
|
||||||
self._append_log(output)
|
self._append_log(output)
|
||||||
|
|
||||||
# check if message can be shown in console
|
# check if message can be shown in console_old
|
||||||
if self._console.value >= LoggingLevel.WARN.value:
|
if self._console.value >= LoggingLevel.WARN.value:
|
||||||
Console.set_foreground_color(ForegroundColor.yellow)
|
Console.set_foreground_color(ForegroundColor.yellow)
|
||||||
Console.write_line(output)
|
Console.write_line(output)
|
||||||
@ -150,7 +150,7 @@ class Logger(LoggerABC):
|
|||||||
if self._level.value >= LoggingLevel.ERROR.value:
|
if self._level.value >= LoggingLevel.ERROR.value:
|
||||||
self._append_log(output)
|
self._append_log(output)
|
||||||
|
|
||||||
# check if message can be shown in console
|
# check if message can be shown in console_old
|
||||||
if self._console.value >= LoggingLevel.ERROR.value:
|
if self._console.value >= LoggingLevel.ERROR.value:
|
||||||
Console.set_foreground_color(ForegroundColor.red)
|
Console.set_foreground_color(ForegroundColor.red)
|
||||||
Console.write_line(output)
|
Console.write_line(output)
|
||||||
@ -169,7 +169,7 @@ class Logger(LoggerABC):
|
|||||||
if self._level.value >= LoggingLevel.FATAL.value:
|
if self._level.value >= LoggingLevel.FATAL.value:
|
||||||
self._append_log(output)
|
self._append_log(output)
|
||||||
|
|
||||||
# check if message can be shown in console
|
# check if message can be shown in console_old
|
||||||
if self._console.value >= LoggingLevel.FATAL.value:
|
if self._console.value >= LoggingLevel.FATAL.value:
|
||||||
Console.set_foreground_color(ForegroundColor.red)
|
Console.set_foreground_color(ForegroundColor.red)
|
||||||
Console.write_line(output)
|
Console.write_line(output)
|
||||||
@ -186,7 +186,7 @@ class Logger(LoggerABC):
|
|||||||
else:
|
else:
|
||||||
output = self._get_string(name, LoggingLevel.ERROR, message)
|
output = self._get_string(name, LoggingLevel.ERROR, message)
|
||||||
|
|
||||||
# check if message can be shown in console
|
# check if message can be shown in console_old
|
||||||
if self._console.value >= LoggingLevel.FATAL.value:
|
if self._console.value >= LoggingLevel.FATAL.value:
|
||||||
Console.set_foreground_color(ForegroundColor.red)
|
Console.set_foreground_color(ForegroundColor.red)
|
||||||
Console.write_line(output)
|
Console.write_line(output)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from distutils.dir_util import copy_tree
|
from typing import Optional
|
||||||
|
|
||||||
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
|
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
|
||||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||||
@ -12,6 +12,13 @@ from cpl_cli.configuration.build_settings_name import BuildSettingsName
|
|||||||
from cpl_cli.configuration.project_settings import ProjectSettings
|
from cpl_cli.configuration.project_settings import ProjectSettings
|
||||||
from cpl_cli.configuration.project_settings_name import ProjectSettingsName
|
from cpl_cli.configuration.project_settings_name import ProjectSettingsName
|
||||||
from cpl_cli.configuration.version_settings_name import VersionSettingsName
|
from cpl_cli.configuration.version_settings_name import VersionSettingsName
|
||||||
|
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, MainWithoutApplicationHostTemplate, MainWithApplicationHostTemplate
|
||||||
|
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 New(CommandABC):
|
class New(CommandABC):
|
||||||
@ -29,6 +36,9 @@ class New(CommandABC):
|
|||||||
self._project_json = {}
|
self._project_json = {}
|
||||||
|
|
||||||
self._command: str = ''
|
self._command: str = ''
|
||||||
|
self._use_application_api: bool = False
|
||||||
|
self._use_startup: bool = False
|
||||||
|
self._use_service_providing: bool = False
|
||||||
|
|
||||||
def _create_project_settings(self, name: str):
|
def _create_project_settings(self, name: str):
|
||||||
self._project_dict = {
|
self._project_dict = {
|
||||||
@ -76,12 +86,29 @@ class New(CommandABC):
|
|||||||
BuildSettings.__name__: self._build_dict
|
BuildSettings.__name__: self._build_dict
|
||||||
}
|
}
|
||||||
|
|
||||||
def _create_project_dir(self):
|
def _get_project_path(self) -> Optional[str]:
|
||||||
project_path = os.path.join(self._runtime.working_directory, self._project.name)
|
project_path = os.path.join(self._runtime.working_directory, self._project.name)
|
||||||
if os.path.isdir(project_path) and len(os.listdir(project_path)) > 0:
|
if os.path.isdir(project_path) and len(os.listdir(project_path)) > 0:
|
||||||
Console.error('Project path is not empty\n')
|
Console.error('Project path is not empty\n')
|
||||||
exit()
|
return None
|
||||||
|
|
||||||
|
return project_path
|
||||||
|
|
||||||
|
def _get_project_informations(self):
|
||||||
|
result = Console.read('Do you want to use application host? (y/n) ')
|
||||||
|
if result.lower() == 'y':
|
||||||
|
self._use_application_api = True
|
||||||
|
|
||||||
|
if self._use_application_api:
|
||||||
|
result = Console.read('Do you want to use startup? (y/n) ')
|
||||||
|
if result.lower() == 'y':
|
||||||
|
self._use_startup = True
|
||||||
|
|
||||||
|
# result = Console.read('Do you want to use service providing? (y/n) ')
|
||||||
|
# if result.lower() == 'y':
|
||||||
|
# self._use_service_providing = True
|
||||||
|
|
||||||
|
def _build_project_dir(self, project_path: str):
|
||||||
if not os.path.isdir(project_path):
|
if not os.path.isdir(project_path):
|
||||||
os.makedirs(project_path)
|
os.makedirs(project_path)
|
||||||
|
|
||||||
@ -89,19 +116,52 @@ class New(CommandABC):
|
|||||||
project_json.write(json.dumps(self._project_json, indent=4))
|
project_json.write(json.dumps(self._project_json, indent=4))
|
||||||
project_json.close()
|
project_json.close()
|
||||||
|
|
||||||
template_path = os.path.join(self._runtime.runtime_directory, f'templates/new/{self._command}')
|
templates: list[TemplateFileABC] = [
|
||||||
if not os.path.isdir(template_path):
|
LicenseTemplate(),
|
||||||
Console.error(template_path, '\n\nTemplate path not found\n')
|
ReadmeTemplate(),
|
||||||
exit()
|
TestsInitTemplate()
|
||||||
|
]
|
||||||
|
if self._use_application_api:
|
||||||
|
templates.append(ApplicationTemplate())
|
||||||
|
if self._use_startup:
|
||||||
|
templates.append(StartupTemplate())
|
||||||
|
templates.append(MainWithApplicationHostAndStartupTemplate())
|
||||||
|
else:
|
||||||
|
templates.append(MainWithApplicationHostTemplate())
|
||||||
|
else:
|
||||||
|
templates.append(MainWithoutApplicationHostTemplate())
|
||||||
|
|
||||||
copy_tree(template_path, project_path)
|
for template in templates:
|
||||||
|
Console.spinner(f'Creating {template.path}{template.name}', self._create_template, project_path, template)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _create_template(project_path: str, template: TemplateFileABC):
|
||||||
|
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()
|
||||||
|
|
||||||
def _console(self, args: list[str]):
|
def _console(self, args: list[str]):
|
||||||
name = self._config.get_configuration(self._command)
|
name = self._config.get_configuration(self._command)
|
||||||
self._create_project_settings(name)
|
|
||||||
self._create_build_settings()
|
Console.spinner('Creating project settings', self._create_project_settings, name)
|
||||||
self._create_project_json()
|
Console.spinner('Creating build settings', self._create_build_settings)
|
||||||
self._create_project_dir()
|
path = self._get_project_path()
|
||||||
|
if path is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
Console.spinner('Creating project file', self._create_project_json)
|
||||||
|
Console.write_line('Building project directory:')
|
||||||
|
self._get_project_informations()
|
||||||
|
try:
|
||||||
|
self._build_project_dir(path)
|
||||||
|
except Exception as e:
|
||||||
|
Console.error('Could not create project', str(e))
|
||||||
|
|
||||||
def run(self, args: list[str]):
|
def run(self, args: list[str]):
|
||||||
self._command = args[0]
|
self._command = args[0]
|
||||||
|
@ -1,35 +1,36 @@
|
|||||||
from cpl_cli.templates.template import Template
|
import textwrap
|
||||||
|
|
||||||
|
|
||||||
class Init:
|
class Init:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_init_py() -> str:
|
def get_init_py() -> str:
|
||||||
string = """# -*- coding: utf-8 -*-
|
string = textwrap.dedent("""\
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
\"\"\"
|
|
||||||
$Name $Description
|
|
||||||
~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
$LongDescription
|
\"\"\"
|
||||||
|
$Name $Description
|
||||||
:copyright: (c) $CopyrightDate $CopyrightName
|
~~~~~~~~~~~~~~~~~~~
|
||||||
:license: $LicenseDescription
|
|
||||||
|
$LongDescription
|
||||||
\"\"\"
|
|
||||||
|
:copyright: (c) $CopyrightDate $CopyrightName
|
||||||
__title__ = '$Title'
|
:license: $LicenseDescription
|
||||||
__author__ = '$Author'
|
|
||||||
__license__ = '$LicenseName'
|
\"\"\"
|
||||||
__copyright__ = 'Copyright (c) $CopyrightDate $CopyrightName'
|
|
||||||
__version__ = '$Version'
|
__title__ = '$Title'
|
||||||
|
__author__ = '$Author'
|
||||||
from collections import namedtuple
|
__license__ = '$LicenseName'
|
||||||
|
__copyright__ = 'Copyright (c) $CopyrightDate $CopyrightName'
|
||||||
$Imports
|
__version__ = '$Version'
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
from collections import namedtuple
|
||||||
version_info = VersionInfo(major=$Major, minor=$Minor, micro=$Micro)
|
|
||||||
"""
|
$Imports
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major=$Major, minor=$Minor, micro=$Micro)
|
||||||
|
""")
|
||||||
|
|
||||||
return Template.build_template_string(string)
|
return string
|
||||||
|
25
src/cpl_cli/templates/new/__init__.py
Normal file
25
src/cpl_cli/templates/new/__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.templates.new'
|
||||||
|
__author__ = 'Sven Heidemann'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||||
|
__version__ = '2021.4.1'
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major=2021, minor=4, micro=1)
|
25
src/cpl_cli/templates/new/console/__init__.py
Normal file
25
src/cpl_cli/templates/new/console/__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.templates.new.console'
|
||||||
|
__author__ = 'Sven Heidemann'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||||
|
__version__ = '2021.4.1'
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major=2021, minor=4, micro=1)
|
23
src/cpl_cli/templates/new/console/license.py
Normal file
23
src/cpl_cli/templates/new/console/license.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||||
|
|
||||||
|
|
||||||
|
class LicenseTemplate(TemplateFileABC):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
|
self._name = 'LICENSE'
|
||||||
|
self._path = ''
|
||||||
|
self._value = """"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def path(self) -> str:
|
||||||
|
return self._path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self) -> str:
|
||||||
|
return self._value
|
23
src/cpl_cli/templates/new/console/readme_py.py
Normal file
23
src/cpl_cli/templates/new/console/readme_py.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||||
|
|
||||||
|
|
||||||
|
class ReadmeTemplate(TemplateFileABC):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
|
self._name = 'README.md'
|
||||||
|
self._path = ''
|
||||||
|
self._value = """"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def path(self) -> str:
|
||||||
|
return self._path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self) -> str:
|
||||||
|
return self._value
|
25
src/cpl_cli/templates/new/console/src/__init__.py
Normal file
25
src/cpl_cli/templates/new/console/src/__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.templates.new.console.src'
|
||||||
|
__author__ = 'Sven Heidemann'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||||
|
__version__ = '2021.4.1'
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major=2021, minor=4, micro=1)
|
@ -1,14 +1,40 @@
|
|||||||
from cpl.application.application_abc import ApplicationABC
|
import textwrap
|
||||||
from cpl.console.console import Console
|
|
||||||
|
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||||
|
|
||||||
|
|
||||||
class Application(ApplicationABC):
|
class ApplicationTemplate(TemplateFileABC):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
ApplicationABC.__init__(self)
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
def configure(self):
|
self._name = 'application.py'
|
||||||
pass
|
self._path = 'src/'
|
||||||
|
self._value = textwrap.dedent("""\
|
||||||
|
from cpl.application.application_abc import ApplicationABC
|
||||||
|
from cpl.console.console import Console
|
||||||
|
|
||||||
|
|
||||||
|
class Application(ApplicationABC):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
ApplicationABC.__init__(self)
|
||||||
|
|
||||||
|
def configure(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def main(self):
|
||||||
|
Console.write_line('Hello World')
|
||||||
|
""")
|
||||||
|
|
||||||
def main(self):
|
@property
|
||||||
Console.write_line('Hello World')
|
def name(self) -> str:
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def path(self) -> str:
|
||||||
|
return self._path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self) -> str:
|
||||||
|
return self._value
|
||||||
|
@ -1,13 +1,105 @@
|
|||||||
from startup import Startup
|
import textwrap
|
||||||
from application import Application
|
|
||||||
|
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||||
|
|
||||||
|
|
||||||
def main():
|
class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
|
||||||
app = Application()
|
|
||||||
app.use_startup(Startup)
|
def __init__(self):
|
||||||
app.build()
|
TemplateFileABC.__init__(self)
|
||||||
app.run()
|
|
||||||
|
self._name = 'main.py'
|
||||||
|
self._path = 'src/'
|
||||||
|
self._value = textwrap.dedent("""\
|
||||||
|
from startup import Startup
|
||||||
|
from application import Application
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
app = Application()
|
||||||
|
app.use_startup(Startup)
|
||||||
|
app.build()
|
||||||
|
app.run()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
""")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def path(self) -> str:
|
||||||
|
return self._path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self) -> str:
|
||||||
|
return self._value
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
class MainWithApplicationHostTemplate(TemplateFileABC):
|
||||||
main()
|
|
||||||
|
def __init__(self):
|
||||||
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
|
self._name = 'main.py'
|
||||||
|
self._path = 'src/'
|
||||||
|
self._value = textwrap.dedent("""\
|
||||||
|
from application import Application
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
app = Application()
|
||||||
|
app.build()
|
||||||
|
app.run()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
""")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def path(self) -> str:
|
||||||
|
return self._path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self) -> str:
|
||||||
|
return self._value
|
||||||
|
|
||||||
|
|
||||||
|
class MainWithoutApplicationHostTemplate(TemplateFileABC):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
|
self._name = 'main.py'
|
||||||
|
self._path = 'src/'
|
||||||
|
self._value = textwrap.dedent("""\
|
||||||
|
from cpl.console.console import Console
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
Console.write_line('Hello World')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
""")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def path(self) -> str:
|
||||||
|
return self._path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self) -> str:
|
||||||
|
return self._value
|
||||||
|
@ -1,33 +1,59 @@
|
|||||||
from typing import Optional
|
import textwrap
|
||||||
|
|
||||||
from cpl.application.application_host import ApplicationHost
|
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||||
from cpl.application.application_host_abc import ApplicationHostABC
|
|
||||||
from cpl.application.startup_abc import StartupABC
|
|
||||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
|
||||||
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
|
|
||||||
|
|
||||||
|
|
||||||
class Startup(StartupABC):
|
class StartupTemplate(TemplateFileABC):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
StartupABC.__init__(self)
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
self._app_host: Optional[ApplicationHostABC] = None
|
self._name = 'startup.py'
|
||||||
self._configuration: Optional[ConfigurationABC] = None
|
self._path = 'src/'
|
||||||
self._services: Optional[ServiceProviderABC] = None
|
self._value = textwrap.dedent("""\
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
def create_application_host(self) -> ApplicationHostABC:
|
from cpl.application.application_host import ApplicationHost
|
||||||
self._app_host = ApplicationHost()
|
from cpl.application.application_host_abc import ApplicationHostABC
|
||||||
self._configuration = self._app_host.configuration
|
from cpl.application.startup_abc import StartupABC
|
||||||
self._services = self._app_host.services
|
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||||
return self._app_host
|
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
|
||||||
|
|
||||||
|
|
||||||
|
class Startup(StartupABC):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
StartupABC.__init__(self)
|
||||||
|
|
||||||
|
self._app_host: Optional[ApplicationHostABC] = None
|
||||||
|
self._configuration: Optional[ConfigurationABC] = None
|
||||||
|
self._services: Optional[ServiceProviderABC] = None
|
||||||
|
|
||||||
|
def create_application_host(self) -> ApplicationHostABC:
|
||||||
|
self._app_host = ApplicationHost()
|
||||||
|
self._configuration = self._app_host.configuration
|
||||||
|
self._services = self._app_host.services
|
||||||
|
return self._app_host
|
||||||
|
|
||||||
|
def create_configuration(self) -> ConfigurationABC:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return self._configuration
|
||||||
|
|
||||||
|
def create_services(self) -> ServiceProviderABC:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return self._services
|
||||||
|
""")
|
||||||
|
|
||||||
def create_configuration(self) -> ConfigurationABC:
|
@property
|
||||||
pass
|
def name(self) -> str:
|
||||||
|
return self._name
|
||||||
|
|
||||||
return self._configuration
|
@property
|
||||||
|
def path(self) -> str:
|
||||||
|
return self._path
|
||||||
|
|
||||||
def create_services(self) -> ServiceProviderABC:
|
@property
|
||||||
pass
|
def value(self) -> str:
|
||||||
|
return self._value
|
||||||
return self._services
|
|
||||||
|
@ -11,7 +11,7 @@ sh-edraft Common Python library
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__title__ = 'cpl_cli.templates.new.console.src.tests'
|
__title__ = 'cpl_cli.templates.new.console_old.src.tests'
|
||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||||
|
27
src/cpl_cli/templates/new/console/src/tests/init.py
Normal file
27
src/cpl_cli/templates/new/console/src/tests/init.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import textwrap
|
||||||
|
|
||||||
|
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||||
|
|
||||||
|
|
||||||
|
class TestsInitTemplate(TemplateFileABC):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
|
self._name = '__init__.py'
|
||||||
|
self._path = 'src/tests/'
|
||||||
|
self._value = textwrap.dedent("""\
|
||||||
|
# imports:
|
||||||
|
""")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def path(self) -> str:
|
||||||
|
return self._path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self) -> str:
|
||||||
|
return self._value
|
@ -1,11 +1,12 @@
|
|||||||
from cpl_cli.templates.template import Template
|
import textwrap
|
||||||
|
|
||||||
|
|
||||||
class Setup:
|
class Setup:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_setup_py() -> str:
|
def get_setup_py() -> str:
|
||||||
string = """\"\"\"
|
string = textwrap.dedent("""\
|
||||||
|
\"\"\"
|
||||||
This file is generated by CPL CLI
|
This file is generated by CPL CLI
|
||||||
\"\"\"
|
\"\"\"
|
||||||
|
|
||||||
@ -26,6 +27,6 @@ class Setup:
|
|||||||
entry_points=$EntryPoints,
|
entry_points=$EntryPoints,
|
||||||
package_data=$PackageData
|
package_data=$PackageData
|
||||||
)
|
)
|
||||||
"""
|
""")
|
||||||
|
|
||||||
return Template.build_template_string(string)
|
return string
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
class Template:
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def build_template_string(string: str) -> str:
|
|
||||||
return_value = ''
|
|
||||||
for i in range(0, len(string.splitlines())):
|
|
||||||
line = string.splitlines()[i]
|
|
||||||
if i == len(string.splitlines())-1:
|
|
||||||
return_value += f'{line.strip()}'
|
|
||||||
break
|
|
||||||
|
|
||||||
return_value += f'{line.strip()}\n'
|
|
||||||
|
|
||||||
return return_value
|
|
19
src/cpl_cli/templates/template_file_abc.py
Normal file
19
src/cpl_cli/templates/template_file_abc.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
class TemplateFileABC(ABC):
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def __init__(self): pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def name(self) -> str: pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def path(self) -> str: pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def value(self) -> str: pass
|
@ -25,7 +25,7 @@ class Application(ApplicationABC):
|
|||||||
self._mailer.send_mail(mail)
|
self._mailer.send_mail(mail)
|
||||||
|
|
||||||
def test_console(self):
|
def test_console(self):
|
||||||
self._logger.debug(__name__, 'Started console test')
|
self._logger.debug(__name__, 'Started console_old test')
|
||||||
Console.write_line('Hello World')
|
Console.write_line('Hello World')
|
||||||
Console.write('\nName: ')
|
Console.write('\nName: ')
|
||||||
Console.write_line('Hello', Console.read_line())
|
Console.write_line('Hello', Console.read_line())
|
||||||
|
Loading…
Reference in New Issue
Block a user