pyegeria 0.8.4.32__py3-none-any.whl → 0.8.4.34__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
 
@@ -1379,16 +1385,42 @@ class CoreServerConfig(Client):
1379
1385
  """
1380
1386
  if server_name is None:
1381
1387
  server_name = self.server_name
1388
+
1382
1389
  validate_name(pg_pwd)
1383
1390
  validate_name(pg_user)
1384
1391
  validate_name(host)
1385
1392
  pg_db = server_name.lower()
1386
1393
 
1387
- jdbc_url = (
1388
- f'"jdbc:postgresql://{host}/{pg_db}?user={pg_user}&password={pg_pwd}"'
1394
+ # Connect to the PostgreSQL server
1395
+ conn = psycopg2.connect(
1396
+ host=host,
1397
+ port=port,
1398
+ user=pg_user,
1399
+ password=pg_pwd,
1400
+ dbname="postgres", # Connect to the default 'postgres' database to perform operations
1389
1401
  )
1390
- index_dir = f'"data/servers/{server_name}/repository/xtdb/rdb-index"'
1391
- lucene_dir = f'"data/servers/{server_name}/repository/xtdb/lucene"'
1402
+ conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) # Enable autocommit mode
1403
+
1404
+ cursor = conn.cursor()
1405
+
1406
+ # Check if database exists
1407
+ cursor.execute(sql.SQL("SELECT 1 FROM pg_database WHERE datname = %s"), [pg_db])
1408
+ database_exists = cursor.fetchone()
1409
+
1410
+ # If the database does not exist, create it
1411
+ if not database_exists:
1412
+ cursor.execute(sql.SQL("CREATE DATABASE {}").format(sql.Identifier(pg_db)))
1413
+ print(f"Database '{pg_db}' created.")
1414
+ else:
1415
+ print(f"Database '{pg_db}' already exists.")
1416
+
1417
+ # Close the connection to the server
1418
+ cursor.close()
1419
+ conn.close()
1420
+
1421
+ jdbc_url = f'"jdbc:postgresql://{host}:{port}/{pg_db}?user={pg_user}&password={pg_pwd}"'
1422
+ index_dir = f'"data/servers/{server_name}/repository/{pg_db}/rdb-index"'
1423
+ lucene_dir = f'"data/servers/{server_name}/repository/{pg_db}/lucene"'
1392
1424
 
1393
1425
  index_str = "{:xtdb/index-store {:kv-store {:xtdb/module xtdb.rocksdb/->kv-store :db-dir "
1394
1426
  index_str2 = index_str + index_dir + "}}"
@@ -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.34
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=APo-jcC6I7XH_vsBaJGj-i4KMHg3WYeFZYt1O9fZc5Y,94957
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.34.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
95
+ pyegeria-0.8.4.34.dist-info/METADATA,sha256=sUBPkspUbjJjNBzpKNE5K34WT2YS_reZHDB3szLwt30,2868
96
+ pyegeria-0.8.4.34.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
97
+ pyegeria-0.8.4.34.dist-info/entry_points.txt,sha256=R8sNzclWZN542SufuVlx9HDia23PlSVnJioUkzCWg4I,3349
98
+ pyegeria-0.8.4.34.dist-info/RECORD,,