Markup and PEP 8 updates
This commit is contained in:
parent
ce15140bdd
commit
1937c314bb
1 changed files with 38 additions and 38 deletions
|
|
@ -29,15 +29,13 @@ from evennia.utils import logger, utils
|
||||||
_RE_COMMENT = re.compile(r"^#.*?$", re.MULTILINE + re.DOTALL)
|
_RE_COMMENT = re.compile(r"^#.*?$", re.MULTILINE + re.DOTALL)
|
||||||
_RE_CODE_START = re.compile(r"^# batchcode code:", re.MULTILINE)
|
_RE_CODE_START = re.compile(r"^# batchcode code:", re.MULTILINE)
|
||||||
_COMMAND_DEFAULT_CLASS = utils.class_from_module(settings.COMMAND_DEFAULT_CLASS)
|
_COMMAND_DEFAULT_CLASS = utils.class_from_module(settings.COMMAND_DEFAULT_CLASS)
|
||||||
#from evennia.commands.default.muxcommand import _COMMAND_DEFAULT_CLASS
|
|
||||||
|
|
||||||
# limit symbols for API inclusion
|
# limit symbols for API inclusion
|
||||||
__all__ = ("CmdBatchCommands", "CmdBatchCode")
|
__all__ = ("CmdBatchCommands", "CmdBatchCode")
|
||||||
|
|
||||||
_HEADER_WIDTH = 70
|
_HEADER_WIDTH = 70
|
||||||
_UTF8_ERROR = \
|
_UTF8_ERROR = """
|
||||||
"""
|
|rDecode error in '%s'.|n
|
||||||
{rDecode error in '%s'.{n
|
|
||||||
|
|
||||||
This file contains non-ascii character(s). This is common if you
|
This file contains non-ascii character(s). This is common if you
|
||||||
wrote some input in a language that has more letters and special
|
wrote some input in a language that has more letters and special
|
||||||
|
|
@ -83,9 +81,9 @@ print "leaving run ..."
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------
|
# -------------------------------------------------------------
|
||||||
# Helper functions
|
# Helper functions
|
||||||
#------------------------------------------------------------
|
# -------------------------------------------------------------
|
||||||
|
|
||||||
def format_header(caller, entry):
|
def format_header(caller, entry):
|
||||||
"""
|
"""
|
||||||
|
|
@ -100,7 +98,7 @@ def format_header(caller, entry):
|
||||||
header = utils.crop(entry, width=width)
|
header = utils.crop(entry, width=width)
|
||||||
ptr = caller.ndb.batch_stackptr + 1
|
ptr = caller.ndb.batch_stackptr + 1
|
||||||
stacklen = len(caller.ndb.batch_stack)
|
stacklen = len(caller.ndb.batch_stack)
|
||||||
header = "{w%02i/%02i{G: %s{n" % (ptr, stacklen, header)
|
header = "|w%02i/%02i|G: %s|n" % (ptr, stacklen, header)
|
||||||
# add extra space to the side for padding.
|
# add extra space to the side for padding.
|
||||||
header = "%s%s" % (header, " " * (width - len(header)))
|
header = "%s%s" % (header, " " * (width - len(header)))
|
||||||
header = header.replace('\n', '\\n')
|
header = header.replace('\n', '\\n')
|
||||||
|
|
@ -114,7 +112,7 @@ def format_code(entry):
|
||||||
"""
|
"""
|
||||||
code = ""
|
code = ""
|
||||||
for line in entry.split('\n'):
|
for line in entry.split('\n'):
|
||||||
code += "\n{G>>>{n %s" % line
|
code += "\n|G>>>|n %s" % line
|
||||||
return code.strip()
|
return code.strip()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -164,9 +162,9 @@ def step_pointer(caller, step=1):
|
||||||
stack = caller.ndb.batch_stack
|
stack = caller.ndb.batch_stack
|
||||||
nstack = len(stack)
|
nstack = len(stack)
|
||||||
if ptr + step <= 0:
|
if ptr + step <= 0:
|
||||||
caller.msg("{RBeginning of batch file.")
|
caller.msg("|RBeginning of batch file.")
|
||||||
if ptr + step >= nstack:
|
if ptr + step >= nstack:
|
||||||
caller.msg("{REnd of batch file.")
|
caller.msg("|REnd of batch file.")
|
||||||
caller.ndb.batch_stackptr = max(0, min(nstack - 1, ptr + step))
|
caller.ndb.batch_stackptr = max(0, min(nstack - 1, ptr + step))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -186,10 +184,10 @@ def show_curr(caller, showall=False):
|
||||||
|
|
||||||
string = format_header(caller, entry)
|
string = format_header(caller, entry)
|
||||||
codeall = entry.strip()
|
codeall = entry.strip()
|
||||||
string += "{G(hh for help)"
|
string += "|G(hh for help)"
|
||||||
if showall:
|
if showall:
|
||||||
for line in codeall.split('\n'):
|
for line in codeall.split('\n'):
|
||||||
string += "\n{G|{n %s" % line
|
string += "\n|G||n %s" % line
|
||||||
caller.msg(string)
|
caller.msg(string)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -217,9 +215,9 @@ def purge_processor(caller):
|
||||||
|
|
||||||
caller.scripts.validate() # this will purge interactive mode
|
caller.scripts.validate() # this will purge interactive mode
|
||||||
|
|
||||||
#------------------------------------------------------------
|
# -------------------------------------------------------------
|
||||||
# main access commands
|
# main access commands
|
||||||
#------------------------------------------------------------
|
# -------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class CmdBatchCommands(_COMMAND_DEFAULT_CLASS):
|
class CmdBatchCommands(_COMMAND_DEFAULT_CLASS):
|
||||||
|
|
@ -243,7 +241,7 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS):
|
||||||
help_category = "Building"
|
help_category = "Building"
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
"Starts the processor."
|
"""Starts the processor."""
|
||||||
|
|
||||||
caller = self.caller
|
caller = self.caller
|
||||||
|
|
||||||
|
|
@ -289,7 +287,8 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS):
|
||||||
caller.msg("\nBatch-command processor - Interactive mode for %s ..." % python_path)
|
caller.msg("\nBatch-command processor - Interactive mode for %s ..." % python_path)
|
||||||
show_curr(caller)
|
show_curr(caller)
|
||||||
else:
|
else:
|
||||||
caller.msg("Running Batch-command processor - Automatic mode for %s (this might take some time) ..." % python_path)
|
caller.msg("Running Batch-command processor - Automatic mode for %s (this might take some time) ..."
|
||||||
|
% python_path)
|
||||||
|
|
||||||
procpool = False
|
procpool = False
|
||||||
if "PythonProcPool" in utils.server_services():
|
if "PythonProcPool" in utils.server_services():
|
||||||
|
|
@ -301,11 +300,11 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS):
|
||||||
if procpool:
|
if procpool:
|
||||||
# run in parallel process
|
# run in parallel process
|
||||||
def callback(r):
|
def callback(r):
|
||||||
caller.msg(" {GBatchfile '%s' applied." % python_path)
|
caller.msg(" |GBatchfile '%s' applied." % python_path)
|
||||||
purge_processor(caller)
|
purge_processor(caller)
|
||||||
|
|
||||||
def errback(e):
|
def errback(e):
|
||||||
caller.msg(" {RError from processor: '%s'" % e)
|
caller.msg(" |RError from processor: '%s'" % e)
|
||||||
purge_processor(caller)
|
purge_processor(caller)
|
||||||
|
|
||||||
utils.run_async(_PROCPOOL_BATCHCMD_SOURCE,
|
utils.run_async(_PROCPOOL_BATCHCMD_SOURCE,
|
||||||
|
|
@ -315,7 +314,7 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS):
|
||||||
at_err=errback)
|
at_err=errback)
|
||||||
else:
|
else:
|
||||||
# run in-process (might block)
|
# run in-process (might block)
|
||||||
for inum in range(len(commands)):
|
for _ in range(len(commands)):
|
||||||
# loop through the batch file
|
# loop through the batch file
|
||||||
if not batch_cmd_exec(caller):
|
if not batch_cmd_exec(caller):
|
||||||
return
|
return
|
||||||
|
|
@ -323,7 +322,7 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS):
|
||||||
# clean out the safety cmdset and clean out all other
|
# clean out the safety cmdset and clean out all other
|
||||||
# temporary attrs.
|
# temporary attrs.
|
||||||
string = " Batchfile '%s' applied." % python_path
|
string = " Batchfile '%s' applied." % python_path
|
||||||
caller.msg("{G%s" % string)
|
caller.msg("|G%s" % string)
|
||||||
purge_processor(caller)
|
purge_processor(caller)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -352,7 +351,7 @@ class CmdBatchCode(_COMMAND_DEFAULT_CLASS):
|
||||||
help_category = "Building"
|
help_category = "Building"
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
"Starts the processor."
|
"""Starts the processor."""
|
||||||
|
|
||||||
caller = self.caller
|
caller = self.caller
|
||||||
|
|
||||||
|
|
@ -410,11 +409,11 @@ class CmdBatchCode(_COMMAND_DEFAULT_CLASS):
|
||||||
if procpool:
|
if procpool:
|
||||||
# run in parallel process
|
# run in parallel process
|
||||||
def callback(r):
|
def callback(r):
|
||||||
caller.msg(" {GBatchfile '%s' applied." % python_path)
|
caller.msg(" |GBatchfile '%s' applied." % python_path)
|
||||||
purge_processor(caller)
|
purge_processor(caller)
|
||||||
|
|
||||||
def errback(e):
|
def errback(e):
|
||||||
caller.msg(" {RError from processor: '%s'" % e)
|
caller.msg(" |RError from processor: '%s'" % e)
|
||||||
purge_processor(caller)
|
purge_processor(caller)
|
||||||
utils.run_async(_PROCPOOL_BATCHCODE_SOURCE,
|
utils.run_async(_PROCPOOL_BATCHCODE_SOURCE,
|
||||||
codes=codes,
|
codes=codes,
|
||||||
|
|
@ -423,7 +422,7 @@ class CmdBatchCode(_COMMAND_DEFAULT_CLASS):
|
||||||
at_err=errback)
|
at_err=errback)
|
||||||
else:
|
else:
|
||||||
# un in-process (will block)
|
# un in-process (will block)
|
||||||
for inum in range(len(codes)):
|
for _ in range(len(codes)):
|
||||||
# loop through the batch file
|
# loop through the batch file
|
||||||
if not batch_code_exec(caller):
|
if not batch_code_exec(caller):
|
||||||
return
|
return
|
||||||
|
|
@ -431,14 +430,14 @@ class CmdBatchCode(_COMMAND_DEFAULT_CLASS):
|
||||||
# clean out the safety cmdset and clean out all other
|
# clean out the safety cmdset and clean out all other
|
||||||
# temporary attrs.
|
# temporary attrs.
|
||||||
string = " Batchfile '%s' applied." % python_path
|
string = " Batchfile '%s' applied." % python_path
|
||||||
caller.msg("{G%s" % string)
|
caller.msg("|G%s" % string)
|
||||||
purge_processor(caller)
|
purge_processor(caller)
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------
|
# -------------------------------------------------------------
|
||||||
# State-commands for the interactive batch processor modes
|
# State-commands for the interactive batch processor modes
|
||||||
# (these are the same for both processors)
|
# (these are the same for both processors)
|
||||||
#------------------------------------------------------------
|
# -------------------------------------------------------------
|
||||||
|
|
||||||
class CmdStateAbort(_COMMAND_DEFAULT_CLASS):
|
class CmdStateAbort(_COMMAND_DEFAULT_CLASS):
|
||||||
"""
|
"""
|
||||||
|
|
@ -453,7 +452,7 @@ class CmdStateAbort(_COMMAND_DEFAULT_CLASS):
|
||||||
locks = "cmd:perm(batchcommands)"
|
locks = "cmd:perm(batchcommands)"
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
"Exit back to default."
|
"""Exit back to default."""
|
||||||
purge_processor(self.caller)
|
purge_processor(self.caller)
|
||||||
self.caller.msg("Exited processor and reset out active cmdset back to the default one.")
|
self.caller.msg("Exited processor and reset out active cmdset back to the default one.")
|
||||||
|
|
||||||
|
|
@ -472,6 +471,7 @@ class CmdStateLL(_COMMAND_DEFAULT_CLASS):
|
||||||
def func(self):
|
def func(self):
|
||||||
show_curr(self.caller, showall=True)
|
show_curr(self.caller, showall=True)
|
||||||
|
|
||||||
|
|
||||||
class CmdStatePP(_COMMAND_DEFAULT_CLASS):
|
class CmdStatePP(_COMMAND_DEFAULT_CLASS):
|
||||||
"""
|
"""
|
||||||
pp
|
pp
|
||||||
|
|
@ -644,7 +644,7 @@ class CmdStateSS(_COMMAND_DEFAULT_CLASS):
|
||||||
else:
|
else:
|
||||||
step = 1
|
step = 1
|
||||||
|
|
||||||
for istep in range(step):
|
for _ in range(step):
|
||||||
if caller.ndb.batch_batchmode == "batch_code":
|
if caller.ndb.batch_batchmode == "batch_code":
|
||||||
batch_code_exec(caller)
|
batch_code_exec(caller)
|
||||||
else:
|
else:
|
||||||
|
|
@ -673,7 +673,7 @@ class CmdStateSL(_COMMAND_DEFAULT_CLASS):
|
||||||
else:
|
else:
|
||||||
step = 1
|
step = 1
|
||||||
|
|
||||||
for istep in range(step):
|
for _ in range(step):
|
||||||
if caller.ndb.batch_batchmode == "batch_code":
|
if caller.ndb.batch_batchmode == "batch_code":
|
||||||
batch_code_exec(caller)
|
batch_code_exec(caller)
|
||||||
else:
|
else:
|
||||||
|
|
@ -699,7 +699,7 @@ class CmdStateCC(_COMMAND_DEFAULT_CLASS):
|
||||||
ptr = caller.ndb.batch_stackptr
|
ptr = caller.ndb.batch_stackptr
|
||||||
step = nstack - ptr
|
step = nstack - ptr
|
||||||
|
|
||||||
for istep in range(step):
|
for _ in range(step):
|
||||||
if caller.ndb.batch_batchmode == "batch_code":
|
if caller.ndb.batch_batchmode == "batch_code":
|
||||||
batch_code_exec(caller)
|
batch_code_exec(caller)
|
||||||
else:
|
else:
|
||||||
|
|
@ -775,7 +775,7 @@ class CmdStateQQ(_COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
|
|
||||||
class CmdStateHH(_COMMAND_DEFAULT_CLASS):
|
class CmdStateHH(_COMMAND_DEFAULT_CLASS):
|
||||||
"Help command"
|
"""Help command"""
|
||||||
|
|
||||||
key = "hh"
|
key = "hh"
|
||||||
help_category = "BatchProcess"
|
help_category = "BatchProcess"
|
||||||
|
|
@ -810,12 +810,12 @@ class CmdStateHH(_COMMAND_DEFAULT_CLASS):
|
||||||
self.caller.msg(string)
|
self.caller.msg(string)
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------
|
# -------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Defining the cmdsets for the interactive batchprocessor
|
# Defining the cmdsets for the interactive batchprocessor
|
||||||
# mode (same for both processors)
|
# mode (same for both processors)
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------
|
# -------------------------------------------------------------
|
||||||
|
|
||||||
class BatchSafeCmdSet(CmdSet):
|
class BatchSafeCmdSet(CmdSet):
|
||||||
"""
|
"""
|
||||||
|
|
@ -827,7 +827,7 @@ class BatchSafeCmdSet(CmdSet):
|
||||||
priority = 150 # override other cmdsets.
|
priority = 150 # override other cmdsets.
|
||||||
|
|
||||||
def at_cmdset_creation(self):
|
def at_cmdset_creation(self):
|
||||||
"Init the cmdset"
|
"""Init the cmdset"""
|
||||||
self.add(CmdStateAbort())
|
self.add(CmdStateAbort())
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -839,7 +839,7 @@ class BatchInteractiveCmdSet(CmdSet):
|
||||||
priority = 104
|
priority = 104
|
||||||
|
|
||||||
def at_cmdset_creation(self):
|
def at_cmdset_creation(self):
|
||||||
"init the cmdset"
|
"""init the cmdset"""
|
||||||
self.add(CmdStateAbort())
|
self.add(CmdStateAbort())
|
||||||
self.add(CmdStateLL())
|
self.add(CmdStateLL())
|
||||||
self.add(CmdStatePP())
|
self.add(CmdStatePP())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue