App Engine SDK 1.8.4 release.
[gae.git] / python / old_dev_appserver.py
blob661f26ea76112ee42bbab41e4339e1a43e024c47
1 #!/usr/bin/env python
3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
20 """Convenience wrapper for starting an appengine tool."""
23 import os
24 import re
25 import sys
28 if not hasattr(sys, 'version_info'):
29 sys.stderr.write('Very old versions of Python are not supported. Please '
30 'use version 2.5 or greater.\n')
31 sys.exit(1)
32 version_tuple = tuple(sys.version_info[:2])
33 if version_tuple < (2, 5):
34 sys.stderr.write('Error: Python %d.%d is not supported. Please use '
35 'version 2.5 or greater.\n' % version_tuple)
36 sys.exit(1)
39 def get_dir_path(sibling):
40 """Get a path to the directory of this script.
42 By default, the canonical path (symlinks resolved) will be returned. In some
43 environments the canonical directory is not sufficient because different
44 parts of the SDK are referenced by symlinks, including this very module's
45 file. In this case, the non-canonical path to this file's directory will be
46 returned (i.e., the directory where the symlink lives, not the directory
47 where it points).
49 Args:
50 sibling: Relative path to a sibiling of this module file. Choose a sibling
51 that is potentially symlinked into the parent directory.
53 Returns:
54 A directory name.
56 Raises:
57 ValueError: If no proper path could be determined.
58 """
59 if 'GAE_SDK_ROOT' in os.environ:
60 gae_sdk_root = os.path.abspath(os.environ['GAE_SDK_ROOT'])
64 os.environ['GAE_SDK_ROOT'] = gae_sdk_root
65 for dir_path in [gae_sdk_root,
66 os.path.join(gae_sdk_root, 'google_appengine')]:
67 if os.path.exists(os.path.join(dir_path, sibling)):
68 return dir_path
69 raise ValueError('GAE_SDK_ROOT %r does not refer to a valid SDK '
70 'directory' % gae_sdk_root)
71 else:
72 py_file = __file__.replace('.pyc', '.py')
73 dir_paths = [os.path.abspath(os.path.dirname(os.path.realpath(py_file))),
74 os.path.abspath(os.path.dirname(py_file))]
75 for dir_path in dir_paths:
76 sibling_path = os.path.join(dir_path, sibling)
77 if os.path.exists(sibling_path):
78 return dir_path
79 raise ValueError('Could not determine SDK root; please set GAE_SDK_ROOT '
80 'environment variable.')
90 DIR_PATH = get_dir_path(os.path.join('lib', 'ipaddr'))
91 SCRIPT_DIR = os.path.join(DIR_PATH, 'google', 'appengine', 'tools')
92 GOOGLE_SQL_DIR = os.path.join(
93 DIR_PATH, 'google', 'storage', 'speckle', 'python', 'tool')
95 EXTRA_PATHS = [
96 DIR_PATH,
97 os.path.join(DIR_PATH, 'lib', 'antlr3'),
98 os.path.join(DIR_PATH, 'lib', 'django-0.96'),
99 os.path.join(DIR_PATH, 'lib', 'fancy_urllib'),
100 os.path.join(DIR_PATH, 'lib', 'ipaddr'),
101 os.path.join(DIR_PATH, 'lib', 'jinja2-2.6'),
102 os.path.join(DIR_PATH, 'lib', 'protorpc'),
103 os.path.join(DIR_PATH, 'lib', 'PyAMF'),
104 os.path.join(DIR_PATH, 'lib', 'markupsafe'),
105 os.path.join(DIR_PATH, 'lib', 'webob_0_9'),
106 os.path.join(DIR_PATH, 'lib', 'webapp2-2.5.2'),
107 os.path.join(DIR_PATH, 'lib', 'yaml', 'lib'),
108 os.path.join(DIR_PATH, 'lib', 'simplejson'),
111 API_SERVER_EXTRA_PATHS = [
112 os.path.join(DIR_PATH, 'lib', 'argparse'),
114 API_SERVER_EXTRA_PATH_SCRIPTS = 'api_server'
117 OAUTH_CLIENT_EXTRA_PATHS = [
118 os.path.join(DIR_PATH, 'lib', 'google-api-python-client'),
119 os.path.join(DIR_PATH, 'lib', 'httplib2'),
120 os.path.join(DIR_PATH, 'lib', 'python-gflags'),
123 OAUTH_CLIENT_EXTRA_PATH_SCRIPTS = '(appcfg|bulkloader)'
126 GOOGLE_SQL_EXTRA_PATHS = OAUTH_CLIENT_EXTRA_PATHS + [
127 os.path.join(DIR_PATH, 'lib', 'enum'),
128 os.path.join(DIR_PATH, 'lib', 'grizzled'),
129 os.path.join(DIR_PATH, 'lib', 'oauth2'),
130 os.path.join(DIR_PATH, 'lib', 'prettytable'),
131 os.path.join(DIR_PATH, 'lib', 'sqlcmd'),
134 GOOGLE_SQL_EXTRA_PATH_SCRIPTS = 'google_sql'
138 SCRIPT_EXCEPTIONS = {
139 "old_dev_appserver.py" : "dev_appserver_main.py"
142 SCRIPT_DIR_EXCEPTIONS = {
143 'google_sql.py': GOOGLE_SQL_DIR,
147 def fix_sys_path(extra_extra_paths=()):
148 """Fix the sys.path to include our extra paths."""
149 extra_paths = EXTRA_PATHS[:]
150 extra_paths.extend(extra_extra_paths)
151 sys.path = extra_paths + sys.path
154 def run_file(file_path, globals_, script_dir=SCRIPT_DIR):
155 """Execute the file at the specified path with the passed-in globals."""
156 script_name = os.path.basename(file_path)
158 if re.match(OAUTH_CLIENT_EXTRA_PATH_SCRIPTS, script_name):
159 extra_extra_paths = OAUTH_CLIENT_EXTRA_PATHS
160 elif re.match(GOOGLE_SQL_EXTRA_PATH_SCRIPTS, script_name):
161 extra_extra_paths = GOOGLE_SQL_EXTRA_PATHS
162 elif re.match(API_SERVER_EXTRA_PATH_SCRIPTS, script_name):
163 extra_extra_paths = API_SERVER_EXTRA_PATHS
164 else:
165 extra_extra_paths = []
166 fix_sys_path(extra_extra_paths)
174 if 'google' in sys.modules:
175 del sys.modules['google']
177 script_name = SCRIPT_EXCEPTIONS.get(script_name, script_name)
178 script_dir = SCRIPT_DIR_EXCEPTIONS.get(script_name, script_dir)
179 script_path = os.path.join(script_dir, script_name)
180 execfile(script_path, globals_)
183 if __name__ == '__main__':
184 run_file(__file__, globals())