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.
17 """Convenience wrapper for starting an appengine tool."""
29 sys
.path
= [os
.path
.dirname(__file__
)] + sys
.path
36 wrapper_util
.reject_old_python_versions((2, 7))
38 _DIR_PATH
= wrapper_util
.get_dir_path(__file__
, os
.path
.join('lib', 'ipaddr'))
39 _PATHS
= wrapper_util
.Paths(_DIR_PATH
)
45 EXTRA_PATHS
= _PATHS
.v2_extra_paths
48 def fix_sys_path(extra_extra_paths
=()):
49 """Fix the sys.path to include our extra paths.
51 fix_sys_path should be called before running testbed-based unit tests so that
52 third-party modules are correctly added to sys.path.
54 sys
.path
[1:1] = EXTRA_PATHS
57 def _run_file(file_path
, globals_
):
58 """Execute the given script with the passed-in globals.
61 file_path: the path to the wrapper for the given script. This will usually
62 be a copy of this file.
63 globals_: the global bindings to be used while executing the wrapped script.
65 script_name
= os
.path
.basename(file_path
)
67 sys
.path
= (_PATHS
.script_paths(script_name
) +
68 _PATHS
.scrub_path(script_name
, sys
.path
))
76 if 'google' in sys
.modules
:
77 del sys
.modules
['google']
79 execfile(_PATHS
.script_file(script_name
), globals_
)
82 if __name__
== '__main__':
83 _run_file(__file__
, globals())