Updated manager function db.
This commit is contained in:
@@ -28,21 +28,18 @@ 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 = parts[0]
|
||||||
host, port_str = db_arg.split(":")
|
port = int(parts[1])
|
||||||
try:
|
storage = ZEO.client((host, port)) # modern ZEO
|
||||||
port = int(port_str)
|
return ZODB.DB(storage)
|
||||||
except ValueError:
|
|
||||||
raise ValueError(f"Invalid port in ZEO address: {db_arg}")
|
# Local
|
||||||
return ZEO.DB((host,port))
|
storage = ZODB.FileStorage.FileStorage(db_arg)
|
||||||
else:
|
return ZODB.DB(storage)
|
||||||
# Local FileStorage path
|
|
||||||
storage = ZODB.FileStorage.FileStorage(db_arg)
|
|
||||||
return ZODB.DB(storage)
|
|
||||||
|
|
||||||
|
|
||||||
def get_or_create_http_users(root):
|
def get_or_create_http_users(root):
|
||||||
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user