def typeclass_search(self, typeclass, include_children=False, include_parents=False): """ Searches through all objects returning those which has a certain typeclass. If location is set, limit search to objects in that location. typeclass - a typeclass class or a python path to a typeclass include_children - return objects with given typeclass and all children inheriting from this typeclass. include_parents - return objects with given typeclass and all parents to this typeclass The include_children/parents keywords are mutually exclusive. """ if callable(typeclass): cls = typeclass.__class__ typeclass = "%s.%s" % (cls.__module__, cls.__name__) elif not isinstance(typeclass, basestring) and hasattr( typeclass, "path"): typeclass = typeclass.path # query objects of exact typeclass query = Q(db_typeclass_path__exact=typeclass) if include_children: # build requests for child typeclass objects clsmodule, clsname = typeclass.rsplit(".", 1) cls = variable_from_module(clsmodule, clsname) subclasses = cls.__subclasses__() if subclasses: for child in (child for child in subclasses if hasattr(child, "path")): query = query | Q(db_typeclass_path__exact=child.path) elif include_parents: # build requests for parent typeclass objects clsmodule, clsname = typeclass.rsplit(".", 1) cls = variable_from_module(clsmodule, clsname) parents = cls.__mro__ if parents: for parent in (parent for parent in parents if hasattr(parent, "path")): query = query | Q(db_typeclass_path__exact=parent.path) # actually query the database return self.filter(query)
def typeclass_search(self, typeclass, include_children=False, include_parents=False): """ Searches through all objects returning those which has a certain typeclass. If location is set, limit search to objects in that location. typeclass - a typeclass class or a python path to a typeclass include_children - return objects with given typeclass and all children inheriting from this typeclass. include_parents - return objects with given typeclass and all parents to this typeclass The include_children/parents keywords are mutually exclusive. """ if callable(typeclass): cls = typeclass.__class__ typeclass = "%s.%s" % (cls.__module__, cls.__name__) elif not isinstance(typeclass, basestring) and hasattr(typeclass, "path"): typeclass = typeclass.path # query objects of exact typeclass query = Q(db_typeclass_path__exact=typeclass) if include_children: # build requests for child typeclass objects clsmodule, clsname = typeclass.rsplit(".", 1) cls = variable_from_module(clsmodule, clsname) subclasses = cls.__subclasses__() if subclasses: for child in (child for child in subclasses if hasattr(child, "path")): query = query | Q(db_typeclass_path__exact=child.path) elif include_parents: # build requests for parent typeclass objects clsmodule, clsname = typeclass.rsplit(".", 1) cls = variable_from_module(clsmodule, clsname) parents = cls.__mro__ if parents: for parent in (parent for parent in parents if hasattr(parent, "path")): query = query | Q(db_typeclass_path__exact=parent.path) # actually query the database return self.filter(query)
def delayed_import(): "Helper method for delayed import of all needed entities" global _ServerSession, _PlayerDB, _ServerConfig, _ScriptDB if not _ServerSession: # we allow optional arbitrary serversession class for overloading modulename, classname = settings.SERVER_SESSION_CLASS.rsplit(".", 1) _ServerSession = variable_from_module(modulename, classname) if not _PlayerDB: from src.players.models import PlayerDB as _PlayerDB if not _ServerConfig: from src.server.models import ServerConfig as _ServerConfig if not _ScriptDB: from src.scripts.models import ScriptDB as _ScriptDB # including once to avoid warnings in Python syntax checkers _ServerSession, _PlayerDB, _ServerConfig, _ScriptDB
def amp_function_call(self, module, function, args, kwargs): """ This allows Portal- and Server-process to call an arbitrary function in the other process. It is intended for use by plugin modules. """ args = loads(args) kwargs = loads(kwargs) # call the function (don't catch tracebacks here) result = variable_from_module(module, function)(*args, **kwargs) if isinstance(result, Deferred): # if result is a deferred, attach handler to properly wrap the return value result.addCallback(lambda r: {"result":dumps(r)}) return result else: return {'result':dumps(result)}
def amp_function_call(self, module, function, args, **kwargs): """ This allows Portal- and Server-process to call an arbitrary function in the other process. It is intended for use by plugin modules. """ args = loads(args) kwargs = loads(kwargs) # call the function (don't catch tracebacks here) result = variable_from_module(module, function)(*args, **kwargs) if isinstance(result, Deferred): # if result is a deferred, attach handler to properly # wrap the return value result.addCallback(lambda r: {"result": dumps(r)}) return result else: return {'result': dumps(result)}
listings to have their crawlers find the mud and automatically extract relevant information about it, such as genre, how many active players and so on. """ from django.conf import settings from src.utils import utils MSSP = chr(70) MSSP_VAR = chr(1) MSSP_VAL = chr(2) # try to get the customized mssp info, if it exists. MSSPTable_CUSTOM = utils.variable_from_module(settings.MSSP_META_MODULE, "MSSPTable", default={}) class Mssp(object): """ Implements the MSSP protocol. Add this to a variable on the telnet protocol to set it up. """ def __init__(self, protocol): """ initialize MSSP by storing protocol on ourselves and calling the client to see if it supports MSSP. """ self.protocol = protocol
from twisted.internet.defer import inlineCallbacks, returnValue from django.conf import settings from src.comms.channelhandler import CHANNELHANDLER from src.utils import logger, utils from src.commands.cmdparser import at_multimatch_cmd from src.utils.utils import string_suggestions, to_unicode from django.utils.translation import ugettext as _ __all__ = ("cmdhandler", ) _GA = object.__getattribute__ _CMDSET_MERGE_CACHE = WeakValueDictionary() # This decides which command parser is to be used. # You have to restart the server for changes to take effect. _COMMAND_PARSER = utils.variable_from_module( *settings.COMMAND_PARSER.rsplit('.', 1)) # System command names - import these variables rather than trying to # remember the actual string constants. If not defined, Evennia # hard-coded defaults are used instead. # command to call if user just presses <return> with no input CMD_NOINPUT = "__noinput_command" # command to call if no command match was found CMD_NOMATCH = "__nomatch_command" # command to call if multiple command matches were found CMD_MULTIMATCH = "__multimatch_command" # command to call if found command is the name of a channel CMD_CHANNEL = "__send_to_channel_command" # command to call as the very first one when the user connects. # (is expected to display the login screen)
options, args = parser.parse_args() nargs = len(args) nclients = DEFAULT_NCLIENTS timestep = DEFAULT_TIMESTEP port = DEFAULT_PORT try: if not args : raise Exception if nargs > 0: nclients = max(1, int(args[0])) if nargs > 1: timestep = max(1, int(args[1])) if nargs > 2: port = int(args[2]) except Exception: print HELPTEXT sys.exit() # import the ACTION tuple from a given module try: action_modpath = settings.DUMMYRUNNER_ACTIONS_MODULE except AttributeError: # use default action_modpath = "src.utils.dummyrunner.dummyrunner_actions" actions = utils.variable_from_module(action_modpath, "ACTIONS") print "Connecting %i dummy client(s) to port %i using a %i second timestep ... " % (nclients, port, timestep) t0 = time.time() start_all_dummy_clients(actions, nclients, timestep, port, verbose=options.verbose) ttot = time.time() - t0 print "... dummy client runner finished after %i seconds." % ttot
def add_cmds(module): "helper method for populating this object with cmds" cmdlist = utils.variable_from_module(module, module.__all__) self.__dict__.update(dict([(c.__name__, c) for c in cmdlist]))
from twisted.internet.defer import inlineCallbacks, returnValue from django.conf import settings from src.comms.channelhandler import CHANNELHANDLER from src.utils import logger, utils from src.commands.cmdparser import at_multimatch_cmd from src.utils.utils import string_suggestions, to_unicode from django.utils.translation import ugettext as _ __all__ = ("cmdhandler",) _GA = object.__getattribute__ _CMDSET_MERGE_CACHE = WeakValueDictionary() # This decides which command parser is to be used. # You have to restart the server for changes to take effect. _COMMAND_PARSER = utils.variable_from_module(*settings.COMMAND_PARSER.rsplit('.', 1)) # System command names - import these variables rather than trying to # remember the actual string constants. If not defined, Evennia # hard-coded defaults are used instead. # command to call if user just presses <return> with no input CMD_NOINPUT = "__noinput_command" # command to call if no command match was found CMD_NOMATCH = "__nomatch_command" # command to call if multiple command matches were found CMD_MULTIMATCH = "__multimatch_command" # command to call if found command is the name of a channel CMD_CHANNEL = "__send_to_channel_command" # command to call as the very first one when the user connects. # (is expected to display the login screen)
from src.typeclasses.models import (TypedObject, TagHandler, NickHandler, AliasHandler, AttributeHandler) from src.commands.cmdsethandler import CmdSetHandler from src.commands import cmdhandler from src.utils import utils, logger from src.utils.utils import to_str, make_iter from django.utils.translation import ugettext as _ __all__ = ("PlayerDB",) _ME = _("me") _SELF = _("self") _SESSIONS = None _AT_SEARCH_RESULT = utils.variable_from_module(*settings.SEARCH_AT_RESULT.rsplit('.', 1)) _MULTISESSION_MODE = settings.MULTISESSION_MODE _GA = object.__getattribute__ _SA = object.__setattr__ _DA = object.__delattr__ _TYPECLASS = None #------------------------------------------------------------ # # PlayerDB # #------------------------------------------------------------
from src.objects.manager import ObjectManager from src.players.models import PlayerDB from src.commands.cmdsethandler import CmdSetHandler from src.commands import cmdhandler from src.scripts.scripthandler import ScriptHandler from src.utils import logger from src.utils.utils import (make_iter, to_str, to_unicode, lazy_property, variable_from_module, dbref) MULTISESSION_MODE = settings.MULTISESSION_MODE from django.utils.translation import ugettext as _ #__all__ = ("ObjectDB", ) _ScriptDB = None _AT_SEARCH_RESULT = variable_from_module( *settings.SEARCH_AT_RESULT.rsplit('.', 1)) _SESSIONS = None _GA = object.__getattribute__ _SA = object.__setattr__ _DA = object.__delattr__ # the sessid_max is based on the length of the db_sessid csv field (excluding commas) _SESSID_MAX = 16 if MULTISESSION_MODE in (1, 3) else 1 class SessidHandler(object): """ Handles the get/setting of the sessid comma-separated integer field """
listings to have their crawlers find the mud and automatically extract relevant information about it, such as genre, how many active players and so on. """ from django.conf import settings from src.utils import utils MSSP = chr(70) MSSP_VAR = chr(1) MSSP_VAL = chr(2) # try to get the customized mssp info, if it exists. MSSPTable_CUSTOM = utils.variable_from_module(settings.MSSP_META_MODULE, "MSSPTable", default={}) class Mssp(object): """ Implements the MSSP protocol. Add this to a variable on the telnet protocol to set it up. """ def __init__(self, protocol): """ initialize MSSP by storing protocol on ourselves and calling the client to see if it supports MSSP. """ self.protocol = protocol self.protocol.will(MSSP).addCallbacks(self.do_mssp, self.no_mssp)
from django.conf import settings from django.db.models.fields import exceptions from src.typeclasses.managers import TypedObjectManager from src.typeclasses.managers import returns_typeclass, returns_typeclass_list from src.utils import utils from src.utils.utils import to_unicode, is_iter, make_iter, string_partial_matching __all__ = ("ObjectManager", ) _GA = object.__getattribute__ # delayed import _ATTR = None # Try to use a custom way to parse id-tagged multimatches. _AT_MULTIMATCH_INPUT = utils.variable_from_module( *settings.SEARCH_AT_MULTIMATCH_INPUT.rsplit('.', 1)) class ObjectManager(TypedObjectManager): """ This ObjectManager implementes methods for searching and manipulating Objects directly from the database. Evennia-specific search methods (will return Typeclasses or lists of Typeclasses, whereas Django-general methods will return Querysets or database objects). dbref (converter) get_id (alias: dbref_search) get_dbref_range object_totals
from django.db.models.fields import exceptions from src.typeclasses.managers import TypedObjectManager from src.typeclasses.managers import returns_typeclass, returns_typeclass_list from src.utils import utils from src.utils.utils import to_unicode, is_iter, make_iter, string_partial_matching __all__ = ("ObjectManager",) _GA = object.__getattribute__ # delayed import _ATTR = None # Try to use a custom way to parse id-tagged multimatches. _AT_MULTIMATCH_INPUT = utils.variable_from_module(*settings.SEARCH_AT_MULTIMATCH_INPUT.rsplit(".", 1)) class ObjectManager(TypedObjectManager): """ This ObjectManager implementes methods for searching and manipulating Objects directly from the database. Evennia-specific search methods (will return Typeclasses or lists of Typeclasses, whereas Django-general methods will return Querysets or database objects). dbref (converter) get_id (alias: dbref_search) get_dbref_range object_totals
from src.typeclasses.models import TypedObject, TagHandler, NickHandler, AliasHandler, AttributeHandler from src.objects.manager import ObjectManager from src.players.models import PlayerDB from src.commands.cmdsethandler import CmdSetHandler from src.commands import cmdhandler from src.scripts.scripthandler import ScriptHandler from src.utils import logger from src.utils.utils import make_iter, to_str, to_unicode, variable_from_module, dbref, LazyLoadHandler from django.utils.translation import ugettext as _ # __all__ = ("ObjectDB", ) _ScriptDB = None _AT_SEARCH_RESULT = variable_from_module(*settings.SEARCH_AT_RESULT.rsplit(".", 1)) _SESSIONS = None _GA = object.__getattribute__ _SA = object.__setattr__ _DA = object.__delattr__ # ------------------------------------------------------------ # # ObjectDB # # ------------------------------------------------------------ class ObjectDB(TypedObject):