drifTech-lib 0.2.2__tar.gz → 0.2.4__tar.gz
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.
Potentially problematic release.
This version of drifTech-lib might be problematic. Click here for more details.
- {driftech_lib-0.2.2 → driftech_lib-0.2.4}/PKG-INFO +1 -1
- {driftech_lib-0.2.2 → driftech_lib-0.2.4}/pyproject.toml +1 -1
- {driftech_lib-0.2.2 → driftech_lib-0.2.4}/pyproject.toml.orig +1 -1
- {driftech_lib-0.2.2 → driftech_lib-0.2.4}/src/driftech_lib/db.py +7 -6
- {driftech_lib-0.2.2 → driftech_lib-0.2.4}/src/driftech_lib/ipc/client.py +7 -6
- {driftech_lib-0.2.2 → driftech_lib-0.2.4}/src/driftech_lib/ipc/server.py +6 -5
- {driftech_lib-0.2.2 → driftech_lib-0.2.4}/LICENSE +0 -0
- {driftech_lib-0.2.2 → driftech_lib-0.2.4}/README.md +0 -0
- {driftech_lib-0.2.2 → driftech_lib-0.2.4}/src/driftech_lib/__init__.py +0 -0
- {driftech_lib-0.2.2 → driftech_lib-0.2.4}/src/driftech_lib/ipc/__init__.py +0 -0
- {driftech_lib-0.2.2 → driftech_lib-0.2.4}/src/driftech_lib/jsonIO.py +0 -0
|
@@ -8,7 +8,7 @@ build-backend = "uv_build"
|
|
|
8
8
|
|
|
9
9
|
[project]
|
|
10
10
|
name = "drifTech-lib"
|
|
11
|
-
version = "0.2.
|
|
11
|
+
version = "0.2.4"
|
|
12
12
|
authors = [{name = "driftbluestone", email = "driftbluestone@gmail.com"}]
|
|
13
13
|
description = "Common files/functions across most drifTech software"
|
|
14
14
|
readme = "README.md"
|
|
@@ -4,6 +4,7 @@ Module for interacting with PostgreSQL
|
|
|
4
4
|
import psycopg, logging
|
|
5
5
|
from typing import Any
|
|
6
6
|
from psycopg import sql
|
|
7
|
+
logger = logging.getLogger("db")
|
|
7
8
|
|
|
8
9
|
__all__ = ["SCHEMA", "start", "run", "single", "multiple", "insert", "delete", "get", "table"]
|
|
9
10
|
|
|
@@ -21,13 +22,13 @@ def check_connection():
|
|
|
21
22
|
cursor.execute("SELECT version();")
|
|
22
23
|
db_version = cursor.fetchone()
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
logger.info("Connection Successful")
|
|
26
|
+
logger.info(f"PostgreSQL version: {db_version[0]}")
|
|
26
27
|
|
|
27
28
|
def close_connection():
|
|
28
29
|
cursor.close()
|
|
29
30
|
connection.close()
|
|
30
|
-
|
|
31
|
+
logger.info("Database connection closed.")
|
|
31
32
|
|
|
32
33
|
def run(*args):
|
|
33
34
|
cursor.execute(*args)
|
|
@@ -118,7 +119,7 @@ def get(table: str, value: tuple[Any], key: tuple[str], column: tuple[str]):
|
|
|
118
119
|
def start(schema: str, host: str, name: str, user: str, password: str, port: int):
|
|
119
120
|
global SCHEMA, connection, cursor
|
|
120
121
|
SCHEMA = sql.Identifier(schema)
|
|
121
|
-
|
|
122
|
+
logger.info("Connecting to database...")
|
|
122
123
|
connection = psycopg.connect(
|
|
123
124
|
host=host,
|
|
124
125
|
dbname=name,
|
|
@@ -128,5 +129,5 @@ def start(schema: str, host: str, name: str, user: str, password: str, port: int
|
|
|
128
129
|
)
|
|
129
130
|
cursor = connection.cursor()
|
|
130
131
|
check_connection()
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
logger.info("Connected to database.")
|
|
133
|
+
run(f"CREATE SCHEMA IF NOT EXISTS {SCHEMA.as_string()};")
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import asyncio, logging
|
|
2
|
+
logger = logging.getLogger("ipc:client")
|
|
2
3
|
__all__ = ["Connector"]
|
|
3
4
|
|
|
4
5
|
class Connector:
|
|
@@ -13,11 +14,11 @@ class Connector:
|
|
|
13
14
|
self.command_queue: asyncio.Queue[bytes] = asyncio.Queue(10)
|
|
14
15
|
|
|
15
16
|
async def start(self):
|
|
16
|
-
|
|
17
|
+
logger.info(f"Connecting to server at {self.HOST}:{self.PORT}...")
|
|
17
18
|
|
|
18
19
|
# Establish the asynchronous socket connection
|
|
19
20
|
reader, writer = await asyncio.open_connection(self.HOST, self.PORT)
|
|
20
|
-
|
|
21
|
+
logger.info("Connected successfully!")
|
|
21
22
|
|
|
22
23
|
# Start the background listening loop as a concurrent task
|
|
23
24
|
listen_task = asyncio.create_task(self._listen(reader))
|
|
@@ -36,13 +37,13 @@ class Connector:
|
|
|
36
37
|
while True:
|
|
37
38
|
data = await reader.read(1024)
|
|
38
39
|
if not data:
|
|
39
|
-
|
|
40
|
+
logger.error("[DISCONNECTED] Server closed the connection.")
|
|
40
41
|
break
|
|
41
42
|
await self.on_message(data)
|
|
42
43
|
except asyncio.CancelledError:
|
|
43
44
|
pass
|
|
44
45
|
except Exception as e:
|
|
45
|
-
|
|
46
|
+
logger.error(f"[ERROR] Reading error: {e}")
|
|
46
47
|
|
|
47
48
|
async def on_message(self, message: bytes):
|
|
48
49
|
"""
|
|
@@ -66,12 +67,12 @@ class Connector:
|
|
|
66
67
|
continue
|
|
67
68
|
|
|
68
69
|
if message.lower() == b"exit":
|
|
69
|
-
|
|
70
|
+
logger.info("Closing connection...")
|
|
70
71
|
break
|
|
71
72
|
|
|
72
73
|
writer.write(message)
|
|
73
74
|
await writer.drain()
|
|
74
75
|
|
|
75
76
|
except Exception as e:
|
|
76
|
-
|
|
77
|
+
logger.error(f"Writing error: {e}")
|
|
77
78
|
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import asyncio, logging
|
|
2
|
+
logger = logging.getLogger("ipc:server")
|
|
2
3
|
__all__ = ["start"]
|
|
3
4
|
|
|
4
5
|
async def start(HOST, PORT):
|
|
5
6
|
server = await asyncio.start_server(interface, HOST, PORT)
|
|
6
|
-
|
|
7
|
+
logger.info(f"[LISTENING] Server is running on {HOST}:{PORT}")
|
|
7
8
|
async with server:
|
|
8
9
|
await server.serve_forever()
|
|
9
10
|
|
|
10
11
|
async def interface(reader: asyncio.StreamReader, writer: asyncio.StreamWriter):
|
|
11
12
|
addr = writer.get_extra_info("peername")
|
|
12
|
-
|
|
13
|
+
logger.info(f"[CONNECTION]: Connection opened for {addr}")
|
|
13
14
|
try:
|
|
14
15
|
while True:
|
|
15
16
|
data = await reader.read(1024)
|
|
16
17
|
if not data:
|
|
17
18
|
break
|
|
18
|
-
|
|
19
|
+
logger.info(f"[{addr}] Received: {data.decode()}")
|
|
19
20
|
writer.write(b"Message processed")
|
|
20
21
|
await writer.drain() # Ensure data is flushed to the network buffer
|
|
21
22
|
except (asyncio.CancelledError, ConnectionResetError, BrokenPipeError, OSError):
|
|
22
|
-
|
|
23
|
+
logger.info(f"[DISCONNECTED] Connection closed for {addr}")
|
|
23
24
|
writer.close()
|
|
24
25
|
await writer.wait_closed()
|
|
25
26
|
finally:
|
|
26
|
-
|
|
27
|
+
logger.info(f"[DISCONNECTED] Connection closed for {addr}")
|
|
27
28
|
writer.close()
|
|
28
29
|
await writer.wait_closed()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|