Fixed issues with batch-code processor not working correctly. Also added some better parsing. Resolves issue 221.
This commit is contained in:
parent
81e7a31072
commit
1ca8df9e70
5 changed files with 39 additions and 36 deletions
|
|
@ -43,7 +43,7 @@ from src.utils import create, search
|
||||||
from game.gamesrc.objects.examples import red_button
|
from game.gamesrc.objects.examples import red_button
|
||||||
from game.gamesrc.objects import baseobjects
|
from game.gamesrc.objects import baseobjects
|
||||||
|
|
||||||
limbo = search.objects(caller, 'Limbo', global_search=True)[0]
|
limbo = search.objects('Limbo', global_search=True)[0]
|
||||||
|
|
||||||
|
|
||||||
#CODE (create red button)
|
#CODE (create red button)
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ def show_curr(caller, showall=False):
|
||||||
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{n>>> %s" % line
|
string += "\n{G|{n %s" % line
|
||||||
caller.msg(string)
|
caller.msg(string)
|
||||||
|
|
||||||
def purge_processor(caller):
|
def purge_processor(caller):
|
||||||
|
|
@ -296,8 +296,8 @@ class CmdBatchCode(MuxCommand):
|
||||||
|
|
||||||
if not codes:
|
if not codes:
|
||||||
string = "'%s' not found.\nYou have to supply the python path "
|
string = "'%s' not found.\nYou have to supply the python path "
|
||||||
string += "of the file relative to \nyour batch-file directory (%s)."
|
string += "of the file relative to \nyour batch-file directories (%s)."
|
||||||
caller.msg(string % (python_path, settings.BASE_BATCHPROCESS_PATH))
|
caller.msg(string % (python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS)))
|
||||||
return
|
return
|
||||||
switches = self.switches
|
switches = self.switches
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ class ObjectManager(TypedObjectManager):
|
||||||
If None, the default 'key' attribute is used.
|
If None, the default 'key' attribute is used.
|
||||||
location: If None, character.location will be used.
|
location: If None, character.location will be used.
|
||||||
"""
|
"""
|
||||||
#ostring = str(ostring).strip()
|
ostring = to_unicode(ostring, force_string=True)
|
||||||
|
|
||||||
if not ostring:
|
if not ostring:
|
||||||
return []
|
return []
|
||||||
|
|
@ -210,16 +210,16 @@ class ObjectManager(TypedObjectManager):
|
||||||
|
|
||||||
if location and ostring == 'here':
|
if location and ostring == 'here':
|
||||||
return [location]
|
return [location]
|
||||||
if caller and to_unicode(ostring) in ('me', 'self'):
|
if caller and ostring in ('me', 'self'):
|
||||||
return [caller]
|
return [caller]
|
||||||
if caller and to_unicode(ostring) in ('*me', '*self'):
|
if caller and ostring in ('*me', '*self'):
|
||||||
return [caller]
|
return [caller]
|
||||||
|
|
||||||
# Test if we are looking for an object controlled by a
|
# Test if we are looking for an object controlled by a
|
||||||
# specific player
|
# specific player
|
||||||
|
|
||||||
#logger.log_infomsg(str(type(ostring)))
|
#logger.log_infomsg(str(type(ostring)))
|
||||||
if to_unicode(ostring).startswith("*"):
|
if ostring.startswith("*"):
|
||||||
# Player search - try to find obj by its player's name
|
# Player search - try to find obj by its player's name
|
||||||
player_match = self.get_object_with_player(ostring)
|
player_match = self.get_object_with_player(ostring)
|
||||||
if player_match is not None:
|
if player_match is not None:
|
||||||
|
|
|
||||||
|
|
@ -31,16 +31,20 @@ class Object(TypeClass):
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
"""
|
"""
|
||||||
|
Checks for equality against an id string or another object or user.
|
||||||
|
|
||||||
This has be located at this level, having it in the
|
This has be located at this level, having it in the
|
||||||
parent doesn't work.
|
parent doesn't work.
|
||||||
"""
|
"""
|
||||||
|
result = self.id == other
|
||||||
result = other and other.id == self.id
|
if not result and hasattr(other, "id"):
|
||||||
try:
|
result = self.id == other.id
|
||||||
uresult = other and (other.user.id == self.user.id)
|
if not result:
|
||||||
except AttributeError:
|
try:
|
||||||
uresult = False
|
result = other and self.user.id == other.user.id
|
||||||
return result or uresult
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
return result
|
||||||
|
|
||||||
# hooks called by the game engine
|
# hooks called by the game engine
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,7 @@ from src.utils import utils
|
||||||
from game import settings as settings_module
|
from game import settings as settings_module
|
||||||
|
|
||||||
ENCODINGS = settings.ENCODINGS
|
ENCODINGS = settings.ENCODINGS
|
||||||
|
CODE_INFO_HEADER = re.compile(r"\(.*?\)")
|
||||||
|
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
# Helper function
|
# Helper function
|
||||||
|
|
@ -327,29 +328,24 @@ class BatchCodeProcessor(object):
|
||||||
Identifies the line type: block command, comment, empty or normal code.
|
Identifies the line type: block command, comment, empty or normal code.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
line = line.strip()
|
parseline = line.strip()
|
||||||
|
|
||||||
if line.startswith("#HEADER"):
|
if parseline.startswith("#HEADER"):
|
||||||
return ("header", "", "")
|
return ("header", "", "")
|
||||||
elif line.startswith("#CODE"):
|
elif parseline.startswith("#CODE"):
|
||||||
# parse code command
|
# parse code command
|
||||||
line = line.lstrip("#CODE").strip()
|
line = line.lstrip("#CODE").strip()
|
||||||
objs = []
|
info = CODE_INFO_HEADER.findall(line) or ""
|
||||||
info = ""
|
if info:
|
||||||
if line and '(' in line and ')' in line:
|
info = info[0]
|
||||||
# a code description
|
line = line.replace(info, "")
|
||||||
lp = line.find('(')
|
objs = [o.strip() for o in line.split(",") if o.strip()]
|
||||||
rp = line.find(')')
|
|
||||||
info = line[lp:rp+1]
|
|
||||||
line = line[rp+1:]
|
|
||||||
if line:
|
|
||||||
objs = [obj.strip() for obj in line.split(',')]
|
|
||||||
return ("codeheader", info, objs)
|
return ("codeheader", info, objs)
|
||||||
elif line.startswith('#'):
|
elif parseline.startswith('#'):
|
||||||
return ('comment', "", "\n%s" % line)
|
return ('comment', "", "%s" % line)
|
||||||
else:
|
else:
|
||||||
#normal line - return it with a line break.
|
#normal line - return it with a line break.
|
||||||
return ('line', "", "\n%s" % line)
|
return ('line', "", "%s" % line)
|
||||||
|
|
||||||
# read indata
|
# read indata
|
||||||
|
|
||||||
|
|
@ -398,10 +394,13 @@ class BatchCodeProcessor(object):
|
||||||
|
|
||||||
# last, we merge the headers with all codes.
|
# last, we merge the headers with all codes.
|
||||||
for codedict in codes:
|
for codedict in codes:
|
||||||
codedict["code"] = "#CODE %s %s\n%s\n\n%s" % (codedict['info'],
|
objs = ", ".join(codedict["objs"])
|
||||||
", ".join(codedict["objs"]),
|
if objs:
|
||||||
header.strip(),
|
objs = "[%s]" % objs
|
||||||
codedict["code"].strip())
|
codedict["code"] = "#CODE %s %s \n%s\n\n%s" % (codedict['info'],
|
||||||
|
objs,
|
||||||
|
header.strip(),
|
||||||
|
codedict["code"].strip())
|
||||||
return codes
|
return codes
|
||||||
|
|
||||||
def code_exec(self, codedict, extra_environ=None, debug=False):
|
def code_exec(self, codedict, extra_environ=None, debug=False):
|
||||||
|
|
@ -429,7 +428,7 @@ class BatchCodeProcessor(object):
|
||||||
# execute the block
|
# execute the block
|
||||||
try:
|
try:
|
||||||
exec(code, environdict)
|
exec(code, environdict)
|
||||||
except Exception:
|
except Exception, e:
|
||||||
errlist = format_exc().split('\n')
|
errlist = format_exc().split('\n')
|
||||||
if len(errlist) > 4:
|
if len(errlist) > 4:
|
||||||
errlist = errlist[4:]
|
errlist = errlist[4:]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue