Added changes to database server logic.
This commit is contained in:
@@ -15,6 +15,7 @@ import sys
|
||||
import uvicorn
|
||||
import ZODB.FileStorage
|
||||
import ZODB.DB
|
||||
import logging
|
||||
from packetserver.http.server import app
|
||||
|
||||
# Global DB and connection for reuse in the FastAPI dependency
|
||||
@@ -25,21 +26,18 @@ _connection = None
|
||||
def open_database(db_arg: str) -> ZODB.DB:
|
||||
"""
|
||||
Open a ZODB database from either a local FileStorage path or ZEO address.
|
||||
Reuses the same logic as http_user_manager.py.
|
||||
"""
|
||||
if ":" in db_arg and db_arg.count(":") == 1 and "." in db_arg.split(":")[0]:
|
||||
logging.debug("using ZEO storage")
|
||||
import ZEO
|
||||
host, port_str = db_arg.split(":")
|
||||
try:
|
||||
port = int(port_str)
|
||||
except ValueError:
|
||||
raise ValueError(f"Invalid port in ZEO address: {db_arg}")
|
||||
storage = ZEO.DB((host, port))
|
||||
return storage
|
||||
port = int(port_str)
|
||||
storage = ZEO.client_storage((host, port))
|
||||
return ZODB.DB(storage) # return the DB
|
||||
else:
|
||||
# Local FileStorage path
|
||||
logging.debug("using standard storage")
|
||||
storage = ZODB.FileStorage.FileStorage(db_arg)
|
||||
return ZODB.DB(storage)
|
||||
return ZODB.DB(storage) # return the DB
|
||||
|
||||
|
||||
def get_db_connection():
|
||||
|
||||
Reference in New Issue
Block a user