summaryrefslogtreecommitdiff
path: root/paste/pyconfig.py
diff options
context:
space:
mode:
authorianb <devnull@localhost>2005-05-10 22:20:16 +0000
committerianb <devnull@localhost>2005-05-10 22:20:16 +0000
commit0aeeb6e06a0d19f4bd01be70a792f974d7de74a1 (patch)
tree89a2f7b8ed82c68b5ae80ccc69de7860a19342c0 /paste/pyconfig.py
parent6f64d5c821ec23332e6f357da83ce18ca654e373 (diff)
downloadpaste-0aeeb6e06a0d19f4bd01be70a792f974d7de74a1.tar.gz
Added new public method to dispatcher to de-dispath; new function to load a config file and update sys.path and paste.CONFIG
Diffstat (limited to 'paste/pyconfig.py')
-rw-r--r--paste/pyconfig.py33
1 files changed, 28 insertions, 5 deletions
diff --git a/paste/pyconfig.py b/paste/pyconfig.py
index a2af1a7..32aa384 100644
--- a/paste/pyconfig.py
+++ b/paste/pyconfig.py
@@ -15,6 +15,7 @@ or dictionary access to get values.
import types
import os
+import sys
from paste.util import thirdparty
UserDict = thirdparty.load_new_module('UserDict', (2, 3))
from paste.reloader import watch_file
@@ -217,7 +218,25 @@ class Config(UserDict.DictMixin):
except ValueError:
pass
return value
-
+
+def setup_config(filename):
+ conf = Config(with_default=True)
+ conf.load(filename)
+ if conf.get('sys_path'):
+ update_sys_path(conf['sys_path'], conf['verbose'])
+ from paste import CONFIG
+ CONFIG.push_process_config(conf)
+ return conf
+
+def update_sys_path(paths, verbose):
+ if isinstance(paths, (str, unicode)):
+ paths = [paths]
+ for path in paths:
+ path = os.path.abspath(path)
+ if path not in sys.path:
+ if verbose:
+ print 'Adding %s to path' % path
+ sys.path.insert(0, path)
class DispatchingConfig(object):
@@ -230,6 +249,10 @@ class DispatchingConfig(object):
for the process or for threads.
"""
+ # @@: What should happen when someone tries to add this
+ # configuration to itself? Probably the conf should become
+ # resolved, and get rid of this delegation wrapper
+
_constructor_lock = threading.Lock()
def __init__(self):
@@ -289,15 +312,15 @@ class DispatchingConfig(object):
self._pop_from(self._process_config, conf)
def __getattr__(self, attr):
- conf = self.__getconf()
+ conf = self.current_conf()
if not conf:
raise AttributeError(
"No configuration has been registered for this process "
"or thread")
return getattr(conf, attr)
- def __getconf(self):
- thread_configs = local_dict()[self._local_key]
+ def current_conf(self):
+ thread_configs = local_dict().get(self._local_key)
if thread_configs:
return thread_configs[-1]
elif self._process_configs:
@@ -307,7 +330,7 @@ class DispatchingConfig(object):
def __getitem__(self, key):
# I thought __getattr__ would catch this, but apparently not
- conf = self.__getconf()
+ conf = self.current_conf()
if not conf:
raise TypeError(
"No configuration has been registered for this process "