Added logic to write PipPath & build dev2
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.environment import EnvironmentNameEnum
|
||||
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from set_pip_urls.pip_settings import PIPSettings
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
@@ -9,8 +17,32 @@ class Application(ApplicationABC):
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
self._pip_settings: Optional[PIPSettings] = config.get_configuration(PIPSettings)
|
||||
|
||||
def configure(self):
|
||||
pass
|
||||
self._configuration.parse_console_arguments(self._services)
|
||||
|
||||
def main(self):
|
||||
Console.write_line('Hello World', self._environment.environment_name)
|
||||
if self._pip_settings is None:
|
||||
Console.error('appsettings.json not found')
|
||||
sys.exit()
|
||||
|
||||
url = None
|
||||
match self._environment.environment_name:
|
||||
case EnvironmentNameEnum.production.value:
|
||||
url = self._pip_settings.production
|
||||
case EnvironmentNameEnum.staging.value:
|
||||
url = self._pip_settings.staging
|
||||
case EnvironmentNameEnum.development.value:
|
||||
url = self._pip_settings.development
|
||||
|
||||
cli_json = {
|
||||
"CLI": {
|
||||
"PipPath": url
|
||||
}
|
||||
}
|
||||
file = os.path.abspath(os.path.join(self._environment.working_directory, '../../src/cpl_cli', 'appsettings.json'))
|
||||
Console.write_line(f'Writing PipPath: {url} to {file}')
|
||||
with open(file, 'w') as f:
|
||||
f.write(json.dumps(cli_json, indent=2))
|
||||
f.close()
|
||||
|
37
tools/set_pip_urls/pip_settings.py
Normal file
37
tools/set_pip_urls/pip_settings.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.environment.environment_name_enum import EnvironmentNameEnum
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class PIPSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._production = ''
|
||||
self._staging = ''
|
||||
self._development = ''
|
||||
|
||||
@property
|
||||
def production(self):
|
||||
return self._production
|
||||
|
||||
@property
|
||||
def staging(self):
|
||||
return self._staging
|
||||
|
||||
@property
|
||||
def development(self):
|
||||
return self._development
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._production = settings[EnvironmentNameEnum.production.value]
|
||||
self._staging = settings[EnvironmentNameEnum.staging.value]
|
||||
self._development = settings[EnvironmentNameEnum.development.value]
|
||||
except Exception as e:
|
||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
@@ -16,7 +16,7 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.16.dev1"
|
||||
"cpl-core>=2022.6.16.dev2"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
|
@@ -10,6 +10,8 @@ class Startup(StartupABC):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||
configuration.add_environment_variables('CPL_')
|
||||
configuration.add_json_file('appsettings.json', optional=False, output=False)
|
||||
return configuration
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
|
Reference in New Issue
Block a user