def ReportMetrics(self): """Reports the collected metrics using a separate async process.""" if not self._metrics: return temp_metrics_file = tempfile.NamedTemporaryFile(delete=False) with temp_metrics_file: pickle.dump(self._metrics, temp_metrics_file) self._metrics = [] reporting_script_path = os.path.join( config.GoogleCloudSDKPackageRoot(), 'core', 'metrics_reporter.py') execution_args = execution_utils.ArgsForPythonTool( reporting_script_path, temp_metrics_file.name) exec_env = os.environ.copy() python_path_var = 'PYTHONPATH' python_path = exec_env.get(python_path_var) if python_path: python_path += os.pathsep + config.LibraryRoot() else: python_path = config.LibraryRoot() exec_env[python_path_var] = python_path subprocess.Popen(execution_args, env=exec_env, **self._async_popen_args) log.debug('Metrics reporting process started...')
def do_GET(self): """Handle a GET request. Parses the query parameters and prints a message if the flow has completed. Note that we can't detect if an error occurred. """ self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() query = self.path.split('?', 1)[-1] query = dict(parse_qsl(query)) self.server.query_params = query if 'code' in query: page = 'oauth2_landing.html' else: page = 'oauth2_landing_error.html' html_path = os.path.join( config.GoogleCloudSDKPackageRoot(), 'core', 'credentials', page) with open(html_path) as html_file: self.wfile.write(html_file.read())
def CreateCLI(): """Generates the gcloud CLI.""" pkg_root = config.GoogleCloudSDKPackageRoot() loader = cli.CLILoader(name='gcloud', command_root_directory=os.path.join( pkg_root, 'gcloud', 'sdktools', 'root'), allow_non_existing_modules=True, version_func=VersionFunc) loader.AddReleaseTrack(base.ReleaseTrack.ALPHA, os.path.join(pkg_root, 'gcloud', 'sdktools', 'alpha'), component='alpha') loader.AddReleaseTrack(base.ReleaseTrack.BETA, os.path.join(pkg_root, 'gcloud', 'sdktools', 'beta'), component='beta') loader.AddModule('auth', os.path.join(pkg_root, 'gcloud', 'sdktools', 'auth')) loader.AddModule('bigquery', os.path.join(pkg_root, 'bigquery', 'commands')) loader.AddModule('bigtable', os.path.join(pkg_root, 'bigtable', 'commands')) loader.AddModule( 'components', os.path.join(pkg_root, 'gcloud', 'sdktools', 'components')) loader.AddModule('compute', os.path.join(pkg_root, 'compute', 'subcommands'), component='compute') loader.AddModule('config', os.path.join(pkg_root, 'gcloud', 'sdktools', 'config')) loader.AddModule('container', os.path.join(pkg_root, 'container', 'commands'), component='gcloud') loader.AddModule('dataflow', os.path.join(pkg_root, 'dataflow', 'commands')) loader.AddModule('deployment_manager', os.path.join(pkg_root, 'deployment_manager', 'commands')) loader.AddModule('dns', os.path.join(pkg_root, 'dns', 'commands'), component='dns') loader.AddModule('endpoints', os.path.join(pkg_root, 'endpoints', 'commands')) loader.AddModule('internal', os.path.join(pkg_root, 'gcloud', 'sdktools', 'internal')) loader.AddModule('meta', os.path.join(pkg_root, 'gcloud', 'sdktools', 'meta')) loader.AddModule('preview', os.path.join(pkg_root, 'preview', 'commands'), component='preview') # Put app and datastore under preview for now. loader.AddModule('preview.analysis', os.path.join(pkg_root, 'analysis', 'commands')) loader.AddModule('preview.app', os.path.join(pkg_root, 'appengine', 'app_commands'), component='app') loader.AddModule('preview.datastore', os.path.join(pkg_root, 'appengine', 'datastore_commands'), component='app') loader.AddModule('genomics', os.path.join(pkg_root, 'genomics', 'commands')) # TODO(user): Put logging in preview for now. loader.AddModule('preview.logging', os.path.join(pkg_root, 'logging', 'commands')) loader.AddModule( 'preview.rolling_updates', os.path.join(pkg_root, 'updater', 'commands', 'rolling_updates')) loader.AddModule('preview.test', os.path.join(pkg_root, 'test', 'commands')) loader.AddModule('projects', os.path.join(pkg_root, 'projects', 'commands'), component='gcloud') loader.AddModule( 'services', os.path.join(pkg_root, 'service_management', 'subcommands')) loader.AddModule('source', os.path.join(pkg_root, 'source', 'commands')) loader.AddModule('sql', os.path.join(pkg_root, 'sql', 'tools'), component='sql') # Check for updates on shutdown but not for any of the updater commands. loader.RegisterPostRunHook(UpdateCheck, exclude_commands=r'gcloud\.components\..*') return loader.Generate()
def GoogleCloudSDKPackageRoot(): return config.GoogleCloudSDKPackageRoot()