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."""
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')
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
)
38 DIR_PATH
= os
.path
.abspath(os
.path
.dirname(os
.path
.realpath(__file__
)))
39 SCRIPT_DIR
= os
.path
.join(DIR_PATH
, 'google', 'appengine', 'tools')
40 GOOGLE_SQL_DIR
= os
.path
.join(
41 DIR_PATH
, 'google', 'storage', 'speckle', 'python', 'tool')
47 os
.path
.join(DIR_PATH
, 'lib', 'antlr3'),
48 os
.path
.join(DIR_PATH
, 'lib', 'django_0_96'),
49 os
.path
.join(DIR_PATH
, 'lib', 'fancy_urllib'),
50 os
.path
.join(DIR_PATH
, 'lib', 'ipaddr'),
51 os
.path
.join(DIR_PATH
, 'lib', 'jinja2'),
52 os
.path
.join(DIR_PATH
, 'lib', 'protorpc'),
53 os
.path
.join(DIR_PATH
, 'lib', 'markupsafe'),
54 os
.path
.join(DIR_PATH
, 'lib', 'webob_0_9'),
55 os
.path
.join(DIR_PATH
, 'lib', 'webapp2'),
56 os
.path
.join(DIR_PATH
, 'lib', 'yaml', 'lib'),
57 os
.path
.join(DIR_PATH
, 'lib', 'simplejson'),
58 os
.path
.join(DIR_PATH
, 'lib', 'google.appengine._internal.graphy'),
61 API_SERVER_EXTRA_PATHS
= [
62 os
.path
.join(DIR_PATH
, 'lib', 'argparse'),
64 API_SERVER_EXTRA_PATH_SCRIPTS
= 'api_server'
67 OAUTH_CLIENT_EXTRA_PATHS
= [
68 os
.path
.join(DIR_PATH
, 'lib', 'google-api-python-client'),
69 os
.path
.join(DIR_PATH
, 'lib', 'httplib2'),
70 os
.path
.join(DIR_PATH
, 'lib', 'python-gflags'),
73 OAUTH_CLIENT_EXTRA_PATH_SCRIPTS
= '(appcfg|bulkloader)'
76 GOOGLE_SQL_EXTRA_PATHS
= OAUTH_CLIENT_EXTRA_PATHS
+ [
77 os
.path
.join(DIR_PATH
, 'lib', 'enum'),
78 os
.path
.join(DIR_PATH
, 'lib', 'grizzled'),
79 os
.path
.join(DIR_PATH
, 'lib', 'oauth2'),
80 os
.path
.join(DIR_PATH
, 'lib', 'prettytable'),
81 os
.path
.join(DIR_PATH
, 'lib', 'sqlcmd'),
84 GOOGLE_SQL_EXTRA_PATH_SCRIPTS
= 'google_sql'
89 "dev_appserver.py" : "dev_appserver_main.py"
92 SCRIPT_DIR_EXCEPTIONS
= {
93 'google_sql.py': GOOGLE_SQL_DIR
,
97 def fix_sys_path(extra_extra_paths
=()):
98 """Fix the sys.path to include our extra paths."""
99 extra_paths
= EXTRA_PATHS
[:]
100 extra_paths
.extend(extra_extra_paths
)
101 sys
.path
= extra_paths
+ sys
.path
104 def run_file(file_path
, globals_
, script_dir
=SCRIPT_DIR
):
105 """Execute the file at the specified path with the passed-in globals."""
106 script_name
= os
.path
.basename(file_path
)
108 if re
.match(OAUTH_CLIENT_EXTRA_PATH_SCRIPTS
, script_name
):
109 extra_extra_paths
= OAUTH_CLIENT_EXTRA_PATHS
110 elif re
.match(GOOGLE_SQL_EXTRA_PATH_SCRIPTS
, script_name
):
111 extra_extra_paths
= GOOGLE_SQL_EXTRA_PATHS
112 elif re
.match(API_SERVER_EXTRA_PATH_SCRIPTS
, script_name
):
113 extra_extra_paths
= API_SERVER_EXTRA_PATHS
115 extra_extra_paths
= []
116 fix_sys_path(extra_extra_paths
)
118 script_name
= SCRIPT_EXCEPTIONS
.get(script_name
, script_name
)
119 script_dir
= SCRIPT_DIR_EXCEPTIONS
.get(script_name
, script_dir
)
120 script_path
= os
.path
.join(script_dir
, script_name
)
121 execfile(script_path
, globals_
)
124 if __name__
== '__main__':
125 run_file(__file__
, globals())