forked from sydney-linux-user-group/slug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
80 lines (60 loc) · 1.84 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/python
#
# -*- coding: utf-8 -*-
# vim: set ts=4 sw=4 et sts=4 ai:
"""Module which setups our configuration environment.
**
Everything should import this module and run the setup function before
doing anything else, *including imports*!
**
"""
import sys
import os
HOST = None
def getpaths():
"""Get the extra third_party paths we need."""
paths = set()
for line in file('third_party.paths', 'r'):
if line.startswith('#'):
continue
paths.add(line.strip().split(' ', 1)[0])
paths = list(paths)
paths.sort()
return paths
def sys_path_insert(ipath):
"""Insert a path into sys if it doesn't exist already."""
if ipath not in sys.path:
sys.path.insert(0, ipath)
def setup_django():
"""Setup the django settings."""
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.2')
def setup(host=None):
"""Setup our configuration environment."""
global HOST # pylint: disable-msg=W0603
if HOST is None:
if host is None:
HOST = 'www.slug.org.au'
else:
HOST = host
# Add our extra modules to sys.path
sys_path_insert('third_party.zip')
for ipath in getpaths():
if 'third_party.zip' in ipath:
continue
sys_path_insert(ipath)
setup_django()
def lint_setup():
"""Setup called to make pylint work."""
if not "APPENGINE_SDK" in os.environ:
print "Please set $APPENGINE_SDK to the location of the appengine SDK."
return 1
print "APPENGINE_SDK at ", os.environ["APPENGINE_SDK"]
sys_path_insert(os.environ["APPENGINE_SDK"])
for ipath in getpaths():
sys_path_insert(ipath.replace('.zip', ''))
setup_django()
if __name__ == "__main__":
for path in getpaths():
print path