Beispiel #1
0
    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 Start(self, *positional, **flags):
        """Start the dev_appserver.

    Args:
      *positional: str, The positional arguments to be passed to dev_appserver.
      **flags: str, The flags to be passed to dev_appserver.

    Raises:
      DevappserverExecutionError: If devappserver execution returns an error.
    """
        all_flags = dict(self._global_flags)
        all_flags.update(flags)
        # Don't include the script name in argv because we are hijacking the parse
        # method.
        argv = (self._GenerateFlags(all_flags) +
                [arg for arg in positional if arg is not None])
        log.debug('Running [dev_appserver.py] with: {cmd}'.format(
            cmd=' '.join(argv)))
        run_args = execution_utils.ArgsForPythonTool(self.__executable_path,
                                                     *argv)
        # TODO(user): Take this out (b/19485297).  This is because the
        # devappserver is depending on our pythonpath right now (it should not in
        # the future (b/19443812).  We need to do this because if something invokes
        # gcloud.py directly, the sys.path is updated but is never put in the env.
        # If you call gcloud.sh then it does put it in the env so this is not
        # required.
        env = dict(os.environ)
        env['PYTHONPATH'] = os.pathsep.join(sys.path)
        return_code = subprocess.call(run_args, env=env)
        if return_code != 0:
            raise DevappserverExecutionError(return_code, argv)
Beispiel #3
0
def ExecutePythonTool(tool_dir, exec_name, *args):
    """Execute the given python script with the given args and command line.

  Args:
    tool_dir: the directory the tool is located in
    exec_name: additional path to the executable under the tool_dir
    *args: args for the command
  """
    _ExecuteTool(
        execution_utils.ArgsForPythonTool(_FullPath(tool_dir, exec_name),
                                          *args))
Beispiel #4
0
def RestartGcloud():
    """Calls gcloud again with the same arguments as this invocation and exit."""
    gcloud = os.path.join(os.path.dirname(googlecloudsdk.__file__), 'gcloud',
                          'gcloud.py')
    gcloud_args = sys.argv[1:]
    args = execution_utils.ArgsForPythonTool(gcloud, *tuple(gcloud_args))

    log.status.Print('Restarting gcloud command:\n  $ gcloud {args}\n'.format(
        args=' '.join(gcloud_args)))
    log.debug('Restarting gcloud: %s', args)
    log.out.flush()
    log.err.flush()

    execution_utils.Exec(args)