Compare commits
4 Commits
9fca2018e5
...
89d591ce0a
Author | SHA1 | Date | |
---|---|---|---|
89d591ce0a | |||
77c560b40c | |||
dad4913bcd | |||
9b56650d4b |
@ -3,12 +3,14 @@ import shutil
|
||||
import json
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.configuration.settings_helper import SettingsHelper
|
||||
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
from cpl_cli.configuration import WorkspaceSettings, WorkspaceSettingsNameEnum
|
||||
from cpl_cli.configuration import WorkspaceSettings, WorkspaceSettingsNameEnum, BuildSettingsNameEnum, ProjectSettings, BuildSettings
|
||||
|
||||
|
||||
class RemoveService(CommandABC):
|
||||
@ -68,6 +70,50 @@ class RemoveService(CommandABC):
|
||||
|
||||
self._create_file(path, ws_dict)
|
||||
|
||||
def _get_project_settings(self, project: str) -> dict:
|
||||
with open(os.path.join(os.getcwd(), self._workspace.projects[project]), 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
return project_json
|
||||
|
||||
def _write_project_settings(self, project: str, project_settings: dict, build_settings: dict):
|
||||
with open(os.path.join(os.getcwd(), self._workspace.projects[project]), 'w', encoding='utf-8') as file:
|
||||
file.write(json.dumps({
|
||||
ProjectSettings.__name__: project_settings,
|
||||
BuildSettings.__name__: build_settings
|
||||
}, indent=2))
|
||||
file.close()
|
||||
|
||||
def _find_deps_in_projects(self, project_name: str, rel_path: str):
|
||||
for project in self._workspace.projects:
|
||||
if project == project_name:
|
||||
continue
|
||||
|
||||
project_settings = self._get_project_settings(project)
|
||||
if BuildSettings.__name__ not in project_settings or BuildSettingsNameEnum.project_references.value not in project_settings[BuildSettings.__name__]:
|
||||
continue
|
||||
|
||||
ref_to_delete = ''
|
||||
for ref in project_settings[BuildSettings.__name__][BuildSettingsNameEnum.project_references.value]:
|
||||
if os.path.basename(ref) == f'{project_name}.json':
|
||||
ref_to_delete = ref
|
||||
|
||||
if ref_to_delete not in project_settings[BuildSettings.__name__][BuildSettingsNameEnum.project_references.value]:
|
||||
continue
|
||||
|
||||
project_settings[BuildSettings.__name__][BuildSettingsNameEnum.project_references.value].remove(ref_to_delete)
|
||||
Console.spinner(
|
||||
f'Removing {project_name} from {project}',
|
||||
self._write_project_settings,
|
||||
project,
|
||||
project_settings[ProjectSettings.__name__],
|
||||
project_settings[BuildSettings.__name__],
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
def execute(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
@ -88,15 +134,17 @@ class RemoveService(CommandABC):
|
||||
Console.error(f'Project {project_name} is the default project.')
|
||||
return
|
||||
|
||||
src_path = os.path.abspath(os.path.dirname(self._workspace.projects[project_name]))
|
||||
src_path = os.path.dirname(self._workspace.projects[project_name])
|
||||
Console.spinner(
|
||||
f'Removing {src_path}',
|
||||
self._remove_sources,
|
||||
src_path,
|
||||
os.path.abspath(src_path),
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
self._find_deps_in_projects(project_name, src_path)
|
||||
|
||||
del self._workspace.projects[project_name]
|
||||
path = 'cpl-workspace.json'
|
||||
Console.spinner(
|
||||
|
@ -41,12 +41,12 @@ def main():
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
# ((
|
||||
# ( `)
|
||||
# ; / ,
|
||||
# / \/
|
||||
# / |
|
||||
# / ~/
|
||||
# / ) ) ~ edraft
|
||||
# ___// | /
|
||||
# `--' \_~-,
|
||||
# ((
|
||||
# ( `)
|
||||
# ; / ,
|
||||
# / \/
|
||||
# / |
|
||||
# / ~/
|
||||
# / ) ) ~ edraft
|
||||
# ___// | /
|
||||
# `--' \_~-,
|
||||
|
@ -1,10 +1,52 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from cpl_core.utils import String
|
||||
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class AddTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
def __init__(self, methodName: str):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
self._source = 'add-test-project'
|
||||
self._target = 'add-test-library'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
|
||||
def test_equal(self):
|
||||
pass
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
return project_json
|
||||
|
||||
def setUp(self):
|
||||
os.chdir(os.path.abspath(PLAYGROUND_PATH))
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
CLICommands.new('console', self._target, '--ab', '--s')
|
||||
|
||||
def cleanUp(self):
|
||||
# remove projects
|
||||
if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))):
|
||||
return
|
||||
|
||||
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source)))
|
||||
|
||||
def test_add(self):
|
||||
CLICommands.add(self._source, self._target)
|
||||
settings = self._get_project_settings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('ProjectReferences', settings['BuildSettings'])
|
||||
self.assertIn('BuildSettings', settings)
|
||||
self.assertIn(
|
||||
f'../{String.convert_to_snake_case(self._target)}/{self._target}.json',
|
||||
settings['BuildSettings']['ProjectReferences']
|
||||
)
|
||||
|
@ -5,9 +5,11 @@ import unittest
|
||||
from typing import Optional
|
||||
from unittest import TestResult
|
||||
|
||||
from unittests_cli.add_test_case import AddTestCase
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_cli.generate_test_case import GenerateTestCase
|
||||
from unittests_cli.new_test_case import NewTestCase
|
||||
from unittests_cli.remove_test_case import RemoveTestCase
|
||||
|
||||
|
||||
class CLITestSuite(unittest.TestSuite):
|
||||
@ -32,8 +34,8 @@ class CLITestSuite(unittest.TestSuite):
|
||||
# self.addTests(loader.loadTestsFromTestCase(UpdateTestCase))
|
||||
|
||||
# workspace needed
|
||||
# self.addTests(loader.loadTestsFromTestCase(AddTestCase))
|
||||
# self.addTests(loader.loadTestsFromTestCase(RemoveTestCase))
|
||||
self.addTests(loader.loadTestsFromTestCase(AddTestCase))
|
||||
self.addTests(loader.loadTestsFromTestCase(RemoveTestCase))
|
||||
|
||||
def _setup(self):
|
||||
try:
|
||||
|
@ -1,10 +1,49 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from cpl_core.utils import String
|
||||
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class RemoveTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
def __init__(self, methodName: str):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
self._source = 'add-test-project'
|
||||
self._target = 'add-test-library'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
|
||||
def test_equal(self):
|
||||
pass
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
return project_json
|
||||
|
||||
def setUp(self):
|
||||
os.chdir(os.path.abspath(PLAYGROUND_PATH))
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
CLICommands.new('console', self._target, '--ab', '--s')
|
||||
CLICommands.add(self._source, self._target)
|
||||
|
||||
def test_remove(self):
|
||||
CLICommands.remove(self._target)
|
||||
path = os.path.abspath(os.path.join(os.getcwd(), f'../{String.convert_to_snake_case(self._target)}'))
|
||||
self.assertTrue(os.path.exists(os.getcwd()))
|
||||
self.assertTrue(os.path.exists(os.path.join(os.getcwd(), self._project_file)))
|
||||
self.assertFalse(os.path.exists(path))
|
||||
settings = self._get_project_settings()
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('ProjectReferences', settings['BuildSettings'])
|
||||
self.assertIn('BuildSettings', settings)
|
||||
self.assertNotIn(
|
||||
f'../{String.convert_to_snake_case(self._target)}/{self._target}.json',
|
||||
settings['BuildSettings']['ProjectReferences']
|
||||
)
|
||||
|
@ -17,6 +17,10 @@ class CLICommands:
|
||||
|
||||
subprocess.run(command, env=env_vars)
|
||||
|
||||
@classmethod
|
||||
def add(cls, source: str, target: str):
|
||||
cls._run('add', source, target)
|
||||
|
||||
@classmethod
|
||||
def generate(cls, schematic: str, name: str, output=False):
|
||||
cls._run('generate', schematic, name, output=output)
|
||||
@ -24,3 +28,7 @@ class CLICommands:
|
||||
@classmethod
|
||||
def new(cls, project_type: str, name: str, *args, output=False):
|
||||
cls._run('new', project_type, name, *args, output=output)
|
||||
|
||||
@classmethod
|
||||
def remove(cls, project: str):
|
||||
cls._run('remove', project)
|
||||
|
Loading…
Reference in New Issue
Block a user