diff options
| author | ianb <devnull@localhost> | 2005-05-30 20:46:42 +0000 |
|---|---|---|
| committer | ianb <devnull@localhost> | 2005-05-30 20:46:42 +0000 |
| commit | 96926020d9b9b7886f98bc54652ebbc5c9b3274b (patch) | |
| tree | 2ac6a80c750bce8b14326ead18709e1d031cc9b3 | |
| parent | 36bdc0f806b528097c652487016d9ec94562474d (diff) | |
| download | paste-96926020d9b9b7886f98bc54652ebbc5c9b3274b.tar.gz | |
Make sure URLParser is given proper package names
| -rw-r--r-- | paste/util/findpackage.py | 22 | ||||
| -rw-r--r-- | paste/webkit/conf_setup.py | 4 |
2 files changed, 25 insertions, 1 deletions
diff --git a/paste/util/findpackage.py b/paste/util/findpackage.py new file mode 100644 index 0000000..276e216 --- /dev/null +++ b/paste/util/findpackage.py @@ -0,0 +1,22 @@ +import sys +import os + +def find_package(dir): + """ + Given a directory, finds the equivalent package name. If it + is directly in sys.path, returns ''. + """ + orig_dir = dir + path = sys.path + packages = [] + last_dir = None + while 1: + if dir in path: + return '.'.join(packages) + packages.insert(0, os.path.basename(dir)) + dir = os.path.dirname(dir) + if last_dir == dir: + raise ValueError( + "%s is not under any path found in sys.path" % orig_dir) + last_dir = dir + diff --git a/paste/webkit/conf_setup.py b/paste/webkit/conf_setup.py index 656bea6..cf34457 100644 --- a/paste/webkit/conf_setup.py +++ b/paste/webkit/conf_setup.py @@ -5,6 +5,7 @@ from paste import urlparser from paste import session from paste import recursive from paste import httpexceptions +from paste.util.findpackage import find_package def build_application(conf): if not 'publish_dir' in conf: @@ -14,7 +15,8 @@ def build_application(conf): install_fake_webware = conf.get('install_fake_webware', True) if install_fake_webware: _install_fake_webware() - app = urlparser.URLParser(directory, os.path.basename(directory)) + package = find_package(directory) + app = urlparser.URLParser(directory, package) app = makeapp.apply_conf_middleware( app, conf, [httpexceptions.middleware, session.SessionMiddleware, |
