Updated manager function db.

This commit is contained in:
Michael Woods
2025-12-21 23:15:41 -05:00
parent 9803e2acf4
commit 23365ae207

View File

@@ -28,19 +28,16 @@ HTTP_USERS_KEY = "httpUsers"
def open_database(db_arg: str) -> ZODB.DB: def open_database(db_arg: str) -> ZODB.DB:
""" if ":" in db_arg:
Open a ZODB database from either a local FileStorage path or ZEO address. parts = db_arg.split(":")
""" if len(parts) == 2 and parts[1].isdigit():
if ":" in db_arg and db_arg.count(":") == 1 and "." in db_arg.split(":")[0]:
import ZEO import ZEO
host, port_str = db_arg.split(":") host = parts[0]
try: port = int(parts[1])
port = int(port_str) storage = ZEO.client((host, port)) # modern ZEO
except ValueError: return ZODB.DB(storage)
raise ValueError(f"Invalid port in ZEO address: {db_arg}")
return ZEO.DB((host,port)) # Local
else:
# Local FileStorage path
storage = ZODB.FileStorage.FileStorage(db_arg) storage = ZODB.FileStorage.FileStorage(db_arg)
return ZODB.DB(storage) return ZODB.DB(storage)
@@ -133,8 +130,7 @@ def main():
main_users = root.setdefault('users', PersistentMapping()) main_users = root.setdefault('users', PersistentMapping())
if callsign not in main_users: if callsign not in main_users:
new_user = User(callsign) User.write_new(main_users, args.callsign) # correct: pass mapping + callsign
new_user.write_new(root)
print(f" → Also created regular BBS user {callsign} (with UUID)") print(f" → Also created regular BBS user {callsign} (with UUID)")
else: else:
print(f" → Regular BBS user {callsign} already exists") print(f" → Regular BBS user {callsign} already exists")