Commit db473745 authored by Hanno Schlichting's avatar Hanno Schlichting

Make Sessions/Transience optional dependencies in ZTC.

parent 17089c2a
...@@ -30,39 +30,46 @@ def setupCoreSessions(app): ...@@ -30,39 +30,46 @@ def setupCoreSessions(app):
from Acquisition import aq_base from Acquisition import aq_base
commit = 0 commit = 0
if not hasattr(app, 'temp_folder'): try:
from Products.TemporaryFolder.TemporaryFolder import MountedTemporaryFolder from Products.TemporaryFolder.TemporaryFolder import \
tf = MountedTemporaryFolder('temp_folder', 'Temporary Folder') MountedTemporaryFolder
app._setObject('temp_folder', tf)
commit = 1
if not hasattr(aq_base(app.temp_folder), 'session_data'):
from Products.Transience.Transience import TransientObjectContainer from Products.Transience.Transience import TransientObjectContainer
toc = TransientObjectContainer('session_data',
'Session Data Container',
timeout_mins=3,
limit=100)
app.temp_folder._setObject('session_data', toc)
commit = 1
if not hasattr(app, 'browser_id_manager'):
from Products.Sessions.BrowserIdManager import BrowserIdManager from Products.Sessions.BrowserIdManager import BrowserIdManager
bid = BrowserIdManager('browser_id_manager',
'Browser Id Manager')
app._setObject('browser_id_manager', bid)
commit = 1
if not hasattr(app, 'session_data_manager'):
from Products.Sessions.SessionDataManager import SessionDataManager from Products.Sessions.SessionDataManager import SessionDataManager
sdm = SessionDataManager('session_data_manager', except ImportError:
title='Session Data Manager', pass
path='/temp_folder/session_data', else:
requestName='SESSION') if not hasattr(app, 'temp_folder'):
app._setObject('session_data_manager', sdm) tf = MountedTemporaryFolder('temp_folder', 'Temporary Folder')
commit = 1 app._setObject('temp_folder', tf)
commit = 1
if commit:
transaction.commit() if not hasattr(aq_base(app.temp_folder), 'session_data'):
toc = TransientObjectContainer(
'session_data',
'Session Data Container',
timeout_mins=3,
limit=100)
app.temp_folder._setObject('session_data', toc)
commit = 1
if not hasattr(app, 'browser_id_manager'):
bid = BrowserIdManager('browser_id_manager',
'Browser Id Manager')
app._setObject('browser_id_manager', bid)
commit = 1
if not hasattr(app, 'session_data_manager'):
sdm = SessionDataManager(
'session_data_manager',
title='Session Data Manager',
path='/temp_folder/session_data',
requestName='SESSION')
app._setObject('session_data_manager', sdm)
commit = 1
if commit:
transaction.commit()
@layer.appcall @layer.appcall
...@@ -83,15 +90,18 @@ def importObjectFromFile(container, filename, quiet=0): ...@@ -83,15 +90,18 @@ def importObjectFromFile(container, filename, quiet=0):
from ZopeLite import _print, _patched from ZopeLite import _print, _patched
quiet = quiet or not _patched quiet = quiet or not _patched
start = time.time() start = time.time()
if not quiet: _print("Importing %s ... " % os.path.basename(filename)) if not quiet:
_print("Importing %s ... " % os.path.basename(filename))
container._importObjectFromFile(filename, verify=0) container._importObjectFromFile(filename, verify=0)
transaction.commit() transaction.commit()
if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) if not quiet:
_print('done (%.3fs)\n' % (time.time() - start))
_Z2HOST = None _Z2HOST = None
_Z2PORT = None _Z2PORT = None
def startZServer(number_of_threads=1, log=None): def startZServer(number_of_threads=1, log=None):
'''Starts an HTTP ZServer thread.''' '''Starts an HTTP ZServer thread.'''
global _Z2HOST, _Z2PORT global _Z2HOST, _Z2PORT
...@@ -104,7 +114,7 @@ def startZServer(number_of_threads=1, log=None): ...@@ -104,7 +114,7 @@ def startZServer(number_of_threads=1, log=None):
t = QuietThread(target=zserverRunner, args=(_Z2HOST, _Z2PORT, log)) t = QuietThread(target=zserverRunner, args=(_Z2HOST, _Z2PORT, log))
t.setDaemon(1) t.setDaemon(1)
t.start() t.start()
time.sleep(0.1) # Sandor Palfy time.sleep(0.1) # Sandor Palfy
return _Z2HOST, _Z2PORT return _Z2HOST, _Z2PORT
...@@ -134,12 +144,12 @@ def makelist(arg): ...@@ -134,12 +144,12 @@ def makelist(arg):
'''Turns arg into a list. Where arg may be '''Turns arg into a list. Where arg may be
list, tuple, or string. list, tuple, or string.
''' '''
if type(arg) == type([]): if isinstance(arg, list):
return arg return arg
if type(arg) == type(()): if isinstance(arg, tuple):
return list(arg) return list(arg)
if type(arg) == type(''): if isinstance(arg, str):
return filter(None, [arg]) return filter(None, [arg])
raise ValueError('Argument must be list, tuple, or string') raise ValueError('Argument must be list, tuple, or string')
...@@ -152,4 +162,3 @@ __all__ = [ ...@@ -152,4 +162,3 @@ __all__ = [
'makerequest', 'makerequest',
'makelist', 'makelist',
] ]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment