Fixed issues with batch-code processor not working correctly. Also added some better parsing. Resolves issue 221.

This commit is contained in:
Griatch 2012-03-20 22:29:37 +01:00
parent 81e7a31072
commit 1ca8df9e70
5 changed files with 39 additions and 36 deletions

View file

@ -43,7 +43,7 @@ from src.utils import create, search
from game.gamesrc.objects.examples import red_button
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)

View file

@ -151,7 +151,7 @@ def show_curr(caller, showall=False):
string += "{G(hh for help)"
if showall:
for line in codeall.split('\n'):
string += "\n{n>>> %s" % line
string += "\n{G|{n %s" % line
caller.msg(string)
def purge_processor(caller):
@ -296,8 +296,8 @@ class CmdBatchCode(MuxCommand):
if not codes:
string = "'%s' not found.\nYou have to supply the python path "
string += "of the file relative to \nyour batch-file directory (%s)."
caller.msg(string % (python_path, settings.BASE_BATCHPROCESS_PATH))
string += "of the file relative to \nyour batch-file directories (%s)."
caller.msg(string % (python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS)))
return
switches = self.switches

View file

@ -191,7 +191,7 @@ class ObjectManager(TypedObjectManager):
If None, the default 'key' attribute is used.
location: If None, character.location will be used.
"""
#ostring = str(ostring).strip()
ostring = to_unicode(ostring, force_string=True)
if not ostring:
return []
@ -210,16 +210,16 @@ class ObjectManager(TypedObjectManager):
if location and ostring == 'here':
return [location]
if caller and to_unicode(ostring) in ('me', 'self'):
if caller and ostring in ('me', 'self'):
return [caller]
if caller and to_unicode(ostring) in ('*me', '*self'):
if caller and ostring in ('*me', '*self'):
return [caller]
# Test if we are looking for an object controlled by a
# specific player
#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_match = self.get_object_with_player(ostring)
if player_match is not None:

View file

@ -31,16 +31,20 @@ class Object(TypeClass):
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
parent doesn't work.
"""
result = other and other.id == self.id
try:
uresult = other and (other.user.id == self.user.id)
except AttributeError:
uresult = False
return result or uresult
result = self.id == other
if not result and hasattr(other, "id"):
result = self.id == other.id
if not result:
try:
result = other and self.user.id == other.user.id
except AttributeError:
pass
return result
# hooks called by the game engine

View file

@ -147,6 +147,7 @@ from src.utils import utils
from game import settings as settings_module
ENCODINGS = settings.ENCODINGS
CODE_INFO_HEADER = re.compile(r"\(.*?\)")
#------------------------------------------------------------
# Helper function
@ -327,29 +328,24 @@ class BatchCodeProcessor(object):
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", "", "")
elif line.startswith("#CODE"):
elif parseline.startswith("#CODE"):
# parse code command
line = line.lstrip("#CODE").strip()
objs = []
info = ""
if line and '(' in line and ')' in line:
# a code description
lp = line.find('(')
rp = line.find(')')
info = line[lp:rp+1]
line = line[rp+1:]
if line:
objs = [obj.strip() for obj in line.split(',')]
info = CODE_INFO_HEADER.findall(line) or ""
if info:
info = info[0]
line = line.replace(info, "")
objs = [o.strip() for o in line.split(",") if o.strip()]
return ("codeheader", info, objs)
elif line.startswith('#'):
return ('comment', "", "\n%s" % line)
elif parseline.startswith('#'):
return ('comment', "", "%s" % line)
else:
#normal line - return it with a line break.
return ('line', "", "\n%s" % line)
return ('line', "", "%s" % line)
# read indata
@ -398,10 +394,13 @@ class BatchCodeProcessor(object):
# last, we merge the headers with all codes.
for codedict in codes:
codedict["code"] = "#CODE %s %s\n%s\n\n%s" % (codedict['info'],
", ".join(codedict["objs"]),
header.strip(),
codedict["code"].strip())
objs = ", ".join(codedict["objs"])
if objs:
objs = "[%s]" % objs
codedict["code"] = "#CODE %s %s \n%s\n\n%s" % (codedict['info'],
objs,
header.strip(),
codedict["code"].strip())
return codes
def code_exec(self, codedict, extra_environ=None, debug=False):
@ -429,7 +428,7 @@ class BatchCodeProcessor(object):
# execute the block
try:
exec(code, environdict)
except Exception:
except Exception, e:
errlist = format_exc().split('\n')
if len(errlist) > 4:
errlist = errlist[4:]