From 1937c314bbcf7c771c562f843694545868503c23 Mon Sep 17 00:00:00 2001 From: BlauFeuer Date: Tue, 21 Feb 2017 10:34:15 -0500 Subject: [PATCH] Markup and PEP 8 updates --- evennia/commands/default/batchprocess.py | 76 ++++++++++++------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/evennia/commands/default/batchprocess.py b/evennia/commands/default/batchprocess.py index cefeba6ba..6fbcfc2ec 100644 --- a/evennia/commands/default/batchprocess.py +++ b/evennia/commands/default/batchprocess.py @@ -29,15 +29,13 @@ from evennia.utils import logger, utils _RE_COMMENT = re.compile(r"^#.*?$", re.MULTILINE + re.DOTALL) _RE_CODE_START = re.compile(r"^# batchcode code:", re.MULTILINE) _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 __all__ = ("CmdBatchCommands", "CmdBatchCode") _HEADER_WIDTH = 70 -_UTF8_ERROR = \ -""" - {rDecode error in '%s'.{n +_UTF8_ERROR = """ + |rDecode error in '%s'.|n This file contains non-ascii character(s). This is common if you wrote some input in a language that has more letters and special @@ -83,9 +81,9 @@ print "leaving run ..." """ -#------------------------------------------------------------ +# ------------------------------------------------------------- # Helper functions -#------------------------------------------------------------ +# ------------------------------------------------------------- def format_header(caller, entry): """ @@ -100,7 +98,7 @@ def format_header(caller, entry): header = utils.crop(entry, width=width) ptr = caller.ndb.batch_stackptr + 1 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. header = "%s%s" % (header, " " * (width - len(header))) header = header.replace('\n', '\\n') @@ -114,7 +112,7 @@ def format_code(entry): """ code = "" for line in entry.split('\n'): - code += "\n{G>>>{n %s" % line + code += "\n|G>>>|n %s" % line return code.strip() @@ -164,9 +162,9 @@ def step_pointer(caller, step=1): stack = caller.ndb.batch_stack nstack = len(stack) if ptr + step <= 0: - caller.msg("{RBeginning of batch file.") + caller.msg("|RBeginning of batch file.") 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)) @@ -186,10 +184,10 @@ def show_curr(caller, showall=False): string = format_header(caller, entry) codeall = entry.strip() - string += "{G(hh for help)" + string += "|G(hh for help)" if showall: for line in codeall.split('\n'): - string += "\n{G|{n %s" % line + string += "\n|G||n %s" % line caller.msg(string) @@ -217,9 +215,9 @@ def purge_processor(caller): caller.scripts.validate() # this will purge interactive mode -#------------------------------------------------------------ +# ------------------------------------------------------------- # main access commands -#------------------------------------------------------------ +# ------------------------------------------------------------- class CmdBatchCommands(_COMMAND_DEFAULT_CLASS): @@ -243,7 +241,7 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS): help_category = "Building" def func(self): - "Starts the processor." + """Starts the processor.""" caller = self.caller @@ -253,7 +251,7 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS): return python_path = self.args - #parse indata file + # parse indata file try: commands = BATCHCMD.parse_file(python_path) @@ -289,7 +287,8 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS): caller.msg("\nBatch-command processor - Interactive mode for %s ..." % python_path) show_curr(caller) 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 if "PythonProcPool" in utils.server_services(): @@ -301,11 +300,11 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS): if procpool: # run in parallel process def callback(r): - caller.msg(" {GBatchfile '%s' applied." % python_path) + caller.msg(" |GBatchfile '%s' applied." % python_path) purge_processor(caller) def errback(e): - caller.msg(" {RError from processor: '%s'" % e) + caller.msg(" |RError from processor: '%s'" % e) purge_processor(caller) utils.run_async(_PROCPOOL_BATCHCMD_SOURCE, @@ -315,7 +314,7 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS): at_err=errback) else: # run in-process (might block) - for inum in range(len(commands)): + for _ in range(len(commands)): # loop through the batch file if not batch_cmd_exec(caller): return @@ -323,7 +322,7 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS): # clean out the safety cmdset and clean out all other # temporary attrs. string = " Batchfile '%s' applied." % python_path - caller.msg("{G%s" % string) + caller.msg("|G%s" % string) purge_processor(caller) @@ -352,7 +351,7 @@ class CmdBatchCode(_COMMAND_DEFAULT_CLASS): help_category = "Building" def func(self): - "Starts the processor." + """Starts the processor.""" caller = self.caller @@ -363,7 +362,7 @@ class CmdBatchCode(_COMMAND_DEFAULT_CLASS): python_path = self.args debug = 'debug' in self.switches - #parse indata file + # parse indata file try: codes = BATCHCODE.parse_file(python_path) except UnicodeDecodeError as err: @@ -410,11 +409,11 @@ class CmdBatchCode(_COMMAND_DEFAULT_CLASS): if procpool: # run in parallel process def callback(r): - caller.msg(" {GBatchfile '%s' applied." % python_path) + caller.msg(" |GBatchfile '%s' applied." % python_path) purge_processor(caller) def errback(e): - caller.msg(" {RError from processor: '%s'" % e) + caller.msg(" |RError from processor: '%s'" % e) purge_processor(caller) utils.run_async(_PROCPOOL_BATCHCODE_SOURCE, codes=codes, @@ -423,7 +422,7 @@ class CmdBatchCode(_COMMAND_DEFAULT_CLASS): at_err=errback) else: # un in-process (will block) - for inum in range(len(codes)): + for _ in range(len(codes)): # loop through the batch file if not batch_code_exec(caller): return @@ -431,14 +430,14 @@ class CmdBatchCode(_COMMAND_DEFAULT_CLASS): # clean out the safety cmdset and clean out all other # temporary attrs. string = " Batchfile '%s' applied." % python_path - caller.msg("{G%s" % string) + caller.msg("|G%s" % string) purge_processor(caller) -#------------------------------------------------------------ +# ------------------------------------------------------------- # State-commands for the interactive batch processor modes # (these are the same for both processors) -#------------------------------------------------------------ +# ------------------------------------------------------------- class CmdStateAbort(_COMMAND_DEFAULT_CLASS): """ @@ -453,7 +452,7 @@ class CmdStateAbort(_COMMAND_DEFAULT_CLASS): locks = "cmd:perm(batchcommands)" def func(self): - "Exit back to default." + """Exit back to default.""" purge_processor(self.caller) 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): show_curr(self.caller, showall=True) + class CmdStatePP(_COMMAND_DEFAULT_CLASS): """ pp @@ -644,7 +644,7 @@ class CmdStateSS(_COMMAND_DEFAULT_CLASS): else: step = 1 - for istep in range(step): + for _ in range(step): if caller.ndb.batch_batchmode == "batch_code": batch_code_exec(caller) else: @@ -673,7 +673,7 @@ class CmdStateSL(_COMMAND_DEFAULT_CLASS): else: step = 1 - for istep in range(step): + for _ in range(step): if caller.ndb.batch_batchmode == "batch_code": batch_code_exec(caller) else: @@ -699,7 +699,7 @@ class CmdStateCC(_COMMAND_DEFAULT_CLASS): ptr = caller.ndb.batch_stackptr step = nstack - ptr - for istep in range(step): + for _ in range(step): if caller.ndb.batch_batchmode == "batch_code": batch_code_exec(caller) else: @@ -775,7 +775,7 @@ class CmdStateQQ(_COMMAND_DEFAULT_CLASS): class CmdStateHH(_COMMAND_DEFAULT_CLASS): - "Help command" + """Help command""" key = "hh" help_category = "BatchProcess" @@ -810,12 +810,12 @@ class CmdStateHH(_COMMAND_DEFAULT_CLASS): self.caller.msg(string) -#------------------------------------------------------------ +# ------------------------------------------------------------- # # Defining the cmdsets for the interactive batchprocessor # mode (same for both processors) # -#------------------------------------------------------------ +# ------------------------------------------------------------- class BatchSafeCmdSet(CmdSet): """ @@ -827,7 +827,7 @@ class BatchSafeCmdSet(CmdSet): priority = 150 # override other cmdsets. def at_cmdset_creation(self): - "Init the cmdset" + """Init the cmdset""" self.add(CmdStateAbort()) @@ -839,7 +839,7 @@ class BatchInteractiveCmdSet(CmdSet): priority = 104 def at_cmdset_creation(self): - "init the cmdset" + """init the cmdset""" self.add(CmdStateAbort()) self.add(CmdStateLL()) self.add(CmdStatePP())