thestage 0.5.471__py3-none-any.whl → 0.6.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- thestage/.env +5 -5
- thestage/__init__.py +3 -4
- thestage/__main__.py +9 -9
- thestage/cli_command.py +56 -56
- thestage/cli_command_helper.py +51 -51
- thestage/color_scheme/color_scheme.py +7 -7
- thestage/config/__init__.py +18 -18
- thestage/config/config_storage.py +5 -5
- thestage/config/env_base.py +7 -7
- thestage/controllers/__init__.py +0 -0
- thestage/controllers/base_controller.py +67 -67
- thestage/controllers/config_controller.py +137 -137
- thestage/controllers/container_controller.py +389 -389
- thestage/controllers/instance_controller.py +183 -183
- thestage/controllers/project_controller.py +810 -783
- thestage/controllers/utils_controller.py +32 -32
- thestage/debug_main.dist.py +28 -28
- thestage/entities/__init__.py +0 -0
- thestage/entities/container.py +17 -17
- thestage/entities/enums/__init__.py +0 -0
- thestage/entities/enums/order_direction_type.py +6 -6
- thestage/entities/enums/shell_type.py +7 -7
- thestage/entities/enums/tail_output_type.py +6 -6
- thestage/entities/enums/yes_no_response.py +7 -7
- thestage/entities/file_item.py +27 -27
- thestage/entities/project_inference_simulator.py +18 -18
- thestage/entities/project_inference_simulator_model.py +16 -16
- thestage/entities/project_task.py +19 -19
- thestage/entities/rented_instance.py +19 -19
- thestage/entities/self_hosted_instance.py +18 -18
- thestage/exceptions/__init__.py +0 -0
- thestage/exceptions/auth_exception.py +6 -6
- thestage/exceptions/base_exception.py +13 -13
- thestage/exceptions/business_logic_exception.py +6 -6
- thestage/exceptions/config_exception.py +6 -6
- thestage/exceptions/file_system_exception.py +6 -6
- thestage/exceptions/git_access_exception.py +17 -17
- thestage/exceptions/remote_server_exception.py +24 -24
- thestage/git/ProgressPrinter.py +22 -22
- thestage/helpers/__init__.py +0 -0
- thestage/helpers/error_handler.py +115 -115
- thestage/helpers/exception_hook.py +14 -14
- thestage/helpers/logger/__init__.py +0 -0
- thestage/helpers/logger/app_logger.py +50 -50
- thestage/helpers/ssh_util.py +38 -38
- thestage/i18n/en_GB/messages.po +947 -947
- thestage/i18n/translation.py +9 -9
- thestage/main.py +36 -36
- thestage/services/.env +6 -6
- thestage/services/__init__.py +0 -0
- thestage/services/abstract_mapper.py +9 -9
- thestage/services/abstract_service.py +87 -87
- thestage/services/app_config_service.py +52 -52
- thestage/services/clients/__init__.py +0 -0
- thestage/services/clients/git/__init__.py +0 -0
- thestage/services/clients/git/git_client.py +436 -331
- thestage/services/clients/thestage_api/__init__.py +0 -0
- thestage/services/clients/thestage_api/api_client.py +718 -720
- thestage/services/clients/thestage_api/core/api_client_core.py +108 -108
- thestage/services/clients/thestage_api/core/http_client_exception.py +12 -12
- thestage/services/clients/thestage_api/dtos/__init__.py +0 -0
- thestage/services/clients/thestage_api/dtos/base_response.py +13 -13
- thestage/services/clients/thestage_api/dtos/cloud_provider_region.py +19 -19
- thestage/services/clients/thestage_api/dtos/container_param_request.py +11 -11
- thestage/services/clients/thestage_api/dtos/container_response.py +67 -67
- thestage/services/clients/thestage_api/dtos/docker_container_assigned_device.py +10 -10
- thestage/services/clients/thestage_api/dtos/docker_container_controller/docker_container_list_request.py +13 -13
- thestage/services/clients/thestage_api/dtos/docker_container_controller/docker_container_list_response.py +13 -13
- thestage/services/clients/thestage_api/dtos/docker_container_mapping.py +10 -10
- thestage/services/clients/thestage_api/dtos/entity_filter_request.py +14 -14
- thestage/services/clients/thestage_api/dtos/enums/__init__.py +0 -0
- thestage/services/clients/thestage_api/dtos/enums/container_pending_action.py +10 -10
- thestage/services/clients/thestage_api/dtos/enums/container_status.py +17 -17
- thestage/services/clients/thestage_api/dtos/enums/cpu_type.py +8 -8
- thestage/services/clients/thestage_api/dtos/enums/currency_type.py +10 -10
- thestage/services/clients/thestage_api/dtos/enums/daemon_status.py +9 -9
- thestage/services/clients/thestage_api/dtos/enums/disk_type.py +7 -7
- thestage/services/clients/thestage_api/dtos/enums/drive_type.py +7 -7
- thestage/services/clients/thestage_api/dtos/enums/gpu_name.py +8 -8
- thestage/services/clients/thestage_api/dtos/enums/inference_model_status.py +9 -9
- thestage/services/clients/thestage_api/dtos/enums/inference_simulator_status.py +15 -15
- thestage/services/clients/thestage_api/dtos/enums/instance_rented_status.py +17 -17
- thestage/services/clients/thestage_api/dtos/enums/instance_type.py +7 -7
- thestage/services/clients/thestage_api/dtos/enums/location_region.py +11 -11
- thestage/services/clients/thestage_api/dtos/enums/power_status.py +10 -10
- thestage/services/clients/thestage_api/dtos/enums/provider_name.py +11 -11
- thestage/services/clients/thestage_api/dtos/enums/selfhosted_status.py +10 -10
- thestage/services/clients/thestage_api/dtos/enums/task_execution_status.py +12 -12
- thestage/services/clients/thestage_api/dtos/enums/task_status.py +12 -12
- thestage/services/clients/thestage_api/dtos/frontend_status.py +10 -10
- thestage/services/clients/thestage_api/dtos/inference_controller/deploy_inference_model_to_instance_request.py +13 -13
- thestage/services/clients/thestage_api/dtos/inference_controller/deploy_inference_model_to_instance_response.py +13 -13
- thestage/services/clients/thestage_api/dtos/inference_controller/deploy_inference_model_to_sagemaker_request.py +12 -12
- thestage/services/clients/thestage_api/dtos/inference_controller/deploy_inference_model_to_sagemaker_response.py +12 -12
- thestage/services/clients/thestage_api/dtos/inference_controller/get_inference_simulator_request.py +10 -10
- thestage/services/clients/thestage_api/dtos/inference_controller/get_inference_simulator_response.py +13 -13
- thestage/services/clients/thestage_api/dtos/inference_controller/inference_simulator_list_for_project_request.py +14 -14
- thestage/services/clients/thestage_api/dtos/inference_controller/inference_simulator_list_for_project_response.py +12 -12
- thestage/services/clients/thestage_api/dtos/inference_controller/inference_simulator_model_list_for_project_request.py +12 -12
- thestage/services/clients/thestage_api/dtos/inference_controller/inference_simulator_model_list_for_project_response.py +13 -13
- thestage/services/clients/thestage_api/dtos/inference_simulator_model_response.py +11 -11
- thestage/services/clients/thestage_api/dtos/inference_simulator_response.py +11 -11
- thestage/services/clients/thestage_api/dtos/installed_service.py +17 -17
- thestage/services/clients/thestage_api/dtos/instance_detected_gpus.py +20 -20
- thestage/services/clients/thestage_api/dtos/instance_rented_response.py +71 -71
- thestage/services/clients/thestage_api/dtos/logging_controller/docker_container_log_stream_request.py +7 -7
- thestage/services/clients/thestage_api/dtos/logging_controller/log_polling_request.py +13 -13
- thestage/services/clients/thestage_api/dtos/logging_controller/log_polling_response.py +14 -14
- thestage/services/clients/thestage_api/dtos/logging_controller/task_log_stream_request.py +7 -7
- thestage/services/clients/thestage_api/dtos/logging_controller/user_logs_query_request.py +21 -21
- thestage/services/clients/thestage_api/dtos/logging_controller/user_logs_query_response.py +14 -14
- thestage/services/clients/thestage_api/dtos/paginated_entity_list.py +11 -11
- thestage/services/clients/thestage_api/dtos/pagination_data.py +10 -10
- thestage/services/clients/thestage_api/dtos/price_definition.py +14 -14
- thestage/services/clients/thestage_api/dtos/project_controller/project_get_deploy_ssh_key_request.py +7 -7
- thestage/services/clients/thestage_api/dtos/project_controller/project_get_deploy_ssh_key_response.py +10 -10
- thestage/services/clients/thestage_api/dtos/project_controller/project_push_inference_simulator_model_request.py +8 -8
- thestage/services/clients/thestage_api/dtos/project_controller/project_push_inference_simulator_model_response.py +6 -6
- thestage/services/clients/thestage_api/dtos/project_controller/project_run_task_request.py +15 -15
- thestage/services/clients/thestage_api/dtos/project_controller/project_run_task_response.py +10 -10
- thestage/services/clients/thestage_api/dtos/project_controller/project_start_inference_simulator_request.py +13 -14
- thestage/services/clients/thestage_api/dtos/project_controller/project_start_inference_simulator_response.py +10 -10
- thestage/services/clients/thestage_api/dtos/project_response.py +32 -32
- thestage/services/clients/thestage_api/dtos/selfhosted_instance_response.py +56 -56
- thestage/services/clients/thestage_api/dtos/sftp_path_helper.py +13 -13
- thestage/services/clients/thestage_api/dtos/ssh_key_controller/add_ssh_key_to_user_request.py +8 -8
- thestage/services/clients/thestage_api/dtos/ssh_key_controller/add_ssh_key_to_user_response.py +11 -11
- thestage/services/clients/thestage_api/dtos/ssh_key_controller/add_ssh_public_key_to_instance_request.py +8 -8
- thestage/services/clients/thestage_api/dtos/ssh_key_controller/add_ssh_public_key_to_instance_response.py +11 -11
- thestage/services/clients/thestage_api/dtos/ssh_key_controller/is_user_has_public_ssh_key_request.py +7 -7
- thestage/services/clients/thestage_api/dtos/ssh_key_controller/is_user_has_public_ssh_key_response.py +12 -12
- thestage/services/clients/thestage_api/dtos/task_controller/task_list_for_project_request.py +10 -10
- thestage/services/clients/thestage_api/dtos/task_controller/task_list_for_project_response.py +12 -12
- thestage/services/clients/thestage_api/dtos/task_controller/task_status_localized_map_response.py +9 -9
- thestage/services/clients/thestage_api/dtos/task_controller/task_view_response.py +12 -12
- thestage/services/clients/thestage_api/dtos/user_controller/user_profile.py +12 -12
- thestage/services/clients/thestage_api/dtos/validate_token_response.py +11 -11
- thestage/services/config_provider/__init__.py +0 -0
- thestage/services/config_provider/config_provider.py +237 -237
- thestage/services/connect/connect_service.py +196 -196
- thestage/services/connect/dto/remote_server_config.py +9 -9
- thestage/services/container/__init__.py +0 -0
- thestage/services/container/container_service.py +374 -374
- thestage/services/container/mapper/__init__.py +0 -0
- thestage/services/container/mapper/container_mapper.py +30 -30
- thestage/services/core_files/config_entity.py +26 -26
- thestage/services/filesystem_service.py +133 -133
- thestage/services/instance/__init__.py +0 -0
- thestage/services/instance/instance_service.py +303 -303
- thestage/services/instance/mapper/__init__.py +0 -0
- thestage/services/instance/mapper/instance_mapper.py +24 -24
- thestage/services/instance/mapper/selfhosted_mapper.py +33 -33
- thestage/services/logging/byte_print_style.py +5 -5
- thestage/services/logging/dto/log_message.py +15 -15
- thestage/services/logging/dto/log_type.py +6 -6
- thestage/services/logging/exception/log_polling_exception.py +6 -6
- thestage/services/logging/logging_constants.py +3 -3
- thestage/services/logging/logging_service.py +367 -367
- thestage/services/project/__init__.py +0 -0
- thestage/services/project/dto/inference_simulator_dto.py +22 -22
- thestage/services/project/dto/inference_simulator_model_dto.py +20 -20
- thestage/services/project/dto/project_config.py +14 -14
- thestage/services/project/mapper/__init__.py +0 -0
- thestage/services/project/mapper/project_inference_simulator_mapper.py +21 -21
- thestage/services/project/mapper/project_inference_simulator_model_mapper.py +21 -21
- thestage/services/project/mapper/project_task_mapper.py +22 -22
- thestage/services/project/project_service.py +1253 -1241
- thestage/services/remote_server_service.py +609 -609
- thestage/services/service_factory.py +97 -97
- thestage/services/task/dto/task_dto.py +40 -40
- thestage/services/validation_service.py +61 -61
- {thestage-0.5.471.dist-info → thestage-0.6.2.dist-info}/LICENSE.txt +12 -12
- {thestage-0.5.471.dist-info → thestage-0.6.2.dist-info}/METADATA +1 -1
- thestage-0.6.2.dist-info/RECORD +176 -0
- {thestage-0.5.471.dist-info → thestage-0.6.2.dist-info}/WHEEL +1 -1
- thestage/debug_tests.py +0 -12
- thestage/services/clients/.DS_Store +0 -0
- thestage-0.5.471.dist-info/RECORD +0 -178
- {thestage-0.5.471.dist-info → thestage-0.6.2.dist-info}/entry_points.txt +0 -0
thestage/i18n/translation.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
|
-
from python_gettext_translations.translations import translate
|
|
4
|
-
|
|
5
|
-
from thestage.config import THESTAGE_LOCAL_LANGUAGE
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def __(original: str, placeholders: Optional[dict] = None) -> str:
|
|
9
|
-
return translate(THESTAGE_LOCAL_LANGUAGE, original, placeholders)
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from python_gettext_translations.translations import translate
|
|
4
|
+
|
|
5
|
+
from thestage.config import THESTAGE_LOCAL_LANGUAGE
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def __(original: str, placeholders: Optional[dict] = None) -> str:
|
|
9
|
+
return translate(THESTAGE_LOCAL_LANGUAGE, original, placeholders)
|
thestage/main.py
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
from thestage.helpers import exception_hook
|
|
2
|
-
import traceback
|
|
3
|
-
|
|
4
|
-
from thestage.cli_command_helper import get_command_group_help_panel
|
|
5
|
-
from thestage.helpers.logger.app_logger import app_logger, get_log_path_from_os
|
|
6
|
-
from thestage.services.service_factory import ServiceFactory
|
|
7
|
-
from rich import print
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def main():
|
|
11
|
-
service_factory = ServiceFactory()
|
|
12
|
-
config_provider = service_factory.get_config_provider()
|
|
13
|
-
config = config_provider.build_config()
|
|
14
|
-
|
|
15
|
-
try:
|
|
16
|
-
try:
|
|
17
|
-
api_client = service_factory.get_thestage_api_client()
|
|
18
|
-
token_info = api_client.validate_token(config.main.thestage_auth_token)
|
|
19
|
-
config_provider.update_allowed_commands_and_is_token_valid(validate_token_response=token_info)
|
|
20
|
-
except Exception as e:
|
|
21
|
-
app_logger.error(f'{traceback.format_exc()}')
|
|
22
|
-
print('Unexpected error occurred') # TODO inquire what we want here if backend is offline
|
|
23
|
-
print(f'Application logs path: {str(get_log_path_from_os())}')
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
from thestage.controllers import base_controller, container_controller, instance_controller, project_controller, \
|
|
27
|
-
config_controller
|
|
28
|
-
|
|
29
|
-
base_controller.app.add_typer(project_controller.app, name="project", rich_help_panel=get_command_group_help_panel())
|
|
30
|
-
base_controller.app.add_typer(container_controller.app, name="container", rich_help_panel=get_command_group_help_panel())
|
|
31
|
-
base_controller.app.add_typer(instance_controller.app, name="instance", rich_help_panel=get_command_group_help_panel())
|
|
32
|
-
base_controller.app.add_typer(config_controller.app, name="config", rich_help_panel=get_command_group_help_panel())
|
|
33
|
-
|
|
34
|
-
base_controller.app()
|
|
35
|
-
except KeyboardInterrupt:
|
|
36
|
-
print('THESTAGE: Keyboard Interrupt')
|
|
1
|
+
from thestage.helpers import exception_hook
|
|
2
|
+
import traceback
|
|
3
|
+
|
|
4
|
+
from thestage.cli_command_helper import get_command_group_help_panel
|
|
5
|
+
from thestage.helpers.logger.app_logger import app_logger, get_log_path_from_os
|
|
6
|
+
from thestage.services.service_factory import ServiceFactory
|
|
7
|
+
from rich import print
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
service_factory = ServiceFactory()
|
|
12
|
+
config_provider = service_factory.get_config_provider()
|
|
13
|
+
config = config_provider.build_config()
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
try:
|
|
17
|
+
api_client = service_factory.get_thestage_api_client()
|
|
18
|
+
token_info = api_client.validate_token(config.main.thestage_auth_token)
|
|
19
|
+
config_provider.update_allowed_commands_and_is_token_valid(validate_token_response=token_info)
|
|
20
|
+
except Exception as e:
|
|
21
|
+
app_logger.error(f'{traceback.format_exc()}')
|
|
22
|
+
print('Unexpected error occurred') # TODO inquire what we want here if backend is offline
|
|
23
|
+
print(f'Application logs path: {str(get_log_path_from_os())}')
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
from thestage.controllers import base_controller, container_controller, instance_controller, project_controller, \
|
|
27
|
+
config_controller
|
|
28
|
+
|
|
29
|
+
base_controller.app.add_typer(project_controller.app, name="project", rich_help_panel=get_command_group_help_panel())
|
|
30
|
+
base_controller.app.add_typer(container_controller.app, name="container", rich_help_panel=get_command_group_help_panel())
|
|
31
|
+
base_controller.app.add_typer(instance_controller.app, name="instance", rich_help_panel=get_command_group_help_panel())
|
|
32
|
+
base_controller.app.add_typer(config_controller.app, name="config", rich_help_panel=get_command_group_help_panel())
|
|
33
|
+
|
|
34
|
+
base_controller.app()
|
|
35
|
+
except KeyboardInterrupt:
|
|
36
|
+
print('THESTAGE: Keyboard Interrupt')
|
thestage/services/.env
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
THESTAGE_CONFIG_DIR=.thestage
|
|
2
|
-
THESTAGE_CONFIG_FILE=config.json
|
|
3
|
-
THESTAGE_CLI_ENV=DEV
|
|
4
|
-
THESTAGE_API_URL=http://localhost:8100
|
|
5
|
-
THESTAGE_API_URL=http://localhost:8100
|
|
6
|
-
LOG_FILE=thestage.log
|
|
1
|
+
THESTAGE_CONFIG_DIR=.thestage
|
|
2
|
+
THESTAGE_CONFIG_FILE=config.json
|
|
3
|
+
THESTAGE_CLI_ENV=DEV
|
|
4
|
+
THESTAGE_API_URL=http://localhost:8100
|
|
5
|
+
THESTAGE_API_URL=http://localhost:8100
|
|
6
|
+
LOG_FILE=thestage.log
|
thestage/services/__init__.py
CHANGED
|
File without changes
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
from abc import ABC, abstractmethod
|
|
2
|
-
from typing import Any, Optional, Tuple
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class AbstractMapper(ABC):
|
|
6
|
-
|
|
7
|
-
@abstractmethod
|
|
8
|
-
def build_entity(self, item: Any) -> Optional[Any]:
|
|
9
|
-
raise NotImplementedError()
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Any, Optional, Tuple
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AbstractMapper(ABC):
|
|
6
|
+
|
|
7
|
+
@abstractmethod
|
|
8
|
+
def build_entity(self, item: Any) -> Optional[Any]:
|
|
9
|
+
raise NotImplementedError()
|
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
from abc import ABC
|
|
2
|
-
from typing import List, Dict, Any, Optional
|
|
3
|
-
|
|
4
|
-
import typer
|
|
5
|
-
from tabulate import tabulate
|
|
6
|
-
from thestage.i18n.translation import __
|
|
7
|
-
from thestage.services.abstract_mapper import AbstractMapper
|
|
8
|
-
from thestage.services.clients.thestage_api.dtos.paginated_entity_list import PaginatedEntityList
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class AbstractService(ABC):
|
|
12
|
-
# TODO remove recursion
|
|
13
|
-
def print(
|
|
14
|
-
self,
|
|
15
|
-
func_get_data,
|
|
16
|
-
func_special_params: Dict[str, Any],
|
|
17
|
-
mapper: AbstractMapper,
|
|
18
|
-
headers: List[str],
|
|
19
|
-
row: int = 5,
|
|
20
|
-
page: int = 1,
|
|
21
|
-
show_index: str = 'always',
|
|
22
|
-
max_col_width: List[Optional[int]] = None,
|
|
23
|
-
depth: int = 0,
|
|
24
|
-
):
|
|
25
|
-
paginated_entity_list: PaginatedEntityList = func_get_data(
|
|
26
|
-
row=row,
|
|
27
|
-
page=page,
|
|
28
|
-
**func_special_params,
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
result = list(map(lambda x: mapper.build_entity(x), paginated_entity_list.entities))
|
|
32
|
-
|
|
33
|
-
if result:
|
|
34
|
-
raw_data = [list(item.model_dump(
|
|
35
|
-
by_alias=True,
|
|
36
|
-
).values()) for item in result]
|
|
37
|
-
else:
|
|
38
|
-
if depth == 0:
|
|
39
|
-
typer.echo(__("No items found"))
|
|
40
|
-
else:
|
|
41
|
-
typer.echo(__("Listing completed"))
|
|
42
|
-
raise typer.Exit(0)
|
|
43
|
-
|
|
44
|
-
# tabulate() crashes on any None value, check mappers
|
|
45
|
-
|
|
46
|
-
typer.echo(__(
|
|
47
|
-
"Current page: %page% | Total pages: %total_pages% | Items per page: %limit%",
|
|
48
|
-
{
|
|
49
|
-
'page': str(page),
|
|
50
|
-
'limit': str(row),
|
|
51
|
-
'total_pages': str(paginated_entity_list.pagination_data.total_pages),
|
|
52
|
-
}
|
|
53
|
-
))
|
|
54
|
-
|
|
55
|
-
typer.echo(tabulate(
|
|
56
|
-
raw_data,
|
|
57
|
-
headers=headers,
|
|
58
|
-
showindex=show_index,
|
|
59
|
-
tablefmt="double_grid",
|
|
60
|
-
maxcolwidths=max_col_width,
|
|
61
|
-
))
|
|
62
|
-
|
|
63
|
-
if page >= paginated_entity_list.pagination_data.total_pages:
|
|
64
|
-
typer.echo(__("Listing completed"))
|
|
65
|
-
raise typer.Exit(0)
|
|
66
|
-
|
|
67
|
-
next_page: int = typer.prompt(
|
|
68
|
-
text=__('Go to next page (0 to exit)?'),
|
|
69
|
-
default=page + 1,
|
|
70
|
-
show_choices=False,
|
|
71
|
-
type=int,
|
|
72
|
-
show_default=True,
|
|
73
|
-
)
|
|
74
|
-
if next_page == 0:
|
|
75
|
-
raise typer.Exit(0)
|
|
76
|
-
else:
|
|
77
|
-
self.print(
|
|
78
|
-
func_get_data=func_get_data,
|
|
79
|
-
func_special_params=func_special_params,
|
|
80
|
-
mapper=mapper,
|
|
81
|
-
headers=headers,
|
|
82
|
-
row=row,
|
|
83
|
-
page=next_page,
|
|
84
|
-
max_col_width=max_col_width,
|
|
85
|
-
show_index=show_index,
|
|
86
|
-
depth=depth + 1,
|
|
87
|
-
)
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from typing import List, Dict, Any, Optional
|
|
3
|
+
|
|
4
|
+
import typer
|
|
5
|
+
from tabulate import tabulate
|
|
6
|
+
from thestage.i18n.translation import __
|
|
7
|
+
from thestage.services.abstract_mapper import AbstractMapper
|
|
8
|
+
from thestage.services.clients.thestage_api.dtos.paginated_entity_list import PaginatedEntityList
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AbstractService(ABC):
|
|
12
|
+
# TODO remove recursion
|
|
13
|
+
def print(
|
|
14
|
+
self,
|
|
15
|
+
func_get_data,
|
|
16
|
+
func_special_params: Dict[str, Any],
|
|
17
|
+
mapper: AbstractMapper,
|
|
18
|
+
headers: List[str],
|
|
19
|
+
row: int = 5,
|
|
20
|
+
page: int = 1,
|
|
21
|
+
show_index: str = 'always',
|
|
22
|
+
max_col_width: List[Optional[int]] = None,
|
|
23
|
+
depth: int = 0,
|
|
24
|
+
):
|
|
25
|
+
paginated_entity_list: PaginatedEntityList = func_get_data(
|
|
26
|
+
row=row,
|
|
27
|
+
page=page,
|
|
28
|
+
**func_special_params,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
result = list(map(lambda x: mapper.build_entity(x), paginated_entity_list.entities))
|
|
32
|
+
|
|
33
|
+
if result:
|
|
34
|
+
raw_data = [list(item.model_dump(
|
|
35
|
+
by_alias=True,
|
|
36
|
+
).values()) for item in result]
|
|
37
|
+
else:
|
|
38
|
+
if depth == 0:
|
|
39
|
+
typer.echo(__("No items found"))
|
|
40
|
+
else:
|
|
41
|
+
typer.echo(__("Listing completed"))
|
|
42
|
+
raise typer.Exit(0)
|
|
43
|
+
|
|
44
|
+
# tabulate() crashes on any None value, check mappers
|
|
45
|
+
|
|
46
|
+
typer.echo(__(
|
|
47
|
+
"Current page: %page% | Total pages: %total_pages% | Items per page: %limit%",
|
|
48
|
+
{
|
|
49
|
+
'page': str(page),
|
|
50
|
+
'limit': str(row),
|
|
51
|
+
'total_pages': str(paginated_entity_list.pagination_data.total_pages),
|
|
52
|
+
}
|
|
53
|
+
))
|
|
54
|
+
|
|
55
|
+
typer.echo(tabulate(
|
|
56
|
+
raw_data,
|
|
57
|
+
headers=headers,
|
|
58
|
+
showindex=show_index,
|
|
59
|
+
tablefmt="double_grid",
|
|
60
|
+
maxcolwidths=max_col_width,
|
|
61
|
+
))
|
|
62
|
+
|
|
63
|
+
if page >= paginated_entity_list.pagination_data.total_pages:
|
|
64
|
+
typer.echo(__("Listing completed"))
|
|
65
|
+
raise typer.Exit(0)
|
|
66
|
+
|
|
67
|
+
next_page: int = typer.prompt(
|
|
68
|
+
text=__('Go to next page (0 to exit)?'),
|
|
69
|
+
default=page + 1,
|
|
70
|
+
show_choices=False,
|
|
71
|
+
type=int,
|
|
72
|
+
show_default=True,
|
|
73
|
+
)
|
|
74
|
+
if next_page == 0:
|
|
75
|
+
raise typer.Exit(0)
|
|
76
|
+
else:
|
|
77
|
+
self.print(
|
|
78
|
+
func_get_data=func_get_data,
|
|
79
|
+
func_special_params=func_special_params,
|
|
80
|
+
mapper=mapper,
|
|
81
|
+
headers=headers,
|
|
82
|
+
row=row,
|
|
83
|
+
page=next_page,
|
|
84
|
+
max_col_width=max_col_width,
|
|
85
|
+
show_index=show_index,
|
|
86
|
+
depth=depth + 1,
|
|
87
|
+
)
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
import click
|
|
4
|
-
import typer
|
|
5
|
-
|
|
6
|
-
from thestage.services.config_provider.config_provider import ConfigProvider
|
|
7
|
-
from thestage.services.core_files.config_entity import ConfigEntity
|
|
8
|
-
from thestage.i18n.translation import __
|
|
9
|
-
from thestage.entities.enums.yes_no_response import YesOrNoResponse
|
|
10
|
-
from thestage.services.validation_service import ValidationService
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class AppConfigService:
|
|
14
|
-
|
|
15
|
-
__validation_service: ValidationService
|
|
16
|
-
|
|
17
|
-
def __init__(
|
|
18
|
-
self,
|
|
19
|
-
validation_service: ValidationService,
|
|
20
|
-
config_provider: ConfigProvider,
|
|
21
|
-
):
|
|
22
|
-
self.__validation_service = validation_service
|
|
23
|
-
self.__config_provider = config_provider
|
|
24
|
-
|
|
25
|
-
def app_change_token(
|
|
26
|
-
self,
|
|
27
|
-
token: str,
|
|
28
|
-
):
|
|
29
|
-
config = self.__config_provider.get_config()
|
|
30
|
-
|
|
31
|
-
if config.main.thestage_auth_token:
|
|
32
|
-
response: YesOrNoResponse = typer.prompt(
|
|
33
|
-
text=__('Do you want to change current token?'),
|
|
34
|
-
show_choices=True,
|
|
35
|
-
default=YesOrNoResponse.YES.value,
|
|
36
|
-
type=click.Choice([r.value for r in YesOrNoResponse]),
|
|
37
|
-
show_default=True,
|
|
38
|
-
)
|
|
39
|
-
if response == YesOrNoResponse.NO:
|
|
40
|
-
raise typer.Exit(0)
|
|
41
|
-
|
|
42
|
-
config.main.thestage_auth_token = token
|
|
43
|
-
self.__config_provider.update_config(updated_config=config)
|
|
44
|
-
self.__validation_service.check_token()
|
|
45
|
-
self.__config_provider.save_config()
|
|
46
|
-
|
|
47
|
-
@staticmethod
|
|
48
|
-
def app_remove_env():
|
|
49
|
-
os.unsetenv('THESTAGE_CONFIG_FILE')
|
|
50
|
-
os.unsetenv('THESTAGE_API_URL')
|
|
51
|
-
os.unsetenv('THESTAGE_LOG_FILE')
|
|
52
|
-
os.unsetenv('THESTAGE_AUTH_TOKEN')
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
import typer
|
|
5
|
+
|
|
6
|
+
from thestage.services.config_provider.config_provider import ConfigProvider
|
|
7
|
+
from thestage.services.core_files.config_entity import ConfigEntity
|
|
8
|
+
from thestage.i18n.translation import __
|
|
9
|
+
from thestage.entities.enums.yes_no_response import YesOrNoResponse
|
|
10
|
+
from thestage.services.validation_service import ValidationService
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AppConfigService:
|
|
14
|
+
|
|
15
|
+
__validation_service: ValidationService
|
|
16
|
+
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
validation_service: ValidationService,
|
|
20
|
+
config_provider: ConfigProvider,
|
|
21
|
+
):
|
|
22
|
+
self.__validation_service = validation_service
|
|
23
|
+
self.__config_provider = config_provider
|
|
24
|
+
|
|
25
|
+
def app_change_token(
|
|
26
|
+
self,
|
|
27
|
+
token: str,
|
|
28
|
+
):
|
|
29
|
+
config = self.__config_provider.get_config()
|
|
30
|
+
|
|
31
|
+
if config.main.thestage_auth_token:
|
|
32
|
+
response: YesOrNoResponse = typer.prompt(
|
|
33
|
+
text=__('Do you want to change current token?'),
|
|
34
|
+
show_choices=True,
|
|
35
|
+
default=YesOrNoResponse.YES.value,
|
|
36
|
+
type=click.Choice([r.value for r in YesOrNoResponse]),
|
|
37
|
+
show_default=True,
|
|
38
|
+
)
|
|
39
|
+
if response == YesOrNoResponse.NO:
|
|
40
|
+
raise typer.Exit(0)
|
|
41
|
+
|
|
42
|
+
config.main.thestage_auth_token = token
|
|
43
|
+
self.__config_provider.update_config(updated_config=config)
|
|
44
|
+
self.__validation_service.check_token()
|
|
45
|
+
self.__config_provider.save_config()
|
|
46
|
+
|
|
47
|
+
@staticmethod
|
|
48
|
+
def app_remove_env():
|
|
49
|
+
os.unsetenv('THESTAGE_CONFIG_FILE')
|
|
50
|
+
os.unsetenv('THESTAGE_API_URL')
|
|
51
|
+
os.unsetenv('THESTAGE_LOG_FILE')
|
|
52
|
+
os.unsetenv('THESTAGE_AUTH_TOKEN')
|
|
File without changes
|
|
File without changes
|