Skip to content

Instantly share code, notes, and snippets.

@ods
Created June 20, 2013 13:46
Show Gist options
  • Save ods/5822818 to your computer and use it in GitHub Desktop.
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
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