support for loading extra modules
This commit is contained in:
parent
65705249d7
commit
7c56ce1a57
|
@ -103,6 +103,34 @@ class AuthenticPublisher(Publisher):
|
|||
get_response().breadcrumb = []
|
||||
self.install_lang(lang)
|
||||
return Publisher.try_publish(self, request)
|
||||
|
||||
|
||||
extra_dirs = None
|
||||
def register_extra_dir(cls, dir):
|
||||
if not cls.extra_dirs:
|
||||
cls.extra_dirs = []
|
||||
cls.extra_dirs.append(dir)
|
||||
register_extra_dir = classmethod(register_extra_dir)
|
||||
|
||||
def load_extra_dirs(cls):
|
||||
for extra_dir in cls.extra_dirs or []:
|
||||
if not os.path.exists(extra_dir):
|
||||
continue
|
||||
sys.path.append(extra_dir)
|
||||
for filename in os.listdir(extra_dir):
|
||||
if not filename.endswith('.py'):
|
||||
continue
|
||||
modulename = filename[:-3]
|
||||
fp, pathname, description = imp.find_module(modulename, [extra_dir])
|
||||
try:
|
||||
imp.load_module(modulename, fp, pathname, description)
|
||||
except:
|
||||
raise
|
||||
logger.warn('failed to load extra module: %s' % modulename)
|
||||
if fp:
|
||||
fp.close()
|
||||
load_extra_dirs = classmethod(load_extra_dirs)
|
||||
|
||||
|
||||
class AuthenticVHostPublisher(AuthenticPublisher):
|
||||
def try_publish(self, request):
|
||||
|
@ -115,6 +143,7 @@ class AuthenticVHostPublisher(AuthenticPublisher):
|
|||
|
||||
|
||||
def create_publisher(publisher_class = AuthenticPublisher):
|
||||
publisher_class.load_extra_dirs()
|
||||
publisher = publisher_class(RootDirectory(),
|
||||
session_cookie_name = 'authentic',
|
||||
session_cookie_path = '/',
|
||||
|
|
|
@ -15,14 +15,13 @@ def start(args):
|
|||
port = int(args[i+1])
|
||||
i += 1
|
||||
elif args[i] == '--extra':
|
||||
authentic.AuthenticPublisher.register_extra_dir(args[i+1])
|
||||
extra_dirs.append(args[i+1])
|
||||
i += 1
|
||||
elif args[i] == '--single-host':
|
||||
single_host = True
|
||||
i += 1
|
||||
|
||||
authentic.extra_dirs = extra_dirs
|
||||
|
||||
try:
|
||||
if single_host:
|
||||
run(authentic.create_publisher, port=port, script_name = '')
|
||||
|
|
|
@ -2,9 +2,6 @@
|
|||
|
||||
import sys
|
||||
|
||||
import authentic.ctl
|
||||
|
||||
|
||||
def print_usage():
|
||||
print 'Usage: authenticctl.py command [...]'
|
||||
print ''
|
||||
|
@ -21,11 +18,14 @@ else:
|
|||
command = sys.argv[1]
|
||||
|
||||
if command == 'start':
|
||||
authentic.ctl.start(sys.argv[2:])
|
||||
from authentic.ctl.start import start
|
||||
start(sys.argv[2:])
|
||||
elif command == 'clean_sessions':
|
||||
authentic.ctl.clean_sessions(sys.argv[2:])
|
||||
from authentic.ctl.clean_sessions import clean_sessions
|
||||
clean_sessions(sys.argv[2:])
|
||||
elif command == 'lock':
|
||||
authentic.ctl.lock(sys.argv[2:])
|
||||
from authentic.ctl.lock import lock
|
||||
lock(sys.argv[2:])
|
||||
else:
|
||||
print_usage()
|
||||
|
||||
|
|
Reference in New Issue