Ejemplo n.º 1
0
def CommandLineCleanOutputFilename(output_filename, output_stream):
    output_stream = StreamDecorator(output_stream)

    if not os.path.isfile(output_filename):
        output_stream.write("'{}' does not exist.\n".format(output_filename))
    else:
        output_stream.write("Removing '{}'...".format(output_filename))
        with output_stream.DoneManager():
            FileSystem.RemoveFile(output_filename)

    return 0
    def _CleanImplEx(cls, context, output_stream):
        output_stream = StreamDecorator(output_stream)
        input_items = set(cls.GetInputItems(context))

        for output_filename in context["output_filenames"]:
            if output_filename in input_items:
                continue

            if os.path.isfile(output_filename):
                output_stream.write("Removing '{}'...".format(output_filename))
                with output_stream.DoneManager():
                    FileSystem.RemoveFile(output_filename)

        return super(MultipleOutputMixin,
                     cls)._CleanImplEx(context, output_stream)
Ejemplo n.º 3
0
    def Clean(cls, context, optional_output_stream):
        """
        Handles the complexities associated with cleaning previously generated output,
        ultimately invoking _CleanImpl.
        """

        assert context
        output_stream = StreamDecorator(optional_output_stream)

        output_stream.write(
            cls._GetStatusText("Cleaning", context,
                               cls.GetInputItems(context)))
        with output_stream.DoneManager() as dm:
            dm.result = cls._CleanImpl(context, dm.stream) or 0
            return dm.result
Ejemplo n.º 4
0
def _Impl( display_sentinel,
           json_filename,
           result_filename,
           first,
           output_stream,
           method_name,
           parser,
         ):
    output_stream = StreamDecorator( output_stream,
                                     line_prefix=display_sentinel,
                                   )

    with open(json_filename) as f:
        try:
            data = parser(f.read(), is_root=True)
        except Exception as ex:
            output_stream.write("ERROR: {} ({})\n".format(str(ex), ex.stack))
            return -1

    output_stream.write("Parsing dependencies...")
    with output_stream.DoneManager():
        dependencies = ActivationData.Load(None, None, None).PrioritizedRepositories

    has_config_specific = False

    output_stream.write("Validating...")
    with output_stream.DoneManager() as dm:
        for index, repository_info in enumerate(dependencies):
            dm.stream.write("Processing '{}' ({} of {})...".format( repository_info.Name,
                                                                    index + 1,
                                                                    len(dependencies),
                                                                  ))
            with dm.stream.DoneManager() as this_dm:
                with Utilities.CustomMethodManager(os.path.join(repository_info.Root, Constants.HOOK_ENVIRONMENT_CUSTOMIZATION_FILENAME), method_name) as method:
                    if not method:
                        continue

                    args = OrderedDict([ ( "data", data ),
                                         ( "output_stream", this_dm.stream ),
                                       ])

                    # Get the method args to see if a configuration is requried
                    func_code = six.get_function_code(method)

                    if "configuration" in func_code.co_varnames[:func_code.co_argcount]:
                        args["configuration"] = repository_info.Configuration
                        has_config_specific = True
                    elif not first:
                        # Don't call a config-agnostic method more than once
                        continue

                    try:
                        this_dm.result = Interface.CreateCulledCallable(method)(args) or 0

                    except Exception as ex:
                        this_dm.stream.write(StringHelpers.LeftJustify( "ERROR: {}\n".format(str(ex).rstrip()),
                                                                        len("ERROR: "),
                                                                      ))
                        this_dm.result = -1

        with open(result_filename, 'w') as f:
            f.write('-1' if dm.result != 0 else '1' if has_config_specific else '0')

        return dm.result
Ejemplo n.º 5
0
    def _Invoke(cls, context, status_stream, verbose):
        """Handles the complexities of compiler invocation, ultimately calling _InvokeImpl."""

        assert context
        status_stream = StreamDecorator(status_stream)

        invoke_reason = cls._GetInvokeReason(
            context, StreamDecorator(status_stream if verbose else None))
        if invoke_reason is None:
            status_stream.write("No changes were detected.\n")
            return 0

        input_items = cls.GetInputItems(context)
        assert input_items

        status_stream.write(
            cls._GetStatusText(cls.InvokeVerb, context, input_items))
        with status_stream.DoneManager() as dm:
            if verbose:
                output_items = cls.GetOutputItems(context)

                if "display_name" in context or len(input_items) == 1:
                    indentation = 4
                else:
                    indentation = 8

                verbose_stream = StreamDecorator(
                    dm.stream,
                    prefix=StringHelpers.LeftJustify(
                        textwrap.dedent(
                            # <Wrong hanging indentation> pylint: disable = C0330
                            """\

                                                                                        ========================================
                                                                                        VERBOSE Output

                                                                                        {}
                                                                                                ->
                                                                                            {}
                                                                                        ========================================      
                                                                                        """
                        ).format(
                            '\n'.join(input_items),
                            StringHelpers.LeftJustify(
                                '\n'.join(output_items)
                                if output_items else "[None]", 4),
                        ),
                        2,
                        skip_first_line=False,
                    ),
                    suffix='\n',
                    line_prefix=' ' * indentation,
                )
                status_stream = verbose_stream
            else:
                status_stream = dm.stream
                verbose_stream = StreamDecorator(None)

            dm.result = cls._InvokeImpl(
                invoke_reason,
                context,
                status_stream,
                verbose_stream,
                verbose,
            ) or 0

            if dm.result >= 0:
                cls._PersistContext(context)

            return dm.result