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', 'PyAMF'),
54 os
.path
.join(DIR_PATH
, 'lib', 'markupsafe'),
55 os
.path
.join(DIR_PATH
, 'lib', 'webob_0_9'),
56 os
.path
.join(DIR_PATH
, 'lib', 'webapp2'),
57 os
.path
.join(DIR_PATH
, 'lib', 'yaml', 'lib'),
58 os
.path
.join(DIR_PATH
, 'lib', 'simplejson'),
59 os
.path
.join(DIR_PATH
, 'lib', 'google.appengine._internal.graphy'),
62 API_SERVER_EXTRA_PATHS
= [
63 os
.path
.join(DIR_PATH
, 'lib', 'argparse'),
65 API_SERVER_EXTRA_PATH_SCRIPTS
= 'api_server'
68 OAUTH_CLIENT_EXTRA_PATHS
= [
69 os
.path
.join(DIR_PATH
, 'lib', 'google-api-python-client'),
70 os
.path
.join(DIR_PATH
, 'lib', 'httplib2'),
71 os
.path
.join(DIR_PATH
, 'lib', 'python-gflags'),
74 OAUTH_CLIENT_EXTRA_PATH_SCRIPTS
= '(appcfg|bulkloader)'
77 GOOGLE_SQL_EXTRA_PATHS
= OAUTH_CLIENT_EXTRA_PATHS
+ [
78 os
.path
.join(DIR_PATH
, 'lib', 'enum'),
79 os
.path
.join(DIR_PATH
, 'lib', 'grizzled'),
80 os
.path
.join(DIR_PATH
, 'lib', 'oauth2'),
81 os
.path
.join(DIR_PATH
, 'lib', 'prettytable'),
82 os
.path
.join(DIR_PATH
, 'lib', 'sqlcmd'),
85 GOOGLE_SQL_EXTRA_PATH_SCRIPTS
= 'google_sql'
90 "dev_appserver.py" : "dev_appserver_main.py"
93 SCRIPT_DIR_EXCEPTIONS
= {
94 'google_sql.py': GOOGLE_SQL_DIR
,
98 def fix_sys_path(extra_extra_paths
=()):
99 """Fix the sys.path to include our extra paths."""
100 extra_paths
= EXTRA_PATHS
[:]
101 extra_paths
.extend(extra_extra_paths
)
102 sys
.path
= extra_paths
+ sys
.path
105 def run_file(file_path
, globals_
, script_dir
=SCRIPT_DIR
):
106 """Execute the file at the specified path with the passed-in globals."""
107 script_name
= os
.path
.basename(file_path
)
109 if re
.match(OAUTH_CLIENT_EXTRA_PATH_SCRIPTS
, script_name
):
110 extra_extra_paths
= OAUTH_CLIENT_EXTRA_PATHS
111 elif re
.match(GOOGLE_SQL_EXTRA_PATH_SCRIPTS
, script_name
):
112 extra_extra_paths
= GOOGLE_SQL_EXTRA_PATHS
113 elif re
.match(API_SERVER_EXTRA_PATH_SCRIPTS
, script_name
):
114 extra_extra_paths
= API_SERVER_EXTRA_PATHS
116 extra_extra_paths
= []
117 fix_sys_path(extra_extra_paths
)
119 script_name
= SCRIPT_EXCEPTIONS
.get(script_name
, script_name
)
120 script_dir
= SCRIPT_DIR_EXCEPTIONS
.get(script_name
, script_dir
)
121 script_path
= os
.path
.join(script_dir
, script_name
)
122 execfile(script_path
, globals_
)
125 if __name__
== '__main__':
126 run_file(__file__
, globals())