Exemple #1
0
    def __stage_handlers(self):
        """Push the handlers into the dictionary that we use to describe all 
        available handlers for this workflow.
        """

        scope = {}
        scope.update(mr.handlers.scope.SCOPE_INJECTED_TYPES)

        handler_count = 0
        for name, arg_names, version in self.__library.list_handlers():
            handler_count += 1

            if name in self.__staged_handlers:
                continue

            _logger.info("Compiling handler: [%s]", name)

            hd = self.__library.get_handler(name)

            self.__staged_handlers[name] = STAGED_HANDLER_CLS(
                                        definition=hd,
                                        argument_names=arg_names,
                                        basic_scope=scope)

        if handler_count == 0:
            _logger.warning("No handlers were presented by the library. No "
                            "code was compiled.")
Exemple #2
0
    def __stage_handlers(self):
        """Push the handlers into the dictionary that we use to describe all 
        available handlers for this workflow.
        """

        scope = {}
        scope.update(mr.handlers.scope.SCOPE_INJECTED_TYPES)

        handler_count = 0
        for name, arg_names, version in self.__library.list_handlers():
            handler_count += 1

            if name in self.__staged_handlers:
                continue

            _logger.info("Compiling handler: [%s]", name)

            hd = self.__library.get_handler(name)

            self.__staged_handlers[name] = STAGED_HANDLER_CLS(
                definition=hd, argument_names=arg_names, basic_scope=scope)

        if handler_count == 0:
            _logger.warning("No handlers were presented by the library. No "
                            "code was compiled.")
Exemple #3
0
    def __compile_handlers(self):
        scope = {}
        scope.update(mr.handlers.scope.SCOPE_INJECTED_TYPES)

        handler_count = 0
        for name, arg_names, version in self.__library.list_handlers():
            handler_count += 1

            if name in self.__compiled:
                continue

            _logger.info("Compiling handler: [%s]", name)

            hd = self.__library.get_handler(name)
            (meta, compiled) = self.__compile_handler(hd, arg_names, scope=scope)

            self.__compiled[name] = compiled

        if handler_count == 0:
            _logger.warning("No handlers were presented by the library. No "
                            "code was compiled.")
Exemple #4
0
    def __compile_handler(self, hd, arg_names, scope=None):
        if scope is None:
            scope = {}

        scope.update(mr.handlers.scope.SCOPE_INJECTED_TYPES)
        scope.update(self.__get_scope_objects(hd))

        processor = mr.handlers.utility.get_processor(hd.source_type)

        handler_scope = scope

        if self.__hsf is not None:
            handler_scope.update(self.__hsf.get_scope(hd))

        (meta, compiled) = processor.compile(
                            hd.name, 
                            arg_names, 
                            hd.source_code, 
                            scope=scope)
 
        return (meta, compiled)
Exemple #5
0
    def __compile_handler(self, hd, arg_names, context, scope=None):
        if scope is None:
            scope = {}

        scope.update(mr.handlers.scope.SCOPE_INJECTED_TYPES)
        scope.update(self.__get_scope_objects(hd, context))

        processor = mr.handlers.utility.get_processor(hd.source_type)

        handler_scope = {}
        handler_scope.update(scope)

        stdout_ = cStringIO.StringIO()
        stderr_ = cStringIO.StringIO()

        def custom_print(message):
            """Write the given text into the redirected pipes."""

# TODO(dustin): Until we can figure out how to trap and print errors in the right place.
            print(message)
#            stdout_.write(message)
#            stdout_.write('\n')

        def run_external(cmd, input_data=None, success_code=0, env=None):
            """Feed the *stdout* and *stderr* text into the redirected pipes.
            """

            try:
                handler_scope['HTTP'].debug("RUN: %s", cmd)
            except KeyError:
                pass

            stdin = subprocess.PIPE if input_data is not None else None
            p = subprocess.Popen(
                    cmd, 
                    stdout=subprocess.PIPE, 
                    stderr=subprocess.PIPE, 
                    stdin=stdin,
                    env=env)

            (stdout_text, stderr_text) = p.communicate(input=input_data)

# TODO(dustin): Until we can figure out how to trap and print errors in the right place.
            print(stdout_text)
            print(stderr_text)
#            stdout_.write(stdout_text)
#            stderr_.write(stderr_text)

            if success_code is not None and p.returncode != success_code:
                raise ValueError("Command failed: [%s]" % (cmd,))

            return p.returncode
            
        handler_scope['PRINT'] = custom_print
        handler_scope['RUN'] = run_external

        if self.__hsf is not None:
            handler_scope.update(self.__hsf.get_scope(hd))

        r = processor.compile(
                hd.name, 
                arg_names, 
                hd.source_code, 
                stdout=stdout_, 
                stderr=stderr_, 
                scope=handler_scope)
 
        (meta, compiled) = r

        return (meta, compiled, stdout_, stderr_)
Exemple #6
0
    def __compile_handler(self, hd, arg_names, context, scope=None):
        if scope is None:
            scope = {}

        scope.update(mr.handlers.scope.SCOPE_INJECTED_TYPES)
        scope.update(self.__get_scope_objects(hd, context))

        processor = mr.handlers.utility.get_processor(hd.source_type)

        handler_scope = {}
        handler_scope.update(scope)

        stdout_ = cStringIO.StringIO()
        stderr_ = cStringIO.StringIO()

        def custom_print(message):
            """Write the given text into the redirected pipes."""

            # TODO(dustin): Until we can figure out how to trap and print errors in the right place.
            print(message)


#            stdout_.write(message)
#            stdout_.write('\n')

        def run_external(cmd, input_data=None, success_code=0, env=None):
            """Feed the *stdout* and *stderr* text into the redirected pipes.
            """

            try:
                handler_scope['HTTP'].debug("RUN: %s", cmd)
            except KeyError:
                pass

            stdin = subprocess.PIPE if input_data is not None else None
            p = subprocess.Popen(cmd,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 stdin=stdin,
                                 env=env)

            (stdout_text, stderr_text) = p.communicate(input=input_data)

            # TODO(dustin): Until we can figure out how to trap and print errors in the right place.
            print(stdout_text)
            print(stderr_text)
            #            stdout_.write(stdout_text)
            #            stderr_.write(stderr_text)

            if success_code is not None and p.returncode != success_code:
                raise ValueError("Command failed: [%s]" % (cmd, ))

            return p.returncode

        handler_scope['PRINT'] = custom_print
        handler_scope['RUN'] = run_external

        if self.__hsf is not None:
            handler_scope.update(self.__hsf.get_scope(hd))

        r = processor.compile(hd.name,
                              arg_names,
                              hd.source_code,
                              stdout=stdout_,
                              stderr=stderr_,
                              scope=handler_scope)

        (meta, compiled) = r

        return (meta, compiled, stdout_, stderr_)