pyegeria 0.8.4.32__py3-none-any.whl → 0.8.4.33__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.
@@ -10,6 +10,9 @@ deployed to take effect.
10
10
  """
11
11
 
12
12
  import json
13
+ import psycopg2
14
+ from psycopg2 import sql
15
+ from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
13
16
 
14
17
  # import json
15
18
  from pyegeria._client import Client
@@ -1340,15 +1343,18 @@ class CoreServerConfig(Client):
1340
1343
  self.make_request("POST", url, xtdb_config_body)
1341
1344
 
1342
1345
  def set_xtdb_pg_repository(
1343
- self, host: str, pg_user: str, pg_pwd: str, server_name: str = None
1346
+ self, host: str, port: str, pg_user: str, pg_pwd: str, server_name: str = None
1344
1347
  ) -> None:
1345
- """Set the local repository connection to be XTDB using PostgresSQL Server, passing in basic parameters
1348
+ """Set the local repository connection to be XTDB using PostgresSQL Server, passing in basic parameters.
1349
+ A postgres database with the name of the metadata server will be created if it doesn't exist.
1350
+
1346
1351
 
1347
1352
  Parameters
1348
1353
  ----------
1349
1354
  host : str
1350
- the full hostname and port of the postgres server
1351
-
1355
+ the full hostname of the postgres server
1356
+ port: str
1357
+ the port number of the postgres server
1352
1358
  pg_user : str
1353
1359
  postgresql user name
1354
1360
 
@@ -1384,9 +1390,34 @@ class CoreServerConfig(Client):
1384
1390
  validate_name(host)
1385
1391
  pg_db = server_name.lower()
1386
1392
 
1387
- jdbc_url = (
1388
- f'"jdbc:postgresql://{host}/{pg_db}?user={pg_user}&password={pg_pwd}"'
1393
+ # Connect to the PostgreSQL server
1394
+ conn = psycopg2.connect(
1395
+ host=host,
1396
+ port=port,
1397
+ user=pg_user,
1398
+ password=pg_pwd,
1399
+ dbname="postgres", # Connect to the default 'postgres' database to perform operations
1389
1400
  )
1401
+ conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) # Enable autocommit mode
1402
+
1403
+ cursor = conn.cursor()
1404
+
1405
+ # Check if database exists
1406
+ cursor.execute(sql.SQL("SELECT 1 FROM pg_database WHERE datname = %s"), [pg_db])
1407
+ database_exists = cursor.fetchone()
1408
+
1409
+ # If the database does not exist, create it
1410
+ if not database_exists:
1411
+ cursor.execute(sql.SQL("CREATE DATABASE {}").format(sql.Identifier(pg_db)))
1412
+ print(f"Database '{pg_db}' created.")
1413
+ else:
1414
+ print(f"Database '{pg_db}' already exists.")
1415
+
1416
+ # Close the connection to the server
1417
+ cursor.close()
1418
+ conn.close()
1419
+
1420
+ jdbc_url = f'"jdbc:postgresql://{host}:{port}/{pg_db}?user={pg_user}&password={pg_pwd}"'
1390
1421
  index_dir = f'"data/servers/{server_name}/repository/xtdb/rdb-index"'
1391
1422
  lucene_dir = f'"data/servers/{server_name}/repository/xtdb/lucene"'
1392
1423
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyegeria
3
- Version: 0.8.4.32
3
+ Version: 0.8.4.33
4
4
  Summary: A python client for Egeria
5
5
  Home-page: https://github.com/odpi/egeria-python
6
6
  License: Apache 2.0
@@ -19,6 +19,7 @@ Requires-Dist: confluent-kafka (>=2.5.0,<3.0.0)
19
19
  Requires-Dist: httpx (>=0.27.0,<0.28.0)
20
20
  Requires-Dist: jupyter (>=1.0.0,<2.0.0)
21
21
  Requires-Dist: mermaid-py (>=0.5.3,<0.6.0)
22
+ Requires-Dist: psycopg2-binary (>=2.9.9,<3.0.0)
22
23
  Requires-Dist: pytest (>=8.2.2,<9.0.0)
23
24
  Requires-Dist: requests (>=2.32.3,<3.0.0)
24
25
  Requires-Dist: rich (>=13.8.1,<14.0.0)
@@ -70,7 +70,7 @@ pyegeria/asset_catalog_omvs.py,sha256=6KVQxTeTuMOrXpv8AhiqadDnStIl8JKvPC3qZKmUxA
70
70
  pyegeria/automated_curation_omvs.py,sha256=AUqps7zSqXITAP9YN_mbO_30FCMxpQhlk1KhC5hV8kY,132892
71
71
  pyegeria/classification_manager_omvs.py,sha256=hOKYqNWfAFqwwVgvkUok8kzD4g0pOaNI7QxrkjPZDMI,200796
72
72
  pyegeria/collection_manager_omvs.py,sha256=C8cfgGsx6MpG1Nds3JahyqXel8zpb-9iwXsXCAuzmg0,109717
73
- pyegeria/core_omag_server_config.py,sha256=T1nx8KGuSPn-l8vVkH_I7qsJ7Bvou9TZUB41G2g_ZWc,93730
73
+ pyegeria/core_omag_server_config.py,sha256=ZN7TDPuYy_vUpsiVQUqY6wDmhIHBssZofa0kX35PL10,94950
74
74
  pyegeria/create_tech_guid_lists.py,sha256=HHkC6HW58EN1BiolrYSRqSE0JhPbTepOFzwtdwBxVaU,4640
75
75
  pyegeria/egeria_cat_client.py,sha256=WyxDYklm2eDpsiHLXVJi4WP5BBeXlvWWX5h5CLevdcE,1877
76
76
  pyegeria/egeria_client.py,sha256=8rKu-ACdyBVRw2C114mleCBI4m30YCBi7dPCt5Y-ZTY,3360
@@ -91,8 +91,8 @@ pyegeria/server_operations.py,sha256=ciH890hYT85YQ6OpByn4w7s3a7TtvWZpIG5rkRqbcI0
91
91
  pyegeria/utils.py,sha256=1h6bwveadd6GpbnGLTmqPBmBk68QvxdjGTI9RfbrgKY,5415
92
92
  pyegeria/valid_metadata_omvs.py,sha256=6Hc4g9BOS8w1ILfTG3_A1tfIX3HLtpgZZvcC-z9GePU,36185
93
93
  pyegeria/x_action_author_omvs.py,sha256=za472slZ5tN9Pkd-ukyHS5Sn6MlKkJyIlbLlU3bL_Go,6451
94
- pyegeria-0.8.4.32.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
95
- pyegeria-0.8.4.32.dist-info/METADATA,sha256=WbQ5oi9S_kbOLBEJ6d3rPOLF0_F_JX5verrUS5PXyZs,2820
96
- pyegeria-0.8.4.32.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
97
- pyegeria-0.8.4.32.dist-info/entry_points.txt,sha256=R8sNzclWZN542SufuVlx9HDia23PlSVnJioUkzCWg4I,3349
98
- pyegeria-0.8.4.32.dist-info/RECORD,,
94
+ pyegeria-0.8.4.33.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
95
+ pyegeria-0.8.4.33.dist-info/METADATA,sha256=xBWyDZDBEVbh6D84zR_LiEJfJaCZzQ2yc13oodPShxQ,2868
96
+ pyegeria-0.8.4.33.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
97
+ pyegeria-0.8.4.33.dist-info/entry_points.txt,sha256=R8sNzclWZN542SufuVlx9HDia23PlSVnJioUkzCWg4I,3349
98
+ pyegeria-0.8.4.33.dist-info/RECORD,,