Example #1
0
 def func(self):
     caller = self.caller
     if caller.ndb.batch_batchmode == "batch_code":
         BATCHCODE.parse_file(caller.ndb.batch_pythonpath)
     else:
         BATCHCMD.parse_file(caller.ndb.batch_pythonpath)
     caller.ndb.batch_stackptr = 0
     caller.msg(format_code("File reloaded. Restarting from top."))
     show_curr(caller)
Example #2
0
 def func(self):
     caller = self.caller
     if caller.ndb.batch_batchmode == "batch_code":
         BATCHCODE.parse_file(caller.ndb.batch_pythonpath)
     else:
         BATCHCMD.parse_file(caller.ndb.batch_pythonpath)
     caller.ndb.batch_stackptr = 0
     caller.msg(format_code("File reloaded. Restarting from top."))
     show_curr(caller)
Example #3
0
 def func(self):
     caller = self.caller
     if caller.ndb.batch_batchmode == "batch_code":
         new_data = BATCHCODE.parse_file(caller.ndb.batch_pythonpath)
     else:
         new_data = BATCHCMD.parse_file(caller.ndb.batch_pythonpath)
     caller.ndb.batch_stack = new_data
     caller.msg(format_code("File reloaded. Staying on same command."))
     show_curr(caller)
Example #4
0
 def func(self):
     caller = self.caller
     if caller.ndb.batch_batchmode == "batch_code":
         new_data = BATCHCODE.parse_file(caller.ndb.batch_pythonpath)
     else:
         new_data = BATCHCMD.parse_file(caller.ndb.batch_pythonpath)
     caller.ndb.batch_stack = new_data
     caller.msg(format_code("File reloaded. Staying on same command."))
     show_curr(caller)
Example #5
0
def batch_code_exec(caller):
    """
    Helper function for executing a single batch-code entry
    """
    ptr = caller.ndb.batch_stackptr
    stack = caller.ndb.batch_stack
    debug = caller.ndb.batch_debug
    code = stack[ptr]

    caller.msg(format_header(caller, code))
    err = BATCHCODE.code_exec(code, extra_environ={"caller": caller}, debug=debug)
    if err:
        caller.msg(format_code(err))
        return False
    return True
Example #6
0
def batch_code_exec(caller):
    """
    Helper function for executing a single batch-code entry
    """
    ptr = caller.ndb.batch_stackptr
    stack = caller.ndb.batch_stack
    debug = caller.ndb.batch_debug
    code = stack[ptr]

    caller.msg(format_header(caller, code))
    err = BATCHCODE.code_exec(code,
                              extra_environ={"caller": caller}, debug=debug)
    if err:
        caller.msg(format_code(err))
        return False
    return True
Example #7
0
    def func(self):
        "Starts the processor."

        caller = self.caller

        args = self.args
        if not args:
            caller.msg("Usage: @batchcode[/interactive/debug] <path.to.file>")
            return
        python_path = self.args
        debug = 'debug' in self.switches

        #parse indata file
        try:
            codes = BATCHCODE.parse_file(python_path, debug=debug)
        except UnicodeDecodeError, err:
            caller.msg(_UTF8_ERROR % (python_path, err))
            return
Example #8
0
    def func(self):
        "Starts the processor."

        caller = self.caller

        args = self.args
        if not args:
            caller.msg("Usage: @batchcode[/interactive/debug] <path.to.file>")
            return
        python_path = self.args
        debug = 'debug' in self.switches

        #parse indata file
        try:
            codes = BATCHCODE.parse_file(python_path, debug=debug)
        except UnicodeDecodeError, err:
            caller.msg(_UTF8_ERROR % (python_path, err))
            return
Example #9
0
    def func(self):
        "Starts the processor."

        caller = self.caller

        args = self.args
        if not args:
            caller.msg("Usage: @batchcode[/interactive/debug] <path.to.file>")
            return
        python_path = self.args
        debug = 'debug' in self.switches

        #parse indata file
        try:
            codes = BATCHCODE.parse_file(python_path)
        except UnicodeDecodeError as err:
            caller.msg(_UTF8_ERROR % (python_path, err))
            return
        except IOError:
            string = "'%s' not found.\nYou have to supply the python path\n" \
                     "from one of the defined batch-file directories\n (%s)."
            caller.msg(string % (python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS)))
            return
        if not codes:
            caller.msg("File %s seems empty of functional code." % python_path)
            return

        switches = self.switches

        # Store work data in cache
        caller.ndb.batch_stack = codes
        caller.ndb.batch_stackptr = 0
        caller.ndb.batch_pythonpath = python_path
        caller.ndb.batch_batchmode = "batch_code"
        caller.ndb.batch_debug = debug
        caller.cmdset.add(BatchSafeCmdSet)

        if 'inter' in switches or 'interactive'in switches:
            # Allow more control over how batch file is executed

            # Set interactive state directly
            caller.cmdset.add(BatchInteractiveCmdSet)

            caller.msg("\nBatch-code processor - Interactive mode for %s ..." % python_path)
            show_curr(caller)
        else:
            caller.msg("Running Batch-code processor - Automatic mode for %s ..." % python_path)

            procpool = False
            if "PythonProcPool" in utils.server_services():
                if utils.uses_database("sqlite3"):
                    caller.msg("Batchprocessor disabled ProcPool under SQLite3.")
                else:
                    procpool = True
            if procpool:
                # run in parallel process
                def callback(r):
                    caller.msg("  {GBatchfile '%s' applied." % python_path)
                    purge_processor(caller)

                def errback(e):
                    caller.msg("  {RError from processor: '%s'" % e)
                    purge_processor(caller)
                utils.run_async(_PROCPOOL_BATCHCODE_SOURCE,
                                codes=codes,
                                caller=caller,
                                at_return=callback,
                                at_err=errback)
            else:
                # un in-process (will block)
                for inum in range(len(codes)):
                    # loop through the batch file
                    if not batch_code_exec(caller):
                        return
                    step_pointer(caller, 1)
                # clean out the safety cmdset and clean out all other
                # temporary attrs.
                string = "  Batchfile '%s' applied." % python_path
                caller.msg("{G%s" % string)
                purge_processor(caller)
Example #10
0
    def func(self):
        """Starts the processor."""

        caller = self.caller

        args = self.args
        if not args:
            caller.msg("Usage: @batchcode[/interactive/debug] <path.to.file>")
            return
        python_path = self.args
        debug = 'debug' in self.switches

        # parse indata file
        try:
            codes = BATCHCODE.parse_file(python_path)
        except UnicodeDecodeError as err:
            caller.msg(_UTF8_ERROR % (python_path, err))
            return
        except IOError:
            string = "'%s' not found.\nYou have to supply the python path\n" \
                     "from one of the defined batch-file directories\n (%s)."
            caller.msg(
                string %
                (python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS)))
            return
        if not codes:
            caller.msg("File %s seems empty of functional code." % python_path)
            return

        switches = self.switches

        # Store work data in cache
        caller.ndb.batch_stack = codes
        caller.ndb.batch_stackptr = 0
        caller.ndb.batch_pythonpath = python_path
        caller.ndb.batch_batchmode = "batch_code"
        caller.ndb.batch_debug = debug
        # we use list() here to create a new copy of cmdset_stack
        caller.ndb.batch_cmdset_backup = list(caller.cmdset.cmdset_stack)
        caller.cmdset.add(BatchSafeCmdSet)

        if 'inter' in switches or 'interactive' in switches:
            # Allow more control over how batch file is executed

            # Set interactive state directly
            caller.cmdset.add(BatchInteractiveCmdSet)

            caller.msg("\nBatch-code processor - Interactive mode for %s ..." %
                       python_path)
            show_curr(caller)
        else:
            caller.msg(
                "Running Batch-code processor - Automatic mode for %s ..." %
                python_path)

            procpool = False
            if "PythonProcPool" in utils.server_services():
                if utils.uses_database("sqlite3"):
                    caller.msg(
                        "Batchprocessor disabled ProcPool under SQLite3.")
                else:
                    procpool = True
            if procpool:
                # run in parallel process
                def callback(r):
                    caller.msg("  |GBatchfile '%s' applied." % python_path)
                    purge_processor(caller)

                def errback(e):
                    caller.msg("  |RError from processor: '%s'" % e)
                    purge_processor(caller)

                utils.run_async(_PROCPOOL_BATCHCODE_SOURCE,
                                codes=codes,
                                caller=caller,
                                at_return=callback,
                                at_err=errback)
            else:
                # un in-process (will block)
                for _ in range(len(codes)):
                    # loop through the batch file
                    if not batch_code_exec(caller):
                        return
                    step_pointer(caller, 1)
                # clean out the safety cmdset and clean out all other
                # temporary attrs.
                string = "  Batchfile '%s' applied." % python_path
                caller.msg("|G%s" % string)
                purge_processor(caller)
Example #11
0
    def func(self):
        """Starts the processor."""

        caller = self.caller

        args = self.args
        if not args:
            caller.msg("Usage: batchcode[/interactive/debug] <path.to.file>")
            return
        python_path = self.args
        debug = "debug" in self.switches

        # parse indata file
        try:
            codes = BATCHCODE.parse_file(python_path)
        except UnicodeDecodeError as err:
            caller.msg(_UTF8_ERROR % (python_path, err))
            return
        except IOError as err:
            if err:
                err = "{}\n".format(str(err))
            else:
                err = ""
            string = ("%s'%s' could not load. You have to supply python paths "
                      "from one of the defined batch-file directories\n (%s).")
            caller.msg(string % (err, python_path, ", ".join(
                settings.BASE_BATCHPROCESS_PATHS)))
            return
        if not codes:
            caller.msg("File %s seems empty of functional code." % python_path)
            return

        switches = self.switches

        # Store work data in cache
        caller.ndb.batch_stack = codes
        caller.ndb.batch_stackptr = 0
        caller.ndb.batch_pythonpath = python_path
        caller.ndb.batch_batchmode = "batch_code"
        caller.ndb.batch_debug = debug
        # we use list() here to create a new copy of cmdset_stack
        caller.ndb.batch_cmdset_backup = list(caller.cmdset.cmdset_stack)
        caller.cmdset.add(BatchSafeCmdSet)

        if "inter" in switches or "interactive" in switches:
            # Allow more control over how batch file is executed

            # Set interactive state directly
            caller.cmdset.add(BatchInteractiveCmdSet)

            caller.msg("\nBatch-code processor - Interactive mode for %s ..." %
                       python_path)
            show_curr(caller)
        else:
            caller.msg(
                "Running Batch-code processor - Automatic mode for %s ..." %
                python_path)

            for _ in range(len(codes)):
                # loop through the batch file
                if not batch_code_exec(caller):
                    return
                step_pointer(caller, 1)
            # clean out the safety cmdset and clean out all other
            # temporary attrs.
            string = "  Batchfile '%s' applied." % python_path
            caller.msg("|G%s" % string)
            purge_processor(caller)