root/galaxy-central/eggs/Paste-1.6-py2.6.egg/paste/util/findpackage.py @ 3

リビジョン 3, 0.8 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
2# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
3
4import sys
5import os
6
7def find_package(dir):
8    """
9    Given a directory, finds the equivalent package name.  If it
10    is directly in sys.path, returns ''.
11    """
12    dir = os.path.abspath(dir)
13    orig_dir = dir
14    path = map(os.path.abspath, sys.path)
15    packages = []
16    last_dir = None
17    while 1:
18        if dir in path:
19            return '.'.join(packages)
20        packages.insert(0, os.path.basename(dir))
21        dir = os.path.dirname(dir)
22        if last_dir == dir:
23            raise ValueError(
24                "%s is not under any path found in sys.path" % orig_dir)
25        last_dir = dir
26   
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。