Пример #1
0
  def Run(self, args):
    """Run the upload command."""
    if not os.path.isdir(args.directory):
      raise exceptions.InvalidArgumentException(
          'directory', args.directory + ' is not a directory.')

    mgr = upload.UploadManager()
    result = mgr.Upload(args.branch, args.directory)

    output_dir = args.source_context_directory
    if output_dir:
      files.MakeDir(output_dir)
      output_dir = os.path.realpath(output_dir)
      extended_contexts = result['source_contexts']

      result['context_file'] = os.path.join(output_dir, 'source-context.json')
      best_context = context_util.BestSourceContext(extended_contexts)
      result['best_context'] = context_util.BestSourceContext(extended_contexts)
      files.WriteFileContents(result['context_file'], json.dumps(best_context))

    log.status.write('Wrote {0} file(s), {1} bytes.\n'.format(
        result['files_written'], result['size_written']))
    files_skipped = result['files_skipped']
    if files_skipped:
      log.status.write('Skipped {0} file(s) due to size limitations.\n'.format(
          files_skipped))
    return [result]
Пример #2
0
    def Run(self, args):
        """Run the capture upload command."""

        mgr = capture.CaptureManager()
        result = mgr.UploadCapture(args.capture_id, args.source_location,
                                   args.target_path)
        output_dir = args.output_directory
        files.MakeDir(output_dir)
        output_dir = os.path.realpath(output_dir)
        extended_contexts = result['source_contexts']

        result = dict(result)
        result['extended_context_file'] = os.path.join(output_dir,
                                                       'source-contexts.json')
        with open(result['extended_context_file'], 'w') as f:
            json.dump(extended_contexts, f)

        result['context_file'] = os.path.join(output_dir,
                                              'source-context.json')
        best_context = context_util.BestSourceContext(extended_contexts)
        result['best_context'] = context_util.BestSourceContext(
            extended_contexts)
        with open(result['context_file'], 'w') as f:
            json.dump(best_context, f)

        log.status.write('Wrote {0} file(s), {1} bytes.\n'.format(
            result['files_written'], result['size_written']))
        files_skipped = result['files_skipped']
        if files_skipped:
            log.status.write(
                'Skipped {0} file(s) due to size limitations.\n'.format(
                    files_skipped))
        return [result]
def _GetSourceContextsForUpload(source_dir):
  """Gets source context file information.

  Args:
    source_dir: str, path to the service's source directory
  Returns:
    A dict of filename to (str) source context file contents.
  """
  source_contexts = {}
  # Error message in case of failure.
  m = ('Could not generate [{name}]: {error}\n'
       'Stackdriver Debugger may not be configured or enabled on this '
       'application. See https://cloud.google.com/debugger/ for more '
       'information.')
  try:
    contexts = context_util.CalculateExtendedSourceContexts(source_dir)
  except context_util.GenerateSourceContextError as e:
    log.info(m.format(name=context_util.CONTEXT_FILENAME, error=e))
    return source_contexts

  try:
    context = context_util.BestSourceContext(contexts)
    source_contexts[context_util.CONTEXT_FILENAME] = json.dumps(context)
  except KeyError as e:
    log.info(m.format(name=context_util.CONTEXT_FILENAME, error=e))
  return source_contexts
    def Run(self, args):
        log.warning('This command is deprecated. Please use '
                    '`gcloud beta source debug gen-repo-info-file` instead.')
        contexts = context_util.CalculateExtendedSourceContexts(
            args.source_directory)

        # First create the old-style source-context.json file
        if args.output_file:
            log.warning(
                'The --output-file option is deprecated and will soon be removed.'
            )
            output_directory = os.path.dirname(args.output_file)
            output_file = args.output_file
        else:
            output_directory = ''
            output_file = context_util.CONTEXT_FILENAME

        if not output_directory:
            if args.output_directory:
                output_directory = args.output_directory
                output_file = os.path.join(output_directory, output_file)
            else:
                output_directory = '.'

        best_context = context_util.BestSourceContext(contexts)
        files.MakeDir(output_directory)
        files.WriteFileContents(
            output_file, json.dumps(best_context, indent=2, sort_keys=True))
  def Run(self, args):
    try:
      contexts = context_util.CalculateExtendedSourceContexts(
          args.source_directory)
    except context_util.GenerateSourceContextError as e:
      # This is a usage error. Wrap it with core_exceptions.Error to report
      # it properly (i.e., as an error instead of a crash).
      raise core_exceptions.Error(e)

    # Create the source-context.json file.
    output_file = context_util.CONTEXT_FILENAME

    output_directory = args.output_directory
    output_file = os.path.join(output_directory, output_file)

    if context_util.HasPendingChanges(args.source_directory):
      log.warning(
          'There are uncommitted changes in directory [{0}].\n'
          'The generated source context files will not reflect the current '
          'state of your source code.\n'
          'For best results, commit all changes and re-run this command.\n'
          .format(args.source_directory))
    best_context = context_util.BestSourceContext(contexts)
    files.MakeDir(output_directory)
    files.WriteFileContents(
        output_file, json.dumps(best_context, indent=2, sort_keys=True))
Пример #6
0
    def Run(self, args):
        contexts = context_util.CalculateExtendedSourceContexts(
            args.source_directory)

        # First create the old-style source-context.json file
        output_file = context_util.CONTEXT_FILENAME

        output_directory = args.output_directory
        output_file = os.path.join(output_directory, output_file)

        if context_util.HasPendingChanges(args.source_directory):
            log.warn(
                'There are uncommitted changes in directory [{0}].\n'
                'The generated source context files will not reflect the current '
                'state of your source code.\n'
                'For best results, commit all changes and re-run this command.\n'
                .format(args.source_directory))
        best_context = context_util.BestSourceContext(contexts)
        files.MakeDir(output_directory)
        with open(output_file, 'w') as f:
            json.dump(best_context, f, indent=2, sort_keys=True)

        # Create the new source-contexts.json file.
        with open(
                os.path.join(output_directory,
                             context_util.EXT_CONTEXT_FILENAME), 'w') as f:
            json.dump(contexts, f, indent=2, sort_keys=True)
Пример #7
0
def _GetSourceContextsForUpload(source_dir):
    """Gets source context file information.

  Args:
    source_dir: str, path to the service's source directory
  Returns:
    A dict of filename to (str) source context file contents.
  """
    source_contexts = {}
    try:
        contexts = context_util.CalculateExtendedSourceContexts(source_dir)
        source_contexts[context_util.EXT_CONTEXT_FILENAME] = json.dumps(
            contexts)
        context = context_util.BestSourceContext(contexts)
        source_contexts[context_util.CONTEXT_FILENAME] = json.dumps(context)
    # This error could either be raised by context_util.BestSourceContext or by
    # context_util.CalculateExtendedSourceContexts (in which case stop looking)
    except context_util.GenerateSourceContextError as e:
        log.warn('Could not generate [{name}]: {error}'.format(
            name=context_util.CONTEXT_FILENAME, error=e))
    return source_contexts
Пример #8
0
  def Run(self, args):
    contexts = context_util.CalculateExtendedSourceContexts(
        args.source_directory)

    # First create the old-style source-context.json file
    output_file = context_util.CONTEXT_FILENAME

    output_directory = args.output_directory
    output_file = os.path.join(output_directory, output_file)

    best_context = context_util.BestSourceContext(contexts,
                                                  args.source_directory)
    files.MakeDir(output_directory)
    with open(output_file, 'w') as f:
      json.dump(best_context, f, indent=2, sort_keys=True)

    # Create the new source-contexts.json file.
    with open(
        os.path.join(output_directory,
                     context_util.EXT_CONTEXT_FILENAME), 'w') as f:
      json.dump(contexts, f, indent=2, sort_keys=True)
Пример #9
0
    def Run(self, args):
        contexts = context_util.CalculateExtendedSourceContexts(
            args.source_directory)

        # First create the old-style source-context.json file
        if args.output_file:
            log.warn(
                'The --output-file option is deprecated and will soon be removed.'
            )
            output_directory = os.path.dirname(args.output_file)
            output_file = args.output_file
        else:
            output_directory = ''
            output_file = context_util.CONTEXT_FILENAME

        if not output_directory:
            if args.output_directory:
                output_directory = args.output_directory
                output_file = os.path.join(output_directory, output_file)
            else:
                output_directory = '.'

        best_context = context_util.BestSourceContext(contexts,
                                                      args.source_directory)
        files.MakeDir(output_directory)
        with open(output_file, 'w') as f:
            json.dump(best_context, f, indent=2, sort_keys=True)

        # Create the new source-contexts.json file.
        if args.output_directory and args.output_directory != output_directory:
            output_directory = args.output_directory
            files.MakeDir(output_directory)
        with open(
                os.path.join(output_directory,
                             context_util.EXT_CONTEXT_FILENAME), 'w') as f:
            json.dump(contexts, f, indent=2, sort_keys=True)