pyegeria 5.3.8.1__py3-none-any.whl → 5.3.8.3__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.
pyegeria/__init__.py CHANGED
@@ -94,7 +94,8 @@ from .md_processing_utils import (extract_command, process_glossary_upsert_comma
94
94
  process_categories_upsert_command,
95
95
  get_current_datetime_string, process_per_proj_upsert_command, command_list,
96
96
  render_markdown, process_provenance_command, process_blueprint_upsert_command,
97
- process_solution_component_upsert_command)
97
+ process_solution_component_upsert_command, process_set_categories_parent_command,
98
+ process_term_list_command)
98
99
 
99
100
  #
100
101
  # The following assignments were generated by the `create_tech_guid_lists.py` utility that uses the pyegeria functions
pyegeria/_client.py CHANGED
@@ -784,5 +784,55 @@ class Client:
784
784
  q_name = f"{q_name}::{version_identifier}"
785
785
  return q_name
786
786
 
787
+ def make_preamble(self, obj_type: str, search_string: str, output_format: str = 'MD') -> tuple[str, str | None]:
788
+ """
789
+ Creates a preamble string and an elements action based on the given object type, search string,
790
+ and output format. The preamble provides a descriptive header based on the intent: To make a form,
791
+ a report, or unadorned markdwon. The elements action specifies the action to be taken on the object type.
792
+
793
+ Args:
794
+ obj_type: The type of object being updated or reported on (e.g., "Product", "Category").
795
+ search_string: The search string used to filter objects. Defaults to "All Terms" if None.
796
+ output_format: A format identifier determining the output structure.
797
+ JSON - output standard json
798
+ MD - output standard markdown with no preamble
799
+ FORM - output markdown with a preamble for a form
800
+ REPORT - output markdown with a preamble for a report
801
+
802
+ Returns:
803
+ tuple: A tuple containing:
804
+ - A string representing the formatted update or report preamble.
805
+ - A string or None indicating the action description for the elements,
806
+ depending on the output format.
807
+ """
808
+ search_string = search_string if search_string else "All Elements"
809
+ elements_action = "Update " + obj_type
810
+ if output_format == "FORM":
811
+ preamble = (f"\n# Update {obj_type} Form - created at {datetime.now().strftime('%Y-%m-%d %H:%M')}\n"
812
+ f"\t {obj_type} found from the search string: `{search_string}`\n\n")
813
+
814
+ return preamble, elements_action
815
+ elif output_format == "REPORT":
816
+ elements_md = (f"# {obj_type} Report - created at {datetime.now().strftime('%Y-%m-%d %H:%M')}\n"
817
+ f"\t{obj_type} found from the search string: `{search_string}`\n\n")
818
+ elements_action = None
819
+ return elements_md, elements_action
820
+
821
+ else:
822
+ return "\n", elements_action
823
+
824
+ def make_md_attribute(self, attribute_name: str, attribute_value: str, output_type: str) -> str | None:
825
+ """ Create a markdown attribute line for a given attribute name and value."""
826
+ output = ""
827
+ attribute_value = attribute_value.strip() if attribute_value else ""
828
+ attribute_title = attribute_name.title() if attribute_name else ""
829
+ if output_type in ["FORM", "MD"]:
830
+ output = f"## {attribute_title}\n{attribute_value}\n\n"
831
+ elif output_type == "REPORT":
832
+ if attribute_value:
833
+ output = f"## {attribute_title}\n{attribute_value}\n\n"
834
+ return output
835
+
836
+
787
837
  if __name__ == "__main__":
788
838
  print("Main-__client")
@@ -1,34 +1,26 @@
1
1
  """
2
2
  This is an ongoing experiment in parsing and playing with Freddie docs
3
3
  """
4
- import argparse
5
- import json
6
4
  import os
5
+ from datetime import datetime
6
+
7
+ import click
7
8
  from rich import print
8
9
  from rich.console import Console
9
- from rich.prompt import Prompt
10
10
 
11
-
12
- import click
13
11
  from pyegeria import (extract_command, process_glossary_upsert_command, process_term_upsert_command,
14
12
  process_categories_upsert_command, process_provenance_command,
15
- get_current_datetime_string, process_per_proj_upsert_command, command_list,EgeriaTech,
16
- process_blueprint_upsert_command, process_solution_component_upsert_command,
17
- shared_state
18
- )
19
- from datetime import datetime
13
+ process_set_categories_parent_command, get_current_datetime_string,
14
+ process_per_proj_upsert_command, command_list, EgeriaTech, process_blueprint_upsert_command,
15
+ process_solution_component_upsert_command, dr_egeria_state, process_term_list_command)
20
16
 
21
17
  EGERIA_METADATA_STORE = os.environ.get("EGERIA_METADATA_STORE", "active-metadata-store")
22
18
  EGERIA_KAFKA_ENDPOINT = os.environ.get("KAFKA_ENDPOINT", "localhost:9092")
23
19
  EGERIA_PLATFORM_URL = os.environ.get("EGERIA_PLATFORM_URL", "https://localhost:9443")
24
20
  EGERIA_VIEW_SERVER = os.environ.get("EGERIA_VIEW_SERVER", "view-server")
25
- EGERIA_VIEW_SERVER_URL = os.environ.get(
26
- "EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
27
- )
21
+ EGERIA_VIEW_SERVER_URL = os.environ.get("EGERIA_VIEW_SERVER_URL", "https://localhost:9443")
28
22
  EGERIA_INTEGRATION_DAEMON = os.environ.get("EGERIA_INTEGRATION_DAEMON", "integration-daemon")
29
- EGERIA_INTEGRATION_DAEMON_URL = os.environ.get(
30
- "EGERIA_INTEGRATION_DAEMON_URL", "https://localhost:9443"
31
- )
23
+ EGERIA_INTEGRATION_DAEMON_URL = os.environ.get("EGERIA_INTEGRATION_DAEMON_URL", "https://localhost:9443")
32
24
  EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
33
25
  EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
34
26
  EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
@@ -41,26 +33,17 @@ EGERIA_ROOT_PATH = os.environ.get("EGERIA_ROOT_PATH", "/Users/dwolfson/localGit/
41
33
  EGERIA_INBOX_PATH = os.environ.get("EGERIA_INBOX_PATH", "pyegeria/commands/cat/dr_egeria_inbox")
42
34
  EGERIA_OUTBOX_PATH = os.environ.get("EGERIA_OUTBOX_PATH", "pyegeria/commands/cat/dr_egeria_outbox")
43
35
 
36
+
44
37
  @click.command("process_markdown_file", help="Process a markdown file and return the output as a string.")
45
- @click.option("--file-path", help="File path to markdown file",
46
- default="glossary_test1.md", required=True, prompt=False)
38
+ @click.option("--file-path", help="File path to markdown file", default="glossary_test1.md", required=True,
39
+ prompt=False)
47
40
  @click.option("--directive", default="display", help="How to process the file",
48
- type=click.Choice(["display","validate","process"],case_sensitive=False), prompt=False,)
41
+ type=click.Choice(["display", "validate", "process"], case_sensitive=False), prompt=False, )
49
42
  @click.option("--server", default=EGERIA_VIEW_SERVER, help="Egeria view server to use.")
50
- @click.option(
51
- "--url", default=EGERIA_VIEW_SERVER_URL, help="URL of Egeria platform to connect to"
52
- )
53
-
43
+ @click.option("--url", default=EGERIA_VIEW_SERVER_URL, help="URL of Egeria platform to connect to")
54
44
  @click.option("--userid", default=EGERIA_USER, help="Egeria user")
55
45
  @click.option("--user_pass", default=EGERIA_USER_PASSWORD, help="Egeria user password")
56
- def process_markdown_file(
57
- file_path: str,
58
- directive: str,
59
- server: str,
60
- url: str,
61
- userid: str,
62
- user_pass: str,
63
- )-> None:
46
+ def process_markdown_file(file_path: str, directive: str, server: str, url: str, userid: str, user_pass: str, ) -> None:
64
47
  """
65
48
  Process a markdown file by parsing and executing Dr. Egeria commands. Write output to a new file.
66
49
  """
@@ -82,12 +65,11 @@ def process_markdown_file(
82
65
  final_output = []
83
66
  prov_found = False
84
67
  prov_output = (f"\n# Provenance\n\n* Results from processing file {file_path} on "
85
- f"{datetime.now().strftime("%Y-%m-%d %H:%M")}\n")
68
+ f"{datetime.now().strftime("%Y-%m-%d %H:%M")}\n")
86
69
  h1_blocks = []
87
70
  current_block = ""
88
71
  in_h1_block = False
89
72
 
90
-
91
73
  # Helper function to process the current block
92
74
  def process_current_block(current_block):
93
75
  nonlocal updated, final_output, prov_found, prov_output, h1_blocks, in_h1_block
@@ -103,31 +85,42 @@ def process_markdown_file(
103
85
  prov_found = True
104
86
 
105
87
  elif potential_command in ["Create Glossary", "Update Glossary"]:
106
- result = process_glossary_upsert_command(client, shared_state.get_element_dictionary(), current_block, directive)
88
+ result = process_glossary_upsert_command(client, dr_egeria_state.get_element_dictionary(),
89
+ current_block, directive)
107
90
  elif potential_command in ["Create Category", "Update Category"]:
108
- result = process_categories_upsert_command(client, shared_state.get_element_dictionary(), current_block, directive)
91
+ result = process_categories_upsert_command(client, dr_egeria_state.get_element_dictionary(),
92
+ current_block, directive)
93
+ elif potential_command in ["Set Parent Category", "UnSet Parent Category"]:
94
+ result = process_set_categories_parent_command(client, dr_egeria_state.get_element_dictionary(),
95
+ current_block, directive)
109
96
  elif potential_command in ["Create Term", "Update Term"]:
110
- result = process_term_upsert_command(client, shared_state.get_element_dictionary(), current_block, directive)
97
+ result = process_term_upsert_command(client, dr_egeria_state.get_element_dictionary(), current_block,
98
+ directive)
99
+ elif potential_command in ["List Terms", "List Glossary Terms"]:
100
+ result = process_term_list_command(client, dr_egeria_state.get_element_dictionary(), current_block,
101
+ directive)
111
102
  elif potential_command in ["Create Personal Project", "Update Personal Project"]:
112
- result = process_per_proj_upsert_command(client, shared_state.get_element_dictionary(), current_block, directive)
113
- elif potential_command in ["Create Blueprint", "Update Blueprint", "Create Solution Blueprint", "Update Solution Blueprint"]:
114
- result = process_blueprint_upsert_command(client, shared_state.get_element_dictionary(), current_block, directive)
103
+ result = process_per_proj_upsert_command(client, dr_egeria_state.get_element_dictionary(),
104
+ current_block, directive)
105
+ elif potential_command in ["Create Blueprint", "Update Blueprint", "Create Solution Blueprint",
106
+ "Update Solution Blueprint"]:
107
+ result = process_blueprint_upsert_command(client, dr_egeria_state.get_element_dictionary(),
108
+ current_block, directive)
115
109
  elif potential_command in ["Create Solution Component", "Update Solution Component"]:
116
- result = process_solution_component_upsert_command(client, shared_state.get_element_dictionary(), current_block, directive)
110
+ result = process_solution_component_upsert_command(client, dr_egeria_state.get_element_dictionary(),
111
+ current_block, directive)
117
112
 
118
113
 
119
114
  else:
120
115
  # If command is not recognized, keep the block as-is
121
116
  result = None
122
- # print(json.dumps(shared_state.get_element_dictionary(), indent=4))
117
+ # print(json.dumps(dr_egeria_state.get_element_dictionary(), indent=4))
123
118
  if result:
124
119
  if directive == "process":
125
120
  updated = True
126
- final_output.append(result)
127
- # print(json.dumps(shared_state.get_element_dictionary(), indent=4))
121
+ final_output.append(result) # print(json.dumps(dr_egeria_state.get_element_dictionary(), indent=4))
128
122
  elif directive == "validate":
129
- pass
130
- # print(json.dumps(shared_state.get_element_dictionary(), indent=4))
123
+ pass # print(json.dumps(dr_egeria_state.get_element_dictionary(), indent=4))
131
124
  elif directive == "process":
132
125
  # Handle errors (skip this block but notify the user)
133
126
  print(f"\n==>\tErrors found while processing command: \'{potential_command}\'\n"
@@ -175,7 +168,6 @@ def process_markdown_file(
175
168
  # Join the final output list into a single string
176
169
  final_output = "\n".join(final_output)
177
170
 
178
-
179
171
  try:
180
172
  if updated:
181
173
  path, filename = os.path.split(file_path) # Get both parts
@@ -189,7 +181,8 @@ def process_markdown_file(
189
181
  f2.write(prov_output)
190
182
  click.echo(f"\n==> Output written to {new_file_path}")
191
183
  else:
192
- click.echo("\nNo updates detected. New File not created.")
184
+ if directive != 'display':
185
+ click.echo("\nNo updates detected. New File not created.")
193
186
 
194
187
  except (Exception):
195
188
  console.print_exception(show_locals=True)
@@ -212,7 +205,8 @@ def process_markdown_file(
212
205
  # time_out = args.time_out if args.time_out is not None else 60
213
206
  # try:
214
207
  # file_path = Prompt.ask("Markdown File name to process:", default="")
215
- # directive = Prompt.ask("Processing Directive:", choices=[ "display", "validate", "process"], default="validate")
208
+ # directive = Prompt.ask("Processing Directive:", choices=[ "display", "validate", "process"],
209
+ # default="validate")
216
210
  #
217
211
  # process_markdown_file(file_path, directive, server, url, userid, user_pass)
218
212
  # except KeyboardInterrupt:
@@ -120,6 +120,7 @@ def display_categories(
120
120
  )
121
121
  table.add_column("Description")
122
122
  table.add_column("In Glossary (Qualified Name)")
123
+ table.add_column("Parent Category")
123
124
 
124
125
  categories = m_client.find_glossary_categories(search_string)
125
126
  if type(categories) is list:
@@ -138,8 +139,14 @@ def display_categories(
138
139
  glossary_guid = classification_props.get('anchorGUID','---')
139
140
  glossary_qualified_name = (
140
141
  m_client.get_glossary_by_guid(glossary_guid))['glossaryProperties']['qualifiedName']
142
+ cat_info = m_client.get_category_parent(category_guid)
143
+ if type(cat_info) is dict:
144
+ parent_qn = cat_info['glossaryCategoryProperties']['qualifiedName']
145
+ else:
146
+ parent_qn = '---'
141
147
 
142
- table.add_row(display_name, q_name, description, glossary_qualified_name)
148
+
149
+ table.add_row(display_name, q_name, description, glossary_qualified_name, parent_qn)
143
150
  console = Console(
144
151
  style="bold bright_white on black",
145
152
  width=width,