pyegeria 5.4.0.dev6__py3-none-any.whl → 5.4.0.dev7__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,273 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ SPDX-License-Identifier: Apache-2.0
4
+ Copyright Contributors to the ODPi Egeria project.
5
+
6
+
7
+ A simple display for glossary terms
8
+ """
9
+ import argparse
10
+ import os
11
+ import sys
12
+ import time
13
+
14
+ from rich import box
15
+ from rich.console import Console
16
+ from rich.markdown import Markdown
17
+ from rich.prompt import Prompt
18
+ from rich.table import Table
19
+ from rich.text import Text
20
+
21
+ from pyegeria import (
22
+ EgeriaTech,
23
+ InvalidParameterException,
24
+ PropertyServerException,
25
+ UserNotAuthorizedException, NO_CATEGORIES_FOUND,
26
+ )
27
+ from commands.cat.glossary_actions import EGERIA_HOME_GLOSSARY_GUID
28
+ from pyegeria._globals import NO_GLOSSARIES_FOUND
29
+
30
+ disable_ssl_warnings = True
31
+
32
+ EGERIA_METADATA_STORE = os.environ.get("EGERIA_METADATA_STORE", "active-metadata-store")
33
+ EGERIA_KAFKA_ENDPOINT = os.environ.get("KAFKA_ENDPOINT", "localhost:9092")
34
+ EGERIA_PLATFORM_URL = os.environ.get("EGERIA_PLATFORM_URL", "https://localhost:9443")
35
+ EGERIA_VIEW_SERVER = os.environ.get("EGERIA_VIEW_SERVER", "view-server")
36
+ EGERIA_VIEW_SERVER_URL = os.environ.get(
37
+ "EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
38
+ )
39
+ EGERIA_INTEGRATION_DAEMON = os.environ.get("EGERIA_INTEGRATION_DAEMON", "integration-daemon")
40
+ EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
41
+ EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
42
+ EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
43
+ EGERIA_USER_PASSWORD = os.environ.get("EGERIA_USER_PASSWORD", "secret")
44
+ EGERIA_JUPYTER = bool(os.environ.get("EGERIA_JUPYTER", "False"))
45
+ EGERIA_WIDTH = int(os.environ.get("EGERIA_WIDTH", "250"))
46
+ EGERIA_GLOSSARY_PATH = os.environ.get("EGERIA_GLOSSARY_PATH", None)
47
+ EGERIA_ROOT_PATH = os.environ.get("EGERIA_ROOT_PATH", "../../")
48
+ EGERIA_INBOX_PATH = os.environ.get("EGERIA_INBOX_PATH", "md_processing/dr_egeria_inbox")
49
+ EGERIA_OUTBOX_PATH = os.environ.get("EGERIA_OUTBOX_PATH", "md_processing/dr_egeria_outbox")
50
+
51
+
52
+ def display_command_terms(
53
+ search_string: str = "*",
54
+ glossary_guid: str = EGERIA_HOME_GLOSSARY_GUID,
55
+ glossary_name: str = None,
56
+ view_server: str = EGERIA_VIEW_SERVER,
57
+ view_url: str = EGERIA_VIEW_SERVER_URL,
58
+ user_id: str = EGERIA_USER,
59
+ user_pass: str = EGERIA_USER_PASSWORD,
60
+ jupyter: bool = EGERIA_JUPYTER,
61
+ width: int = EGERIA_WIDTH,
62
+ output_format: str = "TABLE",
63
+ ):
64
+ """Display a table of glossary terms filtered by search_string and glossary, if specified. If no
65
+ filters then all terms are displayed. If glossary_guid or name is specified, then only terms from that
66
+ glossary are displayed.
67
+ Parameters
68
+ ----------
69
+ search_string : str, optional
70
+ The string to search for terms. Defaults to "*".
71
+ glossary_guid : str, optional
72
+ The unique identifier of the glossary. Defaults to None. If specified, then only terms from that glossary
73
+ are displayed. If both glossary_guid and glossary_name are provided then glossary_guid will take precedence.
74
+ glossary_name : str, optional
75
+ The display name of the glossary. Defaults to None. If specified, then only terms from that glossary
76
+ are displayed. If both glossary_guid and glossary_name are provided then glossary_guid will take precedence.
77
+ Note that the use of glossary display name relies on the qualified name conforming to convention. GUID is more
78
+ reliable.
79
+ view_server : str
80
+ The server where the glossary is hosted. Defaults to EGERIA_VIEW_SERVER.
81
+ view_url : str
82
+ The URL of the server where the glossary is hosted. Defaults to EGERIA_VIEW_SERVER_URL.
83
+ user_id : str
84
+ The user ID for authentication. Defaults to EGERIA_USER.
85
+ user_pass : str
86
+ The user password for authentication. Defaults to EGERIA_USER_PASSWORD.
87
+ jupyter : bool
88
+ Flag to indicate if the output should be formatted for Jupyter notebook. Defaults to EGERIA_JUPYTER.
89
+ width : int
90
+ The width of the console output. Defaults to EGERIA_WIDTH.
91
+ output_format: str, optional, default is 'JSON'
92
+ One of TABLE, FORM, REPORT
93
+ """
94
+
95
+ console = Console(
96
+ style="bold bright_white on black", width=width, force_terminal=not jupyter
97
+ )
98
+ try:
99
+ g_client = EgeriaTech(view_server, view_url, user_id, user_pass)
100
+ token = g_client.create_egeria_bearer_token(user_id, user_pass)
101
+ if (glossary_name is not None) and (glossary_name != "*"):
102
+ glossary_guid = g_client.get_guid_for_name(glossary_name)
103
+ if glossary_guid == NO_GLOSSARIES_FOUND:
104
+ console.print(
105
+ f"\nThe glossary name {glossary_name} was not found. Please try using the glossary guid"
106
+ )
107
+ sys.exit(1)
108
+ elif (glossary_guid is not None) and (len(glossary_guid) < 10):
109
+ glossary_guid = None
110
+
111
+ if output_format == "LIST":
112
+ action = "LIST"
113
+ elif output_format == "REPORT":
114
+ action = "Report"
115
+ if output_format != "TABLE":
116
+ file_path = os.path.join(EGERIA_ROOT_PATH, EGERIA_OUTBOX_PATH)
117
+ file_name = f"Command-Help-{time.strftime('%Y-%m-%d-%H-%M-%S')}-{action}.md"
118
+ full_file_path = os.path.join(file_path, file_name)
119
+ os.makedirs(os.path.dirname(full_file_path), exist_ok=True)
120
+ output = g_client.find_glossary_terms(search_string, glossary_guid, output_format=output_format)
121
+ if output == "NO_TERMS_FOUND":
122
+ print(f"\n==> No commands found for search string '{search_string}'")
123
+ return
124
+ with open(full_file_path, 'w') as f:
125
+ f.write(output)
126
+ print(f"\n==> Terms output written to {full_file_path}")
127
+ return
128
+
129
+ except (
130
+ InvalidParameterException,
131
+ PropertyServerException,
132
+ UserNotAuthorizedException,
133
+ ) as e:
134
+ console.print_exception()
135
+
136
+
137
+
138
+ def generate_table(search_string: str, glossary_guid: str) -> Table:
139
+ """Make a new table."""
140
+ table = Table(
141
+ title=f"Glossary Definitions for Terms like {search_string} @ {time.asctime()}",
142
+ style="bright_white on black",
143
+ # row_styles="bright_white on black",
144
+ header_style="bright_white on dark_blue",
145
+ title_style="bold white on black",
146
+ caption_style="white on black",
147
+ show_lines=True,
148
+ box=box.ROUNDED,
149
+ caption=f"View Server '{view_server}' @ Platform - {view_url}",
150
+ expand=True,
151
+ )
152
+ table.add_column("Term Name", width=20)
153
+ # table.add_column("Summary")
154
+ table.add_column("Description", width=40)
155
+ table.add_column("Usage", min_width=100)
156
+
157
+ terms = g_client.find_glossary_terms(
158
+ search_string,
159
+ glossary_guid,
160
+ starts_with=False,
161
+ ends_with=False,
162
+ status_filter=[],
163
+ page_size=500,
164
+ )
165
+
166
+ if type(terms) is str:
167
+ print(f"No commands found - this was not the command you were looking for?! - {search_string} : {glossary_guid} ")
168
+ sys.exit(0)
169
+ sorted_terms = sorted(
170
+ terms, key=lambda k: k["glossaryTermProperties"].get("displayName","---")
171
+ )
172
+ style = "bright_white on black"
173
+ if type(terms) is str:
174
+ return table
175
+ glossary_info = {}
176
+ for term in sorted_terms:
177
+ props = term.get("glossaryTermProperties", "None")
178
+ if props == "None":
179
+ return table
180
+
181
+ display_name = props.get("displayName","---")
182
+ qualified_name = props["qualifiedName"]
183
+ term_guid = term["elementHeader"]["guid"]
184
+ aliases = props.get("aliases", "---")
185
+ q_name = Text(
186
+ f"{qualified_name}\n&\n{term_guid}\n&\n{aliases}", style=style, justify="center"
187
+ )
188
+ abbrev = props.get("abbreviation", "---")
189
+ summary = props.get("summary", "---")
190
+ description = props.get("description",'---')
191
+ version = props.get("publishVersionIdentifier", "---")
192
+ example = props.get("example", "---")
193
+ usage = props.get("usage", "---")
194
+ # ex_us_out = Markdown(f"Example:\n{example}\n---\nUsage: \n{usage}")
195
+
196
+ classifications = term["elementHeader"]["classifications"]
197
+ glossary_guid = None
198
+ for c in classifications:
199
+ if c["classificationName"] == "Anchors":
200
+ glossary_guid = c["classificationProperties"]["anchorScopeGUID"]
201
+
202
+ if glossary_guid and glossary_guid in glossary_info:
203
+ glossary_name = glossary_info[glossary_guid]
204
+ elif glossary_guid:
205
+ g = g_client.get_glossary_for_term(term_guid)
206
+ glossary_name = g["glossaryProperties"].get("displayName", "---")
207
+ glossary_info[glossary_guid] = glossary_name
208
+ else:
209
+ glossary_name = "---"
210
+
211
+ term_abb_ver_out = Markdown(f"{display_name}\n---\n{abbrev}\n---\n{version}")
212
+
213
+ term_status = term["elementHeader"].get("status","---")
214
+ table.add_row(
215
+ Markdown(display_name),
216
+ # summary,
217
+ Markdown(description),
218
+ Markdown(usage),
219
+ style="bold white on black",
220
+ )
221
+
222
+ g_client.close_session()
223
+ return table
224
+
225
+ try:
226
+ with console.pager(styles=True):
227
+ console.print(generate_table(search_string, glossary_guid))
228
+
229
+ except (
230
+ InvalidParameterException,
231
+ PropertyServerException,
232
+ UserNotAuthorizedException,
233
+ ) as e:
234
+ console.print_exception()
235
+
236
+
237
+ def main():
238
+ sus_guid = "f9b78b26-6025-43fa-9299-a905cc6d1575"
239
+ parser = argparse.ArgumentParser()
240
+ parser.add_argument("--server", help="Name of the server to display status for")
241
+ parser.add_argument("--url", help="URL Platform to connect to")
242
+ parser.add_argument("--userid", help="User Id")
243
+ parser.add_argument("--password", help="User Password")
244
+ parser.add_argument("--guid", help="GUID of glossary to search")
245
+
246
+ args = parser.parse_args()
247
+
248
+ # server = args.server if args.server is not None else EGERIA_VIEW_SERVER
249
+ server = args.server if args.server is not None else EGERIA_VIEW_SERVER
250
+
251
+ url = args.url if args.url is not None else EGERIA_PLATFORM_URL
252
+ userid = args.userid if args.userid is not None else EGERIA_USER
253
+ user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD
254
+ guid = args.guid if args.guid is not None else EGERIA_HOME_GLOSSARY_GUID
255
+
256
+ try:
257
+ search_string = Prompt.ask("Enter the command you are searching for:", default="*")
258
+
259
+ output_format = Prompt.ask("What output format do you want?", choices=["TABLE", "LIST", "REPORT"], default="TABLE")
260
+
261
+ display_command_terms(
262
+ search_string, guid, 'Egeria-Markdown', server, url,
263
+ userid, user_pass, output_format= output_format
264
+ )
265
+
266
+ except KeyboardInterrupt:
267
+ pass
268
+
269
+
270
+
271
+
272
+ if __name__ == "__main__":
273
+ main()