From 2ba16e155e59153c3c30862739f5b82be43b55bd Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 21 Sep 2013 22:00:46 +0200 Subject: [PATCH] Fixed a bug in amp that made reloading not work. --- contrib/tutorial_world/scripts.py | 22 +++++++++++----------- src/commands/default/comms.py | 7 ++++--- src/commands/default/system.py | 24 +++++++++--------------- src/commands/default/tests.py | 4 ++-- src/objects/models.py | 1 - src/server/amp.py | 10 +++++----- src/typeclasses/models.py | 9 +++++---- src/utils/idmapper/base.py | 5 +++-- 8 files changed, 39 insertions(+), 43 deletions(-) diff --git a/contrib/tutorial_world/scripts.py b/contrib/tutorial_world/scripts.py index 1cc42f7a39..cffb32efe7 100644 --- a/contrib/tutorial_world/scripts.py +++ b/contrib/tutorial_world/scripts.py @@ -1,5 +1,5 @@ """ -This defines some generally useful scripts for the tutorial world. +This defines some generally useful scripts for the tutorial world. """ import random @@ -9,11 +9,11 @@ from ev import Script # # IrregularEvent - script firing at random intervals # -# This is a generally useful script for updating +# This is a generally useful script for updating # objects at irregular intervals. This is used by as diverse -# entities as Weather rooms and mobs. +# entities as Weather rooms and mobs. +# # -# # #------------------------------------------------------------ @@ -22,7 +22,7 @@ class IrregularEvent(Script): This script, which should be tied to a particular object upon instantiation, calls update_irregular on the object at random intervals. - """ + """ def at_script_creation(self): "This setups the script" @@ -30,7 +30,7 @@ class IrregularEvent(Script): self.desc = "Updates at irregular intervals" self.interval = random.randint(30, 70) # interval to call. self.start_delay = True # wait at least self.interval seconds before calling at_repeat the first time - self.persistent = True + self.persistent = True # this attribute determines how likely it is the # 'update_irregular' method gets called on self.obj (value is @@ -69,7 +69,7 @@ class FastIrregularEvent(IrregularEvent): # # # # Note that this will of course allow a single player to end up with multiple versions of objects if # # they just wait around between resets; In a real game environment this would have to be resolved e.g. -# # with custom versions of the 'get' command not accepting doublets. +# # with custom versions of the 'get' command not accepting doublets. # # # # setting up an event for reseting the world. @@ -91,20 +91,20 @@ class FastIrregularEvent(IrregularEvent): # #this you see when running @ps in game: # self.description = 'Reset the tutorial world .' # self.interval = UPDATE_INTERVAL -# self.persistent = True +# self.persistent = True # def event_function(self): # """ # This is called every self.interval seconds. # """ # #find all objects inheriting the subscribing parents -# for parent in RESET_SUBSCRIBERS: +# for parent in RESET_SUBSCRIBERS: # objects = Object.objects.global_object_script_parent_search(parent) # for obj in objects: -# try: +# try: # obj.scriptlink.reset() # except: # logger.log_errmsg(traceback.print_exc()) - + diff --git a/src/commands/default/comms.py b/src/commands/default/comms.py index 13d1bf961e..1376386239 100644 --- a/src/commands/default/comms.py +++ b/src/commands/default/comms.py @@ -272,10 +272,11 @@ class CmdChannels(MuxPlayerCommand): # full listing (of channels caller is able to listen to) comtable = prettytable.PrettyTable(["{wsub","{wchannel","{wmy aliases","{wlocks","{wdescription"]) for chan in channels: - nicks = [nick for nick in caller.nicks.get(category="channel")] - comtable.add_row([chan in subs and "{gYes{n" or "{rNo{n", + nicks = caller.nicks.get(category="channel") + if nicks: + comtable.add_row([chan in subs and "{gYes{n" or "{rNo{n", "%s%s" % (chan.key, chan.aliases and "(%s)" % ",".join(chan.aliases) or ""), - "%s".join(nick.db_nick for nick in nicks if nick.db_real.lower()==clower()), + "%s".join(nick.db_nick for nick in make_iter(nicks) if nick.db_real.lower()==clower()), chan.locks, chan.desc]) caller.msg("\n{wAvailable channels{n (use {wcomlist{n,{waddcom{n and {wdelcom{n to manage subscriptions):\n%s" % comtable) diff --git a/src/commands/default/system.py b/src/commands/default/system.py index 265bc24f48..0a7b043679 100644 --- a/src/commands/default/system.py +++ b/src/commands/default/system.py @@ -17,6 +17,7 @@ from src.scripts.models import ScriptDB from src.objects.models import ObjectDB from src.players.models import PlayerDB from src.utils import logger, utils, gametime, create, is_pypy, prettytable +from src.utils.utils import crop from src.commands.default.muxcommand import MuxCommand # delayed imports @@ -213,24 +214,17 @@ def format_script_list(scripts): table.align = 'r' for script in scripts: nextrep = script.time_until_next_repeat() - #print ([script.id, - # (not hasattr(script, 'obj') or not script.obj) and "" or script.obj.key, - # script.key, - # (not hasattr(script, 'interval') or script.interval < 0) and "--" or "%ss" % script.interval, - # not nextrep and "--" or "%ss" % nextrep, - # (not hasattr(script, 'repeats') or not script.repeats) and "--" or "%i" % script.repeats, - # script.persistent and "*" or "-", - # script.typeclass_path.rsplit('.', 1)[-1], - # script.desc]) + print type(script), + print script.key table.add_row([script.id, - (not hasattr(script, 'obj') or not script.obj) and "" or script.obj.key, + script.obj.key if (hasattr(script, 'obj') and script.obj) else "", script.key, - (not hasattr(script, 'interval') or script.interval < 0) and "--" or "%ss" % script.interval, - not nextrep and "--" or "%ss" % nextrep, - (not hasattr(script, 'repeats') or not script.repeats) and "--" or "%i" % script.repeats, - script.persistent and "*" or "-", + script.interval if script.interval > 0 else "--", + "%ss" % nextrep if nextrep else "--", + "%i" % script.repeats if script.repeats else "--", + "*" if script.persistent else "-", script.typeclass_path.rsplit('.', 1)[-1], - script.desc]) + crop(script.desc, width=20)]) return "%s" % table diff --git a/src/commands/default/tests.py b/src/commands/default/tests.py index 5bbccce26e..41c52e5b0e 100644 --- a/src/commands/default/tests.py +++ b/src/commands/default/tests.py @@ -31,11 +31,11 @@ _RE = re.compile(r"^\+|-+\+|\+-+|--*|\|", re.MULTILINE) # ------------------------------------------------------------ class TestPlayerClass(Player): - def msg(self, message, **kwargs): + def msg(self, text="", **kwargs): "test message" if not self.ndb.stored_msg: self.ndb.stored_msg = [] - self.ndb.stored_msg.append(message) + self.ndb.stored_msg.append(text) def _get_superuser(self): "test with superuser flag" return self.ndb.is_superuser diff --git a/src/objects/models.py b/src/objects/models.py index ead4f91d2f..c6d0d7620b 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -677,7 +677,6 @@ class ObjectDB(TypedObject): if isinstance(data, dict): kwargs.update(data) - if _GA(self, 'player'): # note that we must call the player *typeclass'* msg(), otherwise one couldn't overload it. if not sessid: diff --git a/src/server/amp.py b/src/server/amp.py index ecfe130189..1f47eff0e2 100644 --- a/src/server/amp.py +++ b/src/server/amp.py @@ -347,7 +347,7 @@ class AMPProtocol(amp.AMP): """ Access method called by the Server and executed on the Server. """ - #print "msg server->portal (server side):", sessid, msg, data + #print "msg server->portal (server side):", sessid, msg, kwargs try: return self.callRemote(MsgServer2Portal, sessid=sessid, @@ -370,7 +370,7 @@ class AMPProtocol(amp.AMP): data = loads(data) server_sessionhandler = self.factory.server.sessions - #print "serveradmin (server side):", sessid, operation, data + #print "serveradmin (server side):", sessid, ord(operation), data if operation == PCONN: #portal_session_connect # create a new session and sync it @@ -395,7 +395,7 @@ class AMPProtocol(amp.AMP): """ Access method called by the Portal and Executed on the Portal. """ - #print "serveradmin (portal side):", sessid, operation, data + #print "serveradmin (portal side):", sessid, ord(operation), data data = dumps(data) return self.callRemote(ServerAdmin, @@ -441,7 +441,7 @@ class AMPProtocol(amp.AMP): return {} PortalAdmin.responder(amp_portal_admin) - def call_remote_PortalAdmin(self, sessid, operation="", **kwargs): + def call_remote_PortalAdmin(self, sessid, operation="", data=""): """ Access method called by the server side. """ @@ -449,7 +449,7 @@ class AMPProtocol(amp.AMP): return self.callRemote(PortalAdmin, sessid=sessid, operation=operation, - data=dumps(kwargs)).addErrback(self.errback, "PortalAdmin") + data=dumps(data)).addErrback(self.errback, "PortalAdmin") # Extra functions diff --git a/src/typeclasses/models.py b/src/typeclasses/models.py index 060785f062..30e7866f31 100644 --- a/src/typeclasses/models.py +++ b/src/typeclasses/models.py @@ -295,7 +295,7 @@ class AttributeHandler(object): ret.append(True if _GA(self.obj, self._m2m_fieldname).filter(Q(db_key__iexact=keystr) & category_cond) else False) return ret[0] if len(ret)==1 else ret - def get(self, key, category=None, default=None, return_obj=False, strattr=False, + def get(self, key=None, category=None, default=None, return_obj=False, strattr=False, raise_exception=False, accessing_obj=None, default_access=True): """ Returns the value of the given Attribute or list of Attributes. @@ -316,8 +316,9 @@ class AttributeHandler(object): for keystr in make_iter(key): cachekey = "%s%s" % (category if category else "", keystr) attr_obj = get_attr_cache(self.obj, cachekey) + key_cond = Q(db_key__iexact=keystr) if key!=None else Q() if not attr_obj: - attr_obj = _GA(self.obj, "db_attributes").filter(Q(db_key__iexact=keystr) & category_cond) + attr_obj = _GA(self.obj, "db_attributes").filter(key_cond & category_cond) if not attr_obj: if raise_exception: raise AttributeError @@ -439,10 +440,10 @@ class NickHandler(AttributeHandler): "Add a new nick" category = "nick_%s" % category super(NickHandler, self).add(key, replacement, category=category, strattr=True, **kwargs) - def get(self, key, category="inputline", **kwargs): + def get(self, key=None, category="inputline", **kwargs): "Get the replacement value matching the given key and category" category = "nick_%s" % category - return super(NickHandler, self).get(key, category=category, strattr=True, **kwargs) + return super(NickHandler, self).get(key=key, category=category, strattr=True, **kwargs) def remove(self, key, category="inputline", **kwargs): "Remove Nick with matching category" category = "nick_%s" % category diff --git a/src/utils/idmapper/base.py b/src/utils/idmapper/base.py index 3db0220ff7..2cee151926 100755 --- a/src/utils/idmapper/base.py +++ b/src/utils/idmapper/base.py @@ -110,9 +110,10 @@ class SharedMemoryModelBase(ModelBase): if dbid: try: value = cls._default_manager.get(id=dbid) - except ObjectDoesNotExist: + except ObjectDoesNotExist,e: # maybe it is just a name that happens to look like a dbid - pass + from src.utils.logger import log_trace + log_trace() #print "_set wrapper:", fname, value, type(value), cls._get_pk_val(cls._meta) _SA(cls, fname, value) # only use explicit update_fields in save if we actually have a