Created
June 20, 2013 13:46
-
-
Save ods/5822818 to your computer and use it in GitHub Desktop.
A possible implementation of path_config.py to quickly get path configuration in all subsites of our typical iktomi-based project. This module is placed in code root and symlinked to all subsite roots. A script in subsite root requires just the following single line: import path_config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys, warnings | |
def _get_root(): | |
# Only .py file is symbolic link, while compiled module can be placed | |
# locally | |
name, ext = os.path.splitext(__file__) | |
fn = os.path.abspath(name +'.py') | |
if os.path.islink(fn): | |
# Symlinks are relative to target, not working dir | |
fn = os.path.join(os.path.dirname(fn), os.readlink(fn)) | |
fn = os.path.abspath(fn) | |
return os.path.dirname(fn) | |
ROOT = _get_root() | |
sys.path.insert(0, os.path.join(ROOT, 'third-party')) | |
warnings.simplefilter('error') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment