psu improvments for db and conn usage; fix table.py

This commit is contained in:
Helmut Merz 2024-10-25 15:08:08 +02:00
parent 14ea59a307
commit 0f2232648c
2 changed files with 13 additions and 5 deletions

View file

@ -43,22 +43,30 @@ except ImportError:
sc = Jeep() # shortcuts sc = Jeep() # shortcuts
db = None
conn = None conn = None
def closeConnection(): def closeConnection():
global conn
if conn is not None: if conn is not None:
print('closing ZODB connection...') print('closing ZODB connection...')
conn.close() conn.close()
conn = None
atexit.register(closeConnection)
def setup(zope_conf=None, loopsRootPath=None, config=config): def setup(zope_conf=None, loopsRootPath=None, config=config):
if zope_conf is None: if zope_conf is None:
zope_conf = getattr(config, 'zope_conf', 'zope.conf') zope_conf = getattr(config, 'zope_conf', 'zope.conf')
if loopsRootPath is None: if loopsRootPath is None:
loopsRootPath = getattr(config, 'loops_path', None) loopsRootPath = getattr(config, 'loops_path', None)
global conn, root, sm, smdefault, intids, pau, loopsRoot, sc global db, conn, root, sm, smdefault, intids, pau, loopsRoot, sc
print(f'opening ZODB connection... - conf: {zope_conf}, path: {loopsRootPath}') if db is None:
conn = wsgi.config(zope_conf).open() print(f'setting up ZODB... - conf: {zope_conf}, path: {loopsRootPath}')
atexit.register(closeConnection) db = wsgi.config(zope_conf)
if conn is None:
print(f'opening ZODB connection...')
conn = db.open()
root = conn.root()['Application'] root = conn.root()['Application']
setSite(root) setSite(root)
sm = component.getSiteManager(root) sm = component.getSiteManager(root)

View file

@ -131,7 +131,7 @@ def getRowValue(k, v):
return v[0] return v[0]
def getRowValueWithKey(k, v): def getRowValueWithKey(k, v):
return ' '.join((k, v[0])) return ' '.join((str(k), v[0]))
@implementer(IIterableSource) @implementer(IIterableSource)