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))
Exemplo n.º 2
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)