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')
45 os
.path
.join(DIR_PATH
, 'lib', 'antlr3'),
46 os
.path
.join(DIR_PATH
, 'lib', 'django_0_96'),
47 os
.path
.join(DIR_PATH
, 'lib', 'fancy_urllib'),
48 os
.path
.join(DIR_PATH
, 'lib', 'ipaddr'),
49 os
.path
.join(DIR_PATH
, 'lib', 'jinja2'),
50 os
.path
.join(DIR_PATH
, 'lib', 'protorpc'),
51 os
.path
.join(DIR_PATH
, 'lib', 'PyAMF'),
52 os
.path
.join(DIR_PATH
, 'lib', 'markupsafe'),
53 os
.path
.join(DIR_PATH
, 'lib', 'webob_0_9'),
54 os
.path
.join(DIR_PATH
, 'lib', 'webapp2'),
55 os
.path
.join(DIR_PATH
, 'lib', 'yaml', 'lib'),
56 os
.path
.join(DIR_PATH
, 'lib', 'simplejson'),
57 os
.path
.join(DIR_PATH
, 'lib', 'google.appengine._internal.graphy'),
60 API_SERVER_EXTRA_PATHS
= [
61 os
.path
.join(DIR_PATH
, 'lib', 'argparse'),
63 API_SERVER_EXTRA_PATH_SCRIPTS
= 'api_server'
66 OAUTH_CLIENT_EXTRA_PATHS
= [
67 os
.path
.join(DIR_PATH
, 'lib', 'google-api-python-client'),
68 os
.path
.join(DIR_PATH
, 'lib', 'httplib2'),
69 os
.path
.join(DIR_PATH
, 'lib', 'python-gflags'),
72 OAUTH_CLIENT_EXTRA_PATH_SCRIPTS
= '(appcfg|bulkloader)'
75 GOOGLE_SQL_EXTRA_PATHS
= OAUTH_CLIENT_EXTRA_PATHS
+ [
76 os
.path
.join(DIR_PATH
, 'lib', 'enum'),
77 os
.path
.join(DIR_PATH
, 'lib', 'grizzled'),
78 os
.path
.join(DIR_PATH
, 'lib', 'oauth2'),
79 os
.path
.join(DIR_PATH
, 'lib', 'prettytable'),
80 os
.path
.join(DIR_PATH
, 'lib', 'sqlcmd'),
83 GOOGLE_SQL_EXTRA_PATH_SCRIPTS
= 'google_sql'
88 "dev_appserver.py" : "dev_appserver_main.py"
91 SCRIPT_DIR_EXCEPTIONS
= {
92 'google_sql.py': GOOGLE_SQL_DIR
,
96 def fix_sys_path(extra_extra_paths
=()):
97 """Fix the sys.path to include our extra paths."""
98 extra_paths
= EXTRA_PATHS
[:]
99 extra_paths
.extend(extra_extra_paths
)
100 sys
.path
= extra_paths
+ sys
.path
103 def run_file(file_path
, globals_
, script_dir
=SCRIPT_DIR
):
104 """Execute the file at the specified path with the passed-in globals."""
105 script_name
= os
.path
.basename(file_path
)
107 if re
.match(OAUTH_CLIENT_EXTRA_PATH_SCRIPTS
, script_name
):
108 extra_extra_paths
= OAUTH_CLIENT_EXTRA_PATHS
109 elif re
.match(GOOGLE_SQL_EXTRA_PATH_SCRIPTS
, script_name
):
110 extra_extra_paths
= GOOGLE_SQL_EXTRA_PATHS
111 elif re
.match(API_SERVER_EXTRA_PATH_SCRIPTS
, script_name
):
112 extra_extra_paths
= API_SERVER_EXTRA_PATHS
114 extra_extra_paths
= []
115 fix_sys_path(extra_extra_paths
)
123 if 'google' in sys
.modules
:
124 del sys
.modules
['google']
126 script_name
= SCRIPT_EXCEPTIONS
.get(script_name
, script_name
)
127 script_dir
= SCRIPT_DIR_EXCEPTIONS
.get(script_name
, script_dir
)
128 script_path
= os
.path
.join(script_dir
, script_name
)
129 execfile(script_path
, globals_
)
132 if __name__
== '__main__':
133 run_file(__file__
, globals())