-
Notifications
You must be signed in to change notification settings - Fork 8
/
appengine_config.py
executable file
·84 lines (64 loc) · 3.07 KB
/
appengine_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
81
82
83
84
# Copyright 2013 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Custom configurations and functions for Google App Engine."""
__author__ = '[email protected] (Pavel Simakov)'
import os
import sys
# Whether we are running in the production environment.
PRODUCTION_MODE = not os.environ.get(
'SERVER_SOFTWARE', 'Development').startswith('Development')
# Set this flag to true to enable bulk downloads of Javascript/CSS files in lib
BUNDLE_LIB_FILES = False
# this is the official location of this app for computing of all relative paths
BUNDLE_ROOT = os.path.dirname(__file__)
# make all Windows and Linux paths have the same separator '/'
BUNDLE_ROOT = BUNDLE_ROOT.replace('\\', '/')
# Default namespace name is '' and not None.
DEFAULT_NAMESPACE_NAME = ''
# Third-party library zip files.
THIRD_PARTY_LIBS = ['babel-0.9.6.zip', 'gaepytz-2011h.zip']
def gcb_force_default_encoding(encoding):
"""Force default encoding to a specific value."""
# Eclipse silently sets default encoding to 'utf-8', while GAE forces
# 'ascii'. We need to control this directly for consistency.
if not sys.getdefaultencoding() == encoding:
reload(sys)
sys.setdefaultencoding(encoding)
def gcb_init_third_party():
"""Add all third party libraries to system path."""
for lib in THIRD_PARTY_LIBS:
thirdparty_lib = os.path.join(BUNDLE_ROOT, 'lib/%s' % lib)
if not os.path.exists(thirdparty_lib):
raise Exception('Library does not exist: %s' % thirdparty_lib)
sys.path.insert(0, thirdparty_lib)
def gcb_configure_dev_server_if_running():
"""Configure various aspects of development server if not production."""
if not PRODUCTION_MODE:
# pylint: disable-msg=g-import-not-at-top
from google.appengine.api import apiproxy_stub_map
from google.appengine.datastore import datastore_stub_util
# Make dev_appserver run with PseudoRandomHRConsistencyPolicy, which we
# believe is the best for localhost manual testing; normally
# dev_appserver runs either under MasterSlave policy, which does not
# allow XG transactions, or under TimeBasedHR policy, which serves
# counter-intuitive dirty query results; this also matches policy for
# the functional tests
stub = apiproxy_stub_map.apiproxy.GetStub(
'datastore_v3')
if stub:
policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
probability=1)
stub.SetConsistencyPolicy(policy)
gcb_init_third_party()
gcb_configure_dev_server_if_running()