App Engine Python SDK version 1.9.12
[gae.git] / python / download_appstats.py
blobde775b6989a12224144e64e9a0f8e917c8b126b5
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."""
23 import os
24 import sys
26 sys_path = sys.path
27 try:
28 sys.path = [os.path.dirname(__file__)] + sys.path
30 import wrapper_util
32 finally:
33 sys.path = sys_path
35 wrapper_util.reject_old_python_versions((2, 5))
40 def get_dir_path(sibling):
41 """Get a path to the directory of this script.
43 By default, the canonical path (symlinks resolved) will be returned. In some
44 environments the canonical directory is not sufficient because different
45 parts of the SDK are referenced by symlinks, including this very module's
46 file. In this case, the non-canonical path to this file's directory will be
47 returned (i.e., the directory where the symlink lives, not the directory
48 where it points).
50 Args:
51 sibling: Relative path to a sibling of this module file. Choose a sibling
52 that is potentially symlinked into the parent directory.
54 Returns:
55 A directory name.
57 Raises:
58 ValueError: If no proper path could be determined.
59 """
60 return wrapper_util.get_dir_path(__file__, sibling)
74 DIR_PATH = get_dir_path(os.path.join('lib', 'ipaddr'))
75 _PATHS = wrapper_util.Paths(DIR_PATH)
77 SCRIPT_DIR = _PATHS.default_script_dir
78 GOOGLE_SQL_DIR = _PATHS.google_sql_dir
80 EXTRA_PATHS = _PATHS.v1_extra_paths
82 API_SERVER_EXTRA_PATHS = _PATHS.api_server_extra_paths
84 ENDPOINTSCFG_EXTRA_PATHS = _PATHS.endpointscfg_extra_paths
87 OAUTH_CLIENT_EXTRA_PATHS = _PATHS.oauth_client_extra_paths
90 GOOGLE_SQL_EXTRA_PATHS = _PATHS.google_sql_extra_paths
95 def fix_sys_path(extra_extra_paths=()):
96 """Fix the sys.path to include our extra paths."""
97 sys.path = EXTRA_PATHS + list(extra_extra_paths) + sys.path
100 def run_file(file_path, globals_):
101 """Execute the given script with the passed-in globals.
103 Args:
104 file_path: the path to the wrapper for the given script. This will usually
105 be a copy of this file.
106 globals_: the global bindings to be used while executing the wrapped script.
108 script_name = os.path.basename(file_path)
110 sys.path = (_PATHS.script_paths(script_name) +
111 _PATHS.scrub_path(script_name, sys.path))
119 if 'google' in sys.modules:
120 del sys.modules['google']
122 execfile(_PATHS.script_file(script_name), globals_)
125 if __name__ == '__main__':
126 run_file(__file__, globals())