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."""
28 sys
.path
= [os
.path
.dirname(__file__
)] + sys
.path
35 wrapper_util
.reject_old_python_versions((2, 7))
37 _DIR_PATH
= wrapper_util
.get_dir_path(__file__
, os
.path
.join('lib', 'ipaddr'))
38 _PATHS
= wrapper_util
.Paths(_DIR_PATH
)
44 EXTRA_PATHS
= _PATHS
.v2_extra_paths
47 def fix_sys_path(extra_extra_paths
=()):
48 """Fix the sys.path to include our extra paths.
50 fix_sys_path should be called before running testbed-based unit tests so that
51 third-party modules are correctly added to sys.path.
53 sys
.path
[1:1] = EXTRA_PATHS
56 def _run_file(file_path
, globals_
):
57 """Execute the given script with the passed-in globals.
60 file_path: the path to the wrapper for the given script. This will usually
61 be a copy of this file.
62 globals_: the global bindings to be used while executing the wrapped script.
64 script_name
= os
.path
.basename(file_path
)
66 sys
.path
= (_PATHS
.script_paths(script_name
) +
67 _PATHS
.scrub_path(script_name
, sys
.path
))
75 if 'google' in sys
.modules
:
76 del sys
.modules
['google']
78 execfile(_PATHS
.script_file(script_name
), globals_
)
81 if __name__
== '__main__':
82 _run_file(__file__
, globals())