2022-05-25 19:53:05 +02:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from cpl_core.environment import EnvironmentNameEnum
|
|
|
|
|
2022-05-25 19:30:11 +02:00
|
|
|
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
|
2022-05-25 19:53:05 +02:00
|
|
|
from set_pip_urls.pip_settings import PIPSettings
|
2022-05-25 19:30:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Application(ApplicationABC):
|
|
|
|
|
|
|
|
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
|
|
|
ApplicationABC.__init__(self, config, services)
|
|
|
|
|
2022-05-25 19:53:05 +02:00
|
|
|
self._pip_settings: Optional[PIPSettings] = config.get_configuration(PIPSettings)
|
|
|
|
|
2022-05-25 19:30:11 +02:00
|
|
|
def configure(self):
|
2022-05-25 19:53:05 +02:00
|
|
|
self._configuration.parse_console_arguments(self._services)
|
2022-05-25 19:30:11 +02:00
|
|
|
|
|
|
|
def main(self):
|
2022-05-25 19:53:05 +02:00
|
|
|
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()
|