Updated the batch processor to use the new global cache system instead of the custom dict-based cache it used before. Much cleaner now.
. Griatch
This commit is contained in:
parent
c2d603c3db
commit
5f6454ea1e
1 changed files with 35 additions and 40 deletions
|
|
@ -57,9 +57,6 @@ from src.statetable import GLOBAL_STATE_TABLE
|
||||||
#global defines for storage
|
#global defines for storage
|
||||||
|
|
||||||
STATENAME="_interactive batch processor"
|
STATENAME="_interactive batch processor"
|
||||||
CMDSTACKS={} # user:cmdstack pairs (for interactive)
|
|
||||||
STACKPTRS={} # user:stackpointer pairs (for interactive)
|
|
||||||
FILENAMES={} # user:filename pairs (for interactive/reload)
|
|
||||||
|
|
||||||
cwhite = r"%cn%ch%cw"
|
cwhite = r"%cn%ch%cw"
|
||||||
cred = r"%cn%ch%cw"
|
cred = r"%cn%ch%cw"
|
||||||
|
|
@ -175,7 +172,7 @@ def cmd_batchprocess(command):
|
||||||
Interactive mode allows the user more control over the
|
Interactive mode allows the user more control over the
|
||||||
processing of the file.
|
processing of the file.
|
||||||
"""
|
"""
|
||||||
global CMDSTACKS,STACKPTRS,FILENAMES
|
#global CMDSTACKS,STACKPTRS,FILENAMES
|
||||||
|
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
|
|
||||||
|
|
@ -214,19 +211,25 @@ def cmd_batchprocess(command):
|
||||||
string += "run Interactive mode. Don't forget to re-set "
|
string += "run Interactive mode. Don't forget to re-set "
|
||||||
string += "it (if you need it) after you're done."
|
string += "it (if you need it) after you're done."
|
||||||
source_object.emit_to(string)
|
source_object.emit_to(string)
|
||||||
|
|
||||||
CMDSTACKS[source_object] = commands
|
# store work data in cache
|
||||||
STACKPTRS[source_object] = 0
|
source_object.cache.batch_cmdstack = commands
|
||||||
FILENAMES[source_object] = filename
|
source_object.cache.batch_stackptr = 0
|
||||||
|
source_object.cache.batch_filename = filename
|
||||||
|
|
||||||
source_object.emit_to("\nBatch processor - Interactive mode for %s ..." % filename)
|
source_object.emit_to("\nBatch processor - Interactive mode for %s ..." % filename)
|
||||||
show_curr(source_object)
|
show_curr(source_object)
|
||||||
else:
|
else:
|
||||||
source_object.set_flag("ADMIN_NOSTATE")
|
set_admin_nostate = False
|
||||||
|
if not source_object.has_flag("ADMIN_NOSTATE"):
|
||||||
|
source_object.set_flag("ADMIN_NOSTATE")
|
||||||
|
set_admin_nostate = True
|
||||||
source_object.emit_to("Running Batch processor - Automatic mode for %s ..." % filename)
|
source_object.emit_to("Running Batch processor - Automatic mode for %s ..." % filename)
|
||||||
source_object.clear_state()
|
source_object.clear_state()
|
||||||
batch_process(source_object, commands)
|
batch_process(source_object, commands)
|
||||||
source_object.emit_to("%s== Batchfile '%s' applied." % (cgreen,filename))
|
source_object.emit_to("%s== Batchfile '%s' applied." % (cgreen,filename))
|
||||||
source_object.unset_flag("ADMIN_NOSTATE")
|
if set_admin_nostate:
|
||||||
|
source_object.unset_flag("ADMIN_NOSTATE")
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("@batchprocess", cmd_batchprocess,
|
GLOBAL_CMD_TABLE.add_command("@batchprocess", cmd_batchprocess,
|
||||||
priv_tuple=("genperms.process_control",), help_category="Building")
|
priv_tuple=("genperms.process_control",), help_category="Building")
|
||||||
|
|
@ -241,14 +244,14 @@ def printfooter():
|
||||||
|
|
||||||
def show_curr(source_object,showall=False):
|
def show_curr(source_object,showall=False):
|
||||||
"Show the current command."
|
"Show the current command."
|
||||||
global CMDSTACKS,STACKPTRS
|
ptr = source_object.cache.batch_stackptr
|
||||||
ptr = STACKPTRS[source_object]
|
commands = source_object.cache.batch_cmdstack
|
||||||
commands = CMDSTACKS[source_object]
|
|
||||||
if ptr >= len(commands):
|
if ptr >= len(commands):
|
||||||
s = "\n You have reached the end of the batch file."
|
s = "\n You have reached the end of the batch file."
|
||||||
s += "\n Use qq to exit or bb to go back."
|
s += "\n Use qq to exit or bb to go back."
|
||||||
source_object.emit_to(s)
|
source_object.emit_to(s)
|
||||||
STACKPTRS[source_object] = len(commands)-1
|
source_object.cache.batch_stackptr = len(commands)-1
|
||||||
show_curr(source_object)
|
show_curr(source_object)
|
||||||
return
|
return
|
||||||
command = commands[ptr]
|
command = commands[ptr]
|
||||||
|
|
@ -266,9 +269,9 @@ def show_curr(source_object,showall=False):
|
||||||
|
|
||||||
def process_commands(source_object, steps=0):
|
def process_commands(source_object, steps=0):
|
||||||
"process one or more commands "
|
"process one or more commands "
|
||||||
global CMDSTACKS,STACKPTRS
|
ptr = source_object.cache.batch_stackptr
|
||||||
ptr = STACKPTRS[source_object]
|
commands = source_object.cache.batch_cmdstack
|
||||||
commands = CMDSTACKS[source_object]
|
|
||||||
if steps:
|
if steps:
|
||||||
try:
|
try:
|
||||||
cmds = commands[ptr:ptr+steps]
|
cmds = commands[ptr:ptr+steps]
|
||||||
|
|
@ -276,7 +279,7 @@ def process_commands(source_object, steps=0):
|
||||||
cmds = commands[ptr:]
|
cmds = commands[ptr:]
|
||||||
for cmd in cmds:
|
for cmd in cmds:
|
||||||
#this so it is kept in case of traceback
|
#this so it is kept in case of traceback
|
||||||
STACKPTRS[source_object] = ptr + 1
|
source_object.cache.batch_stackptr = ptr + 1
|
||||||
#show_curr(source_object)
|
#show_curr(source_object)
|
||||||
source_object.execute_cmd(cmd)
|
source_object.execute_cmd(cmd)
|
||||||
else:
|
else:
|
||||||
|
|
@ -285,29 +288,24 @@ def process_commands(source_object, steps=0):
|
||||||
|
|
||||||
def reload_stack(source_object):
|
def reload_stack(source_object):
|
||||||
"reload the stack"
|
"reload the stack"
|
||||||
global CMDSTACKS,FILENAMES
|
commands = parse_batchbuild_file(source_object.cache.batch_filename)
|
||||||
commands = parse_batchbuild_file(FILENAMES[source_object])
|
|
||||||
if commands:
|
if commands:
|
||||||
CMDSTACKS[source_object] = commands
|
ptr = source_object.cache.batch_stackptr
|
||||||
else:
|
else:
|
||||||
source_object.emit_to("Commands in file could not be reloaded. Was it moved?")
|
source_object.emit_to("Commands in file could not be reloaded. Was it moved?")
|
||||||
|
|
||||||
def move_in_stack(source_object, step=1):
|
def move_in_stack(source_object, step=1):
|
||||||
"store data in stack"
|
"store data in stack"
|
||||||
global CMDSTACKS, STACKPTRS
|
N = len(source_object.cache.batch_cmdstack)
|
||||||
N = len(CMDSTACKS[source_object])
|
currpos = source_object.cache.batch_stackptr
|
||||||
currpos = STACKPTRS[source_object]
|
source_object.cache.batch_stackptr = max(0,min(N-1,currpos+step))
|
||||||
STACKPTRS[source_object] = max(0,min(N-1,currpos+step))
|
|
||||||
|
|
||||||
def exit_state(source_object):
|
def exit_state(source_object):
|
||||||
"Quit the state"
|
"Quit the state"
|
||||||
global CMDSTACKS,STACKPTRS,FILENAMES
|
source_object.cache.batch_cmdstack = None
|
||||||
try:
|
source_object.cache.batch_stackptr = None
|
||||||
del CMDSTACKS[source_object]
|
source_object.cache.batch_filename = None
|
||||||
del STACKPTRS[source_object]
|
|
||||||
del FILENAMES[source_object]
|
|
||||||
except KeyError:
|
|
||||||
logger.log_errmsg("Batchprocessor quit error: all state vars could not be deleted.")
|
|
||||||
# since clear_state() is protected against exiting the interactive mode
|
# since clear_state() is protected against exiting the interactive mode
|
||||||
# (to avoid accidental drop-outs by rooms clearing a player's state),
|
# (to avoid accidental drop-outs by rooms clearing a player's state),
|
||||||
# we have to clear the state directly here.
|
# we have to clear the state directly here.
|
||||||
|
|
@ -349,9 +347,8 @@ def cmd_state_rrr(command):
|
||||||
Reload the batch file, starting over
|
Reload the batch file, starting over
|
||||||
from the beginning.
|
from the beginning.
|
||||||
"""
|
"""
|
||||||
global STACKPTRS
|
|
||||||
reload_stack(command.source_object)
|
reload_stack(command.source_object)
|
||||||
STACKPTRS[command.source_object] = 0
|
command.source_object.cache.batch_stackptr = 0
|
||||||
command.source_object.emit_to("\nFile reloaded. Restarting from top.\n")
|
command.source_object.emit_to("\nFile reloaded. Restarting from top.\n")
|
||||||
show_curr(command.source_object)
|
show_curr(command.source_object)
|
||||||
|
|
||||||
|
|
@ -459,10 +456,9 @@ def cmd_state_cc(command):
|
||||||
Continue to process all remaining
|
Continue to process all remaining
|
||||||
commands.
|
commands.
|
||||||
"""
|
"""
|
||||||
global CMDSTACKS,STACKPTRS
|
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
N = len(CMDSTACKS[source_object])
|
N = len(source_object.cache.batch_cmdstack)
|
||||||
ptr = STACKPTRS[source_object]
|
ptr = source_object.cache.batch_stackptr
|
||||||
step = N - ptr
|
step = N - ptr
|
||||||
process_commands(source_object,step)
|
process_commands(source_object,step)
|
||||||
exit_state(source_object)
|
exit_state(source_object)
|
||||||
|
|
@ -474,7 +470,6 @@ def cmd_state_jj(command):
|
||||||
|
|
||||||
Jump to specific command number
|
Jump to specific command number
|
||||||
"""
|
"""
|
||||||
global STACKPTRS
|
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
arg = command.command_argument
|
arg = command.command_argument
|
||||||
if arg and arg.isdigit():
|
if arg and arg.isdigit():
|
||||||
|
|
@ -482,7 +477,7 @@ def cmd_state_jj(command):
|
||||||
else:
|
else:
|
||||||
source_object.emit_to("You must give a number index.")
|
source_object.emit_to("You must give a number index.")
|
||||||
return
|
return
|
||||||
ptr = STACKPTRS[source_object]
|
ptr = source_object.cache.batch_stackptr
|
||||||
step = no - ptr
|
step = no - ptr
|
||||||
move_in_stack(source_object, step)
|
move_in_stack(source_object, step)
|
||||||
show_curr(source_object)
|
show_curr(source_object)
|
||||||
|
|
@ -501,7 +496,7 @@ def cmd_state_jl(command):
|
||||||
else:
|
else:
|
||||||
source_object.emit_to("You must give a number index.")
|
source_object.emit_to("You must give a number index.")
|
||||||
return
|
return
|
||||||
ptr = STACKPTRS[source_object]
|
ptr = source_object.cache.batch_stackptr
|
||||||
step = no - ptr
|
step = no - ptr
|
||||||
move_in_stack(source_object, step)
|
move_in_stack(source_object, step)
|
||||||
show_curr(source_object, showall=True)
|
show_curr(source_object, showall=True)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue