pyegeria 5.3.9.3__py3-none-any.whl → 5.3.9.5__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.
@@ -0,0 +1,225 @@
1
+ """
2
+ This file contains glossary-related command functions for processing Egeria Markdown
3
+ """
4
+ from typing import Optional
5
+
6
+ from rich.markdown import Markdown
7
+
8
+ from pyegeria.egeria_tech_client import EgeriaTech
9
+ from pyegeria.md_processing.utils.common_utils import (
10
+ debug_level, print_msg, ALWAYS, ERROR, INFO, WARNING, pre_command, command_seperator, EXISTS_REQUIRED
11
+ )
12
+ from pyegeria.md_processing.utils.extraction_utils import (
13
+ extract_command_plus, extract_command, process_simple_attribute
14
+ )
15
+ from pyegeria.md_processing.utils.validation_utils import (
16
+ process_element_identifiers, update_a_command
17
+ )
18
+ from pyegeria.md_processing.utils.display_utils import (
19
+ GLOSSARY_NAME_LABELS
20
+ )
21
+ from pyegeria.dr_egeria_state import update_element_dictionary
22
+
23
+ def process_glossary_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
24
+ """
25
+ Processes a glossary create or update command by extracting key attributes such as
26
+ glossary name, language, description, and usage from the given text.
27
+
28
+ :param txt: A string representing the input cell to be processed for
29
+ extracting glossary-related attributes.
30
+ :param directive: an optional string indicating the directive to be used - display, validate or execute
31
+ :return: A string summarizing the outcome of the processing.
32
+ """
33
+
34
+ command, object_type, object_action = extract_command_plus(txt)
35
+ from pyegeria.md_processing.utils.common_utils import set_debug_level
36
+ set_debug_level(directive)
37
+
38
+ glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, ERROR)
39
+ print(Markdown(
40
+ f"{pre_command} `{object_action}` `{object_type}` for glossary: `\'{glossary_name}\'` with directive: `"
41
+ f"{directive}` "))
42
+ language = process_simple_attribute(txt, ['Language'], INFO)
43
+ description = process_simple_attribute(txt, ['Description'], INFO)
44
+ usage = process_simple_attribute(txt, ['Usage'], INFO)
45
+ q_name = process_simple_attribute(txt, ['Qualified Name'], INFO)
46
+ valid = True
47
+
48
+ if glossary_name is None:
49
+ valid = False
50
+ known_q_name = None
51
+ known_guid = None
52
+ glossary_exists = False
53
+ else:
54
+ element_labels = GLOSSARY_NAME_LABELS
55
+ element_labels.append('Display Name')
56
+ known_q_name, known_guid, valid, glossary_exists = process_element_identifiers(egeria_client, object_type,
57
+ element_labels, txt,
58
+ object_action, None)
59
+ glossary_display = (f"\n* Command: `{command}`\n\t* Glossary Name: {glossary_name}\n\t"
60
+ f"* Language: {language}\n\t* Description:\n{description}\n"
61
+ f"* Usage: {usage}\n")
62
+
63
+ if object_action == 'Update':
64
+ guid = process_simple_attribute(txt, ['GUID', 'guid', 'Guid'])
65
+ glossary_display += f"* Qualified Name: `{q_name}`\n\t* GUID: {guid}\n\n"
66
+ if not glossary_exists:
67
+ msg = f"Glossary can't be updated; `{glossary_name}` not found"
68
+ print_msg("ERROR", msg, debug_level)
69
+ valid = False
70
+ else:
71
+ msg = f"Glossary can be updated; `{glossary_name}` found"
72
+ print_msg(ALWAYS, msg, debug_level)
73
+
74
+
75
+ elif object_action == "Create":
76
+ if glossary_exists:
77
+ msg = f"Glossary `{glossary_name}` can't be created because it already exists.\n"
78
+ print_msg("ERROR", msg, debug_level)
79
+ valid = False
80
+ elif valid:
81
+ msg = f"It is valid to create Glossary `{glossary_name}` with:\n"
82
+ print_msg("ALWAYS", msg, debug_level)
83
+
84
+ if directive == "display":
85
+ print(Markdown(glossary_display))
86
+ return None
87
+
88
+ elif directive == "validate":
89
+ if valid:
90
+ print(Markdown(glossary_display))
91
+ else:
92
+ msg = f"Validation failed for Glossary `{glossary_name}`\n"
93
+ print_msg(ERROR, msg, debug_level)
94
+ print(Markdown(glossary_display))
95
+
96
+ return valid
97
+
98
+ elif directive == "process":
99
+ if valid:
100
+ print(Markdown(glossary_display))
101
+ else:
102
+ if glossary_exists and object_action == "Create":
103
+ msg = f"Create failed because glossary `{glossary_name}` exists - changing `Create` to `Update` in processed output \n"
104
+ print_msg(ERROR, msg, debug_level)
105
+ print(Markdown(glossary_display))
106
+ return update_a_command(txt, command, object_type, known_q_name, known_guid)
107
+ else:
108
+ return None
109
+ if object_action == "Update":
110
+ if not glossary_exists:
111
+ print(f"\n{ERROR}Glossary `{glossary_name}` does not exist! Updating result document with Create "
112
+ f"command\n")
113
+ return update_a_command(txt, command, object_type, known_q_name, known_guid)
114
+
115
+ body = {
116
+ "class": "ReferenceableRequestBody", "elementProperties": {
117
+ "class": "GlossaryProperties", "qualifiedName": known_q_name, "description": description,
118
+ "language": language, "usage": usage
119
+ }
120
+ }
121
+ egeria_client.update_glossary(known_guid, body)
122
+ print_msg(ALWAYS, f"Updated Glossary `{glossary_name}` with GUID {known_guid}", debug_level)
123
+ update_element_dictionary(known_q_name, {
124
+ 'guid': known_guid, 'display_name': glossary_name
125
+ })
126
+ return egeria_client.get_glossary_by_guid(known_guid, output_format='MD')
127
+ elif object_action == "Create":
128
+ glossary_guid = None
129
+
130
+ if glossary_exists:
131
+ print(f"\nGlossary `{glossary_name}` already exists and result document updated\n")
132
+ return update_a_command(txt, command, object_type, known_q_name, known_guid)
133
+ else:
134
+ glossary_guid = egeria_client.create_glossary(glossary_name, description, language, usage)
135
+ if glossary_guid:
136
+ print_msg(ALWAYS, f"Created Glossary `{glossary_name}` with GUID {glossary_guid}", debug_level)
137
+ return egeria_client.get_glossary_by_guid(glossary_guid, output_format='MD')
138
+ else:
139
+ print_msg(ERROR, f"Failed to create Glossary `{glossary_name}`", debug_level)
140
+ return None
141
+ else:
142
+ return None
143
+ else:
144
+ return None
145
+
146
+ def process_glossary_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
147
+ """
148
+ Processes a glossary list command by extracting key attributes such as
149
+ output format and search string from the given text.
150
+
151
+ :param txt: A string representing the input cell to be processed for
152
+ extracting glossary-related attributes.
153
+ :param directive: an optional string indicating the directive to be used - display, validate or execute
154
+ :return: A string summarizing the outcome of the processing.
155
+ """
156
+ from pyegeria.md_processing.utils.common_utils import set_debug_level
157
+ from pyegeria.md_processing.utils.display_utils import OUTPUT_LABELS, SEARCH_LABELS, ELEMENT_OUTPUT_FORMATS
158
+
159
+ command = extract_command(txt)
160
+ set_debug_level(directive)
161
+ print(Markdown(f"{pre_command} `{command}` with directive: `{directive}`"))
162
+
163
+ output_format = process_simple_attribute(txt, OUTPUT_LABELS)
164
+ output_format = output_format.upper() if output_format else "MD"
165
+ if output_format not in ELEMENT_OUTPUT_FORMATS:
166
+ print_msg(WARNING, f"Output format {output_format} not recognized, using MD", debug_level)
167
+ output_format = "MD"
168
+
169
+ search_string = process_simple_attribute(txt, SEARCH_LABELS)
170
+
171
+ if directive == "display":
172
+ print(Markdown(f"\n* Command: {command}\n\t* Output Format: {output_format}\n\t* Search String: {search_string}"))
173
+ return None
174
+ elif directive == "validate":
175
+ print(Markdown(f"\n* Command: {command}\n\t* Output Format: {output_format}\n\t* Search String: {search_string}"))
176
+ return True
177
+ elif directive == "process":
178
+ print(Markdown(f"\n* Command: {command}\n\t* Output Format: {output_format}\n\t* Search String: {search_string}"))
179
+ return egeria_client.list_glossaries(output_format=output_format, search_string=search_string)
180
+
181
+
182
+ def process_glossary_structure_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
183
+ """
184
+ Processes a glossary structure command by extracting key attributes such as
185
+ glossary name and output format from the given text.
186
+
187
+ :param txt: A string representing the input cell to be processed for
188
+ extracting glossary-related attributes.
189
+ :param directive: an optional string indicating the directive to be used - display, validate or execute
190
+ :return: A string summarizing the outcome of the processing.
191
+ """
192
+ from pyegeria.md_processing.utils.common_utils import set_debug_level
193
+ from pyegeria.md_processing.utils.display_utils import OUTPUT_LABELS, ELEMENT_OUTPUT_FORMATS
194
+
195
+ command = extract_command(txt)
196
+ set_debug_level(directive)
197
+ print(Markdown(f"{pre_command} `{command}` with directive: `{directive}`"))
198
+
199
+ glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, ERROR)
200
+ output_format = process_simple_attribute(txt, OUTPUT_LABELS)
201
+ output_format = output_format.upper() if output_format else "MD"
202
+ if output_format not in ELEMENT_OUTPUT_FORMATS:
203
+ print_msg(WARNING, f"Output format {output_format} not recognized, using MD", debug_level)
204
+ output_format = "MD"
205
+
206
+ if glossary_name is None:
207
+ print_msg(ERROR, "No glossary name found", debug_level)
208
+ return None
209
+
210
+ known_q_name, known_guid, valid, glossary_exists = process_element_identifiers(egeria_client, "Glossary",
211
+ GLOSSARY_NAME_LABELS, txt,
212
+ EXISTS_REQUIRED, None)
213
+ if not glossary_exists:
214
+ print_msg(ERROR, f"Glossary {glossary_name} not found", debug_level)
215
+ return None
216
+
217
+ if directive == "display":
218
+ print(Markdown(f"\n* Command: {command}\n\t* Glossary Name: {glossary_name}\n\t* Output Format: {output_format}"))
219
+ return None
220
+ elif directive == "validate":
221
+ print(Markdown(f"\n* Command: {command}\n\t* Glossary Name: {glossary_name}\n\t* Output Format: {output_format}"))
222
+ return True
223
+ elif directive == "process":
224
+ print(Markdown(f"\n* Command: {command}\n\t* Glossary Name: {glossary_name}\n\t* Output Format: {output_format}"))
225
+ return egeria_client.get_glossary_structure(known_guid, output_format=output_format)
@@ -0,0 +1,169 @@
1
+ """
2
+ This file contains project-related command functions for processing Egeria Markdown
3
+ """
4
+ from typing import Optional, Tuple
5
+
6
+ from rich.markdown import Markdown
7
+
8
+ from pyegeria.project_manager_omvs import ProjectManager
9
+ from pyegeria.md_processing.utils.common_utils import (
10
+ debug_level, print_msg, ALWAYS, ERROR, INFO, WARNING, pre_command, command_seperator, is_valid_iso_date
11
+ )
12
+ from pyegeria.md_processing.utils.extraction_utils import (
13
+ extract_command, process_simple_attribute
14
+ )
15
+ from pyegeria.md_processing.utils.display_utils import (
16
+ PROJECT_NAME_LABELS
17
+ )
18
+ from pyegeria._globals import NO_PROJECTS_FOUND
19
+
20
+ def process_per_proj_upsert_command(egeria_client: ProjectManager, txt: str, directive: str = "display") -> str | None:
21
+ """
22
+ Processes a personal project create or update command by extracting key attributes such as
23
+ glossary name, language, description, and usage from the given cell.
24
+
25
+ :param txt: A string representing the input cell to be processed for
26
+ extracting glossary-related attributes.
27
+ :param directive: an optional string indicating the directive to be used - display, validate or execute
28
+ :return: A string summarizing the outcome of the processing.
29
+ """
30
+ from pyegeria.md_processing.utils.common_utils import set_debug_level
31
+
32
+ command = extract_command(txt)
33
+ object = command.split()
34
+ object_type = f"{object[1]} {object[2]}"
35
+ object_action = object[0]
36
+ set_debug_level(directive)
37
+
38
+ project_name = process_simple_attribute(txt, ['Project Name'])
39
+ description = process_simple_attribute(txt, ['Description'])
40
+ project_identifier = process_simple_attribute(txt, ['Project Identifier'])
41
+ project_status = process_simple_attribute(txt, ['Project Status'])
42
+ project_phase = process_simple_attribute(txt, ['Project Phase'])
43
+ project_health = process_simple_attribute(txt, ['Project Health'])
44
+ start_date = process_simple_attribute(txt, ['Start Date'])
45
+ planned_end_date = process_simple_attribute(txt, ['Planned End Date'])
46
+ print(Markdown(f"{pre_command} `\'{command}\'` for project: `{project_name}` with directive: `{directive}` "))
47
+
48
+ project_display = (f"\n* Command: {command}\n\t* Project: {project_name}\n\t"
49
+ f"* Status: {project_status}\n\t* Description: {description}\n\t"
50
+ f"* Phase: {project_phase}\n\t* Health: {project_health}\n\t"
51
+ f"* Start Date: {start_date}\n\t* Planned End Date: {planned_end_date}\n")
52
+
53
+ def validate_project(obj_action: str) -> tuple[bool, bool, str, str]:
54
+ valid = True
55
+ msg = ""
56
+ known_guid = None
57
+ known_q_name = None
58
+
59
+ project_details = egeria_client.get_projects_by_name(project_name)
60
+ if project_details == NO_PROJECTS_FOUND:
61
+ project_exists = False
62
+ else:
63
+ project_exists = True
64
+
65
+ if project_name is None:
66
+ msg = f"* {ERROR}Project name is missing\n"
67
+ valid = False
68
+ if project_status is None:
69
+ msg += f"* {INFO}No Project status found\n"
70
+
71
+ if description is None:
72
+ msg += f"* {INFO}No Description found\n"
73
+
74
+ if project_identifier is None:
75
+ msg += f"* {INFO}No Project Identifier found\n"
76
+
77
+ if project_phase is None:
78
+ msg += f"* {INFO}No Project Phase found\n"
79
+
80
+ if project_health is None:
81
+ msg += f"* {INFO}No Project Health found\n"
82
+
83
+ if start_date is None:
84
+ msg += f"* {INFO}No Start Date found\n"
85
+ elif not is_valid_iso_date(start_date):
86
+ msg += f"* {ERROR}Start Date is not a valid ISO date of form YYYY-MM-DD\n"
87
+ valid = False
88
+
89
+ if planned_end_date is None:
90
+ msg += f"* {INFO} No Planned End Date found\n"
91
+ elif not is_valid_iso_date(planned_end_date):
92
+ msg += f"* {ERROR}Planned End Date is not a valid ISO date of form YYYY-MM-DD\n"
93
+ valid = False
94
+
95
+ if obj_action == "Update":
96
+ q_name = process_simple_attribute(txt, 'Qualified Name')
97
+
98
+ if not project_exists:
99
+ msg += f"* {ERROR}Project {project_name} does not exist\n"
100
+ valid = False
101
+ if len(project_details) > 1 and project_exists:
102
+ msg += f"* {ERROR}More than one project with name {project_name} found\n"
103
+ valid = False
104
+ if len(project_details) == 1:
105
+ known_guid = project_details[0]['elementHeader'].get('guid', None)
106
+ known_q_name = project_details[0]['glossaryProperties'].get('qualifiedName', None)
107
+ if q_name is None:
108
+ msg += f"* {INFO}Qualified Name is missing => can use known qualified name of {known_q_name}\n"
109
+ valid = True
110
+ elif q_name != known_q_name:
111
+ msg += (f"* {ERROR}Project {project_name} qualifiedName mismatch between {q_name} and {known_q_name}\n")
112
+ valid = False
113
+ if valid:
114
+ msg += project_display
115
+ msg += f"* -->Project {project_name} exists and can be updated\n"
116
+ else:
117
+ msg += f"* --> validation failed\n"
118
+ msg += '---'
119
+ print(Markdown(msg))
120
+ return valid, project_exists, known_guid, known_q_name
121
+
122
+ elif obj_action == "Create":
123
+ if project_exists:
124
+ msg += f"\n{ERROR}Project {project_name} already exists"
125
+ else:
126
+ msg += f"\n-->It is valid to create Project \'{project_name}\' with:\n"
127
+ print(Markdown(msg))
128
+ return valid, project_exists, known_guid, known_q_name
129
+
130
+ if directive == "display":
131
+ print(Markdown(project_display))
132
+ return None
133
+ elif directive == "validate":
134
+ valid, project_exists, known_guid, known_q_name = validate_project(object_action)
135
+ return valid
136
+ elif directive == "process":
137
+ valid, project_exists, known_guid, known_q_name = validate_project(object_action)
138
+ if valid:
139
+ if object_action == "Create":
140
+ if project_exists:
141
+ print(f"\n{ERROR}Project {project_name} already exists\n")
142
+ return None
143
+ else:
144
+ project_guid = egeria_client.create_personal_project(project_name, description, project_identifier,
145
+ project_status, project_phase, project_health,
146
+ start_date, planned_end_date)
147
+ if project_guid:
148
+ print_msg(ALWAYS, f"Created Project {project_name} with GUID {project_guid}", debug_level)
149
+ return egeria_client.get_project_by_guid(project_guid, output_format='MD')
150
+ else:
151
+ print_msg(ERROR, f"Failed to create Project {project_name}", debug_level)
152
+ return None
153
+ elif object_action == "Update":
154
+ if not project_exists:
155
+ print(f"\n{ERROR}Project {project_name} does not exist\n")
156
+ return None
157
+ else:
158
+ project_guid = egeria_client.update_personal_project(known_guid, project_name, description,
159
+ project_identifier, project_status,
160
+ project_phase, project_health, start_date,
161
+ planned_end_date)
162
+ if project_guid:
163
+ print_msg(ALWAYS, f"Updated Project {project_name} with GUID {project_guid}", debug_level)
164
+ return egeria_client.get_project_by_guid(project_guid, output_format='MD')
165
+ else:
166
+ print_msg(ERROR, f"Failed to update Project {project_name}", debug_level)
167
+ return None
168
+ else:
169
+ return None