Remove unnecessary configs #70-1
This commit is contained in:
parent
523e019aa0
commit
3b9ef0048e
@ -1 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
post-build
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c)
|
||||
:license:
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'post_build'
|
||||
__author__ = ''
|
||||
__license__ = ''
|
||||
__copyright__ = 'Copyright (c) '
|
||||
__version__ = '0.0.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='0', micro='0')
|
||||
|
@ -3,14 +3,24 @@ from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
from post_build.service.dependencies import Dependencies
|
||||
from post_build.service.remove_config import RemoveConfig
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
self._remove_config: RemoveConfig = services.get_service(RemoveConfig)
|
||||
self._deps: Dependencies = services.get_service(Dependencies)
|
||||
|
||||
def configure(self):
|
||||
pass
|
||||
|
||||
def main(self):
|
||||
Console.write_line('Hello World')
|
||||
Console.write_line('KDB Post-Build:')
|
||||
Console.spinner(f'Removing unnecessary configs', self._remove_config.remove)
|
||||
# Console.spinner(f'Creating requirements file for pip', self._deps.create)
|
||||
|
||||
|
||||
|
@ -11,5 +11,20 @@
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLogLevel": "ERROR",
|
||||
"FileLogLevel": "WARN"
|
||||
},
|
||||
|
||||
"PostBuild": {
|
||||
"KeepConfigs": [
|
||||
"appsettings.json",
|
||||
"appsettings.staging.json",
|
||||
"appsettings.production.json",
|
||||
"apisettings.json",
|
||||
"apisettings.staging.json",
|
||||
"apisettings.production.json"
|
||||
],
|
||||
"ConfigPaths": [
|
||||
"bot/config/",
|
||||
"bot_api/config/"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
29
kdb-bot/tools/post_build/post_build_settings.py
Normal file
29
kdb-bot/tools/post_build/post_build_settings.py
Normal file
@ -0,0 +1,29 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class PostBuildSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._keep_config = []
|
||||
self._config_paths = []
|
||||
|
||||
@property
|
||||
def keep_config(self) -> list[str]:
|
||||
return self._keep_config
|
||||
|
||||
@property
|
||||
def config_paths(self) -> list[str]:
|
||||
return self._config_paths
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._keep_config = settings['KeepConfigs']
|
||||
self._config_paths = settings['ConfigPaths']
|
||||
except Exception as e:
|
||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings')
|
||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
26
kdb-bot/tools/post_build/service/__init__.py
Normal file
26
kdb-bot/tools/post_build/service/__init__.py
Normal file
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
post-build
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c)
|
||||
:license:
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'post_build.service'
|
||||
__author__ = ''
|
||||
__license__ = ''
|
||||
__copyright__ = 'Copyright (c) '
|
||||
__version__ = '0.0.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='0', micro='0')
|
7
kdb-bot/tools/post_build/service/dependencies.py
Normal file
7
kdb-bot/tools/post_build/service/dependencies.py
Normal file
@ -0,0 +1,7 @@
|
||||
class Dependencies:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def create(self):
|
||||
pass
|
39
kdb-bot/tools/post_build/service/remove_config.py
Normal file
39
kdb-bot/tools/post_build/service/remove_config.py
Normal file
@ -0,0 +1,39 @@
|
||||
import os
|
||||
|
||||
from cpl_cli.configuration import ProjectSettings, BuildSettings, WorkspaceSettings
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
|
||||
from post_build.post_build_settings import PostBuildSettings
|
||||
|
||||
|
||||
class RemoveConfig:
|
||||
|
||||
def __init__(self, env: ApplicationEnvironmentABC, ws: WorkspaceSettings, project: ProjectSettings, build: BuildSettings, post_build: PostBuildSettings,):
|
||||
|
||||
self._env = env
|
||||
self._workspace = ws
|
||||
self._project = project
|
||||
self._build = build
|
||||
self._post_build = post_build
|
||||
|
||||
def remove(self):
|
||||
dist_path = os.path.abspath(os.path.join(
|
||||
self._env.working_directory,
|
||||
os.path.dirname(self._workspace.projects[self._project.name]),
|
||||
self._build.output_path,
|
||||
self._project.name,
|
||||
'build'
|
||||
))
|
||||
|
||||
for cfg_path in self._post_build.config_paths:
|
||||
config_path = os.path.join(
|
||||
dist_path,
|
||||
cfg_path
|
||||
)
|
||||
for r, d, f in os.walk(config_path):
|
||||
for file in f:
|
||||
if file in self._post_build.keep_config:
|
||||
continue
|
||||
|
||||
os.remove(os.path.abspath(os.path.join(config_path, file)))
|
@ -1,8 +1,15 @@
|
||||
import os.path
|
||||
|
||||
from cpl_cli.configuration import WorkspaceSettings, ProjectSettings
|
||||
from cpl_core.application import StartupABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironment
|
||||
|
||||
from post_build.service.dependencies import Dependencies
|
||||
from post_build.service.remove_config import RemoveConfig
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
@ -10,7 +17,16 @@ class Startup(StartupABC):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||
configuration.add_json_file(f'appsettings.json', optional=False, output=False)
|
||||
environment.set_working_directory(os.path.abspath(os.path.join(environment.working_directory, '../../')))
|
||||
configuration.add_json_file(f'cpl-workspace.json', optional=False, output=False)
|
||||
ws: WorkspaceSettings = configuration.get_configuration(WorkspaceSettings)
|
||||
configuration.add_json_file(ws.projects[ws.default_project], optional=False, output=False)
|
||||
|
||||
return configuration
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
services.add_transient(RemoveConfig)
|
||||
services.add_transient(Dependencies)
|
||||
|
||||
return services.build_service_provider()
|
||||
|
Loading…
Reference in New Issue
Block a user