PageRenderTime 223ms CodeModel.GetById 121ms app.highlight 4ms RepoModel.GetById 96ms app.codeStats 0ms

/silverlining/init-files/sitecustomize.py

https://bitbucket.org/ianb/silverlining/
Python | 35 lines | 31 code | 3 blank | 1 comment | 4 complexity | 3976e17858cacd24dfff25c127f1efd2 MD5 | raw file
 1import os
 2import site
 3import sys
 4site.addsitedir(os.path.abspath(os.path.join(__file__, '../../python')))
 5import warnings
 6from ConfigParser import ConfigParser
 7
 8
 9def add_silversupport():
10    silverlining_conf = os.path.join(os.environ['HOME'], '.silverlining.conf')
11    parser = ConfigParser()
12    parser.read([silverlining_conf])
13    if (not parser.has_section('environment')
14        or not parser.has_option('environment', 'silverlining_location')):
15        warnings.warn('Problem loading %s: no [environment] silverlining_location setting'
16                      % silverlining_conf)
17        return
18    # Now we make silversupport importable:
19    silverlining_location = parser.get('environment', 'silverlining_location')
20    silversupport_location = os.path.dirname(silverlining_location)
21    sys.path.append(silversupport_location)
22
23if (not os.environ.get('SILVER_VERSION', '').startswith('silverlining/')
24    and not os.path.exists('/usr/local/share/silverlining/lib')):
25    # Not a production environment...
26    add_silversupport()
27    from silversupport.appconfig import AppConfig
28    app_config = AppConfig(os.path.abspath(os.path.join(__file__, '../../../app.ini')))
29    app_config.activate_services(os.environ)
30    os.environ.setdefault('SILVER_VERSION', 'devel/0.0')
31
32try:
33    import silvercustomize
34except ImportError:
35    pass