Exemplo n.º 1
0
def _RunGsutilCommand(command_name, command_arg_str, run_concurrent=False):
    """Runs the specified gsutil command and returns the command's exit code.

  Args:
    command_name: The gsutil command to run.
    command_arg_str: Arguments to pass to the command.
    run_concurrent: Whether concurrent uploads should be enabled while running
      the command.

  Returns:
    The exit code of the call to the gsutil command.
  """
    command_path = _GetGsutilPath()

    if run_concurrent:
        command_args = ['-m', command_name]
    else:
        command_args = [command_name]

    command_args += command_arg_str.split(' ')
    env = None

    if platforms.OperatingSystem.Current(
    ) == platforms.OperatingSystem.WINDOWS:
        gsutil_args = execution_utils.ArgsForCMDTool(command_path + '.cmd',
                                                     *command_args)
    else:
        gsutil_args = execution_utils.ArgsForShellTool(command_path,
                                                       *command_args)
    log.debug('Running command: [{args}], Env: [{env}]'.format(
        args=' '.join(gsutil_args), env=env))
    return execution_utils.Exec(gsutil_args,
                                no_exit=True,
                                env=env,
                                pipe_output_through_logger=True)
Exemplo n.º 2
0
def ExecuteShellTool(tool_dir, exec_name, *args):
  """Execute the given bash script with the given args.

  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.ArgsForShellTool(_FullPath(tool_dir, exec_name), *args))
Exemplo n.º 3
0
def ArgsForGCDEmulator(*args):
    """Constucts an argument list for calling the GCD emulator.

  Args:
    *args: args for the emulator.

  Returns:
    An argument list to execute the GCD emulator.
  """
    current_os = platforms.OperatingSystem.Current()
    if current_os is platforms.OperatingSystem.WINDOWS:
        gcd_executable = os.path.join(GetGCDRoot(), 'gcd.cmd')
        return execution_utils.ArgsForCMDTool(gcd_executable, *args)
    else:
        gcd_executable = os.path.join(GetGCDRoot(), 'gcd.sh')
        return execution_utils.ArgsForShellTool(gcd_executable, *args)
def BuildStartArgs(args, current_os):
  """Builds the command for starting the pubsub emulator.

  Args:
    args: (list of str) The arguments for the pubsub emulator, excluding the
      program binary.
    current_os: (platforms.OperatingSystem)

  Returns:
    A list of command arguments.
  """
  pubsub_dir = GetPubSubRoot()
  if current_os is platforms.OperatingSystem.WINDOWS:
    pubsub_executable = os.path.join(pubsub_dir, r'bin\cloud-pubsub-fake.bat')
    return execution_utils.ArgsForCMDTool(pubsub_executable, *args)

  pubsub_executable = os.path.join(pubsub_dir, 'bin/cloud-pubsub-fake')
  return execution_utils.ArgsForShellTool(pubsub_executable, *args)
Exemplo n.º 5
0
    def _CreateBotoConfig(self):
        gsutil_path = _FindGsutil()
        if not gsutil_path:
            log.debug('Unable to find [gsutil]. Not configuring default .boto '
                      'file')
            return

        boto_path = platforms.ExpandHomePath(os.path.join('~', '.boto'))
        if os.path.exists(boto_path):
            log.debug('Not configuring default .boto file. File already '
                      'exists at [{boto_path}].'.format(boto_path=boto_path))
            return

        # 'gsutil config -n' creates a default .boto file that the user can read and
        # modify.
        command_args = ['config', '-n', '-o', boto_path]
        if platforms.OperatingSystem.Current(
        ) == platforms.OperatingSystem.WINDOWS:
            gsutil_args = execution_utils.ArgsForCMDTool(
                gsutil_path, *command_args)
        else:
            gsutil_args = execution_utils.ArgsForShellTool(
                gsutil_path, *command_args)

        return_code = execution_utils.Exec(gsutil_args,
                                           no_exit=True,
                                           pipe_output_through_logger=True,
                                           file_only_logger=True)
        if return_code == 0:
            log.status.write("""\
Created a default .boto configuration file at [{boto_path}]. See this file and
[https://cloud.google.com/storage/docs/gsutil/commands/config] for more
information about configuring Google Cloud Storage.
""".format(boto_path=boto_path))

        else:
            log.status.write(
                'Error creating a default .boto configuration file. '
                'Please run [gsutil config -n] if you would like to '
                'create this file.\n')