6
6
from dem .cli .console import stdout , stderr
7
7
from dem .core .platform import Platform
8
8
from rich .table import Table
9
+ import typer
9
10
10
11
image_status_messages = {
11
- ToolImage .NOT_AVAILABLE : "[red]Error: Required image is not available![/]" ,
12
- ToolImage .LOCAL_ONLY : "Image is available locally. " ,
13
- ToolImage .REGISTRY_ONLY : "Image is available in the registry. " ,
14
- ToolImage .LOCAL_AND_REGISTRY : "Image is available locally and in the registry. " ,
12
+ ToolImage .NOT_AVAILABLE : "[red]Error: not available![/]" ,
13
+ ToolImage .LOCAL_ONLY : "Local " ,
14
+ ToolImage .REGISTRY_ONLY : "Registry " ,
15
+ ToolImage .LOCAL_AND_REGISTRY : "Local and Registry " ,
15
16
}
16
17
17
- def print_info (dev_env : DevEnv ) -> None :
18
- """ Print information about the given Development Environment.
18
+ def print_local_dev_env_info (dev_env : DevEnv ) -> None :
19
+ """ Print information about the given local Development Environment.
19
20
20
21
Args:
21
22
dev_env -- the Development Environment to print information about
22
23
"""
23
24
tool_info_table = Table ()
24
25
tool_info_table .add_column ("Image" )
25
- tool_info_table .add_column ("Status " )
26
+ tool_info_table .add_column ("Availability " )
26
27
27
- for tool_image in dev_env .tool_images :
28
+ for tool_image in sorted ( dev_env .tool_images , key = lambda x : x . name ) :
28
29
tool_info_table .add_row (tool_image .name ,
29
30
image_status_messages [tool_image .availability ])
31
+ if dev_env .is_installed :
32
+ installation_status = "[green]Installed[/]"
33
+ else :
34
+ installation_status = "Not installed"
35
+ stdout .print (f"\n [bold]Development Environment: { dev_env .name } [/]\n " )
36
+ stdout .print (f"Installation state: { installation_status } \n " )
30
37
stdout .print (tool_info_table )
31
38
32
- def execute (platform : Platform , arg_dev_env_name : str ) -> None :
33
- """ Print information about the given Development Environment.
39
+ if dev_env .is_installed and dev_env .get_tool_image_status () == DevEnv .Status .REINSTALL_NEEDED :
40
+ stderr .print ("\n [red]Error: Incomplete local install! The Dev Env must be reinstalled![/]" )
41
+
42
+ if dev_env .get_tool_image_status () == DevEnv .Status .UNAVAILABLE_IMAGE :
43
+ stderr .print ("\n [red]Error: Required image could not be found either locally or in the registry![/]" )
44
+
45
+ def local_info (platform : Platform , dev_env_name : str ) -> None :
46
+ """ Gather and print information about the given local Development Environment.
34
47
35
48
Args:
36
49
platform -- the platform
37
- arg_dev_env_name -- the name of the Development Environment to print information about
50
+ dev_env_name -- the name of the Development Environment to print information about
51
+
52
+ Raises:
53
+ typer.Abort -- if the Development Environment is unknown
38
54
"""
39
55
platform .assign_tool_image_instances_to_all_dev_envs ()
40
56
41
- dev_env = platform .get_dev_env_by_name (arg_dev_env_name )
57
+ dev_env = platform .get_dev_env_by_name (dev_env_name )
42
58
43
59
if dev_env is None :
44
- for catalog in platform .dev_env_catalogs .catalogs :
60
+ stderr .print (f"[red]Error: Unknown Development Environment: { dev_env_name } [/]\n " )
61
+ raise typer .Abort ()
62
+
63
+ print_local_dev_env_info (dev_env )
64
+
65
+ def print_cat_dev_env_info (dev_env : DevEnv , cat_name : str ) -> None :
66
+ """ Print information about the given catalog Development Environment.
67
+
68
+ Args:
69
+ dev_env -- the Development Environment to print information about
70
+ cat_name -- the name of the catalog the Development Environment belongs to
71
+ """
72
+ tool_info_table = Table ()
73
+ tool_info_table .add_column ("Image" )
74
+ tool_info_table .add_column ("Availability" )
75
+
76
+ for tool_image in sorted (dev_env .tool_images , key = lambda x : x .name ):
77
+ tool_info_table .add_row (tool_image .name ,
78
+ image_status_messages [tool_image .availability ])
79
+ stdout .print (f"\n [bold]Development Environment: { dev_env .name } [/]\n " )
80
+ stdout .print (f"Catalog: { cat_name } \n " )
81
+ stdout .print (tool_info_table )
82
+
83
+ if dev_env .get_tool_image_status () == DevEnv .Status .UNAVAILABLE_IMAGE :
84
+ stderr .print ("\n [red]Error: Required image could not be found in the registry![/]" )
85
+
86
+ def cat_dev_env_info (platform : Platform , dev_env_name : str , selected_cats : list [str ]) -> None :
87
+ """ Gather and print information about the given catalog Development Environment.
88
+
89
+ Args:
90
+ platform -- the platform
91
+ dev_env_name -- the name of the Development Environment to print information about
92
+ selected_cats -- the selected catalog names, empty list means all catalogs
93
+ """
94
+ for catalog in platform .dev_env_catalogs .catalogs :
95
+ if catalog .name in selected_cats or not selected_cats :
45
96
catalog .request_dev_envs ()
46
- dev_env = catalog .get_dev_env_by_name (arg_dev_env_name )
97
+ dev_env = catalog .get_dev_env_by_name (dev_env_name )
47
98
if dev_env :
48
99
dev_env .assign_tool_image_instances (platform .tool_images )
100
+ print_cat_dev_env_info (dev_env , catalog .name )
49
101
break
102
+ else :
103
+ stderr .print (f"[red]Error: Unknown Development Environment: { dev_env_name } [/]\n " )
50
104
51
- if dev_env is None :
52
- stderr .print (f"[red]Error: Unknown Development Environment: { arg_dev_env_name } [/]\n " )
105
+ def selected_cats_info (platform : Platform , dev_env_name : str , selected_cats : list [str ]) -> None :
106
+ """ Print information about the given Development Environment from the selected catalogs.
107
+
108
+ Args:
109
+ platform -- the platform
110
+ dev_env_name -- the name of the Development Environment to print information about
111
+ selected_cats -- the selected catalog names
112
+
113
+ Raises:
114
+ typer.Abort -- if the selected catalog is unknown
115
+ """
116
+ available_cats = set ([cat .name for cat in platform .dev_env_catalogs .catalogs ])
117
+ selected_cats = set (selected_cats )
118
+
119
+ if not selected_cats .issubset (available_cats ):
120
+ stderr .print (f"[red]Error: Unknown catalog(s): { ', ' .join (selected_cats - available_cats )} [/]\n " )
121
+ raise typer .Abort ()
122
+
123
+ cat_dev_env_info (platform , dev_env_name , selected_cats )
124
+
125
+ def all_cats_info (platform : Platform , dev_env_name : str ) -> None :
126
+ """ Print information about the given Development Environment from all catalogs.
127
+
128
+ Args:
129
+ platform -- the platform
130
+ dev_env_name -- the name of the Development Environment to print information about
131
+ """
132
+ cat_dev_env_info (platform , dev_env_name , [])
133
+
134
+ def execute (platform : Platform , arg_dev_env_name : str , cat : bool , selected_cats : list [str ]) -> None :
135
+ """ Print information about the given Development Environment.
136
+
137
+ Args:
138
+ platform -- the platform
139
+ arg_dev_env_name -- the name of the Development Environment to print information about
140
+ cat -- the flag to print information about the Development Environment from the catalogs
141
+ selected_cats -- the selected catalog names
142
+
143
+ Raises:
144
+ typer.Abort -- if the Development Environment is unknown or if the selected catalog is
145
+ unknown
146
+ """
147
+ if not cat :
148
+ local_info (platform , arg_dev_env_name )
149
+ elif selected_cats :
150
+ selected_cats_info (platform , arg_dev_env_name , selected_cats )
53
151
else :
54
- print_info ( dev_env )
152
+ all_cats_info ( platform , arg_dev_env_name )
0 commit comments