1.9.30 sync.
[gae.git] / python / bulkloader.py
blob833a338e89e9a4f39ead77f6002e18a4bc0602ea
1 #!/usr/bin/env python
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."""
24 import os
25 import sys
27 sys_path = sys.path
28 try:
29 sys.path = [os.path.dirname(__file__)] + sys.path
31 import wrapper_util
33 finally:
34 sys.path = sys_path
36 wrapper_util.reject_old_python_versions((2, 5))
41 def get_dir_path(sibling):
42 """Get a path to the directory of this script.
44 By default, the canonical path (symlinks resolved) will be returned. In some
45 environments the canonical directory is not sufficient because different
46 parts of the SDK are referenced by symlinks, including this very module's
47 file. In this case, the non-canonical path to this file's directory will be
48 returned (i.e., the directory where the symlink lives, not the directory
49 where it points).
51 Args:
52 sibling: Relative path to a sibling of this module file. Choose a sibling
53 that is potentially symlinked into the parent directory.
55 Returns:
56 A directory name.
58 Raises:
59 ValueError: If no proper path could be determined.
60 """
61 return wrapper_util.get_dir_path(__file__, sibling)
75 DIR_PATH = get_dir_path(os.path.join('lib', 'ipaddr'))
76 _PATHS = wrapper_util.Paths(DIR_PATH)
78 SCRIPT_DIR = _PATHS.default_script_dir
79 GOOGLE_SQL_DIR = _PATHS.google_sql_dir
81 EXTRA_PATHS = _PATHS.v1_extra_paths
83 API_SERVER_EXTRA_PATHS = _PATHS.api_server_extra_paths
85 ENDPOINTSCFG_EXTRA_PATHS = _PATHS.endpointscfg_extra_paths
88 OAUTH_CLIENT_EXTRA_PATHS = _PATHS.oauth_client_extra_paths
91 GOOGLE_SQL_EXTRA_PATHS = _PATHS.google_sql_extra_paths
96 def fix_sys_path(extra_extra_paths=()):
97 """Fix the sys.path to include our extra paths."""
98 sys.path = EXTRA_PATHS + list(extra_extra_paths) + sys.path
101 def run_file(file_path, globals_):
102 """Execute the given script with the passed-in globals.
104 Args:
105 file_path: the path to the wrapper for the given script. This will usually
106 be a copy of this file.
107 globals_: the global bindings to be used while executing the wrapped script.
109 script_name = os.path.basename(file_path)
111 sys.path = (_PATHS.script_paths(script_name) +
112 _PATHS.scrub_path(script_name, sys.path))
120 if 'google' in sys.modules:
121 del sys.modules['google']
123 execfile(_PATHS.script_file(script_name), globals_)
126 if __name__ == '__main__':
127 run_file(__file__, globals())