Resolves issue 138.

This commit is contained in:
Griatch 2011-02-28 23:43:14 +00:00
parent e094a4d173
commit 38014eda3c
4 changed files with 33 additions and 21 deletions

View file

@ -28,11 +28,12 @@ except ImportError:
import pickle import pickle
import traceback import traceback
from django.db import models from django.db import models
from django.conf import settings
from django.utils.encoding import smart_str from django.utils.encoding import smart_str
from src.utils.idmapper.models import SharedMemoryModel from src.utils.idmapper.models import SharedMemoryModel
from src.typeclasses import managers from src.typeclasses import managers
from src.utils import logger from src.utils import logger
from src.utils.utils import is_iter from src.utils.utils import is_iter, has_parent
# used by Attribute to efficiently identify stored object types. # used by Attribute to efficiently identify stored object types.
# Note that these have to be updated if directory structure changes. # Note that these have to be updated if directory structure changes.
@ -279,16 +280,6 @@ class Attribute(SharedMemoryModel):
""" """
def has_parent(basepath, obj):
"Checks if basepath is somewhere in objs parent tree."
try:
return any(cls for cls in obj.__class__.mro()
if basepath == "%s.%s" % (cls.__module__, cls.__name__))
except (TypeError, AttributeError):
# this can occur if we tried to store a class object, not an
# instance. Not sure if one should defend against this.
return False
if isinstance(in_value, basestring): if isinstance(in_value, basestring):
# (basestring matches both str and unicode) # (basestring matches both str and unicode)
# strings we just store directly. # strings we just store directly.
@ -533,7 +524,7 @@ class TypedObject(SharedMemoryModel):
""" """
Getter. Allows for value = self.typeclass. Getter. Allows for value = self.typeclass.
The typeclass is a class object found at self.typeclass_path; The typeclass is a class object found at self.typeclass_path;
it allows for extending the ObjectDB for all different it allows for extending the Typed object for all different
types of objects that the game needs. This property types of objects that the game needs. This property
handles loading and initialization of the typeclass on the fly. handles loading and initialization of the typeclass on the fly.
""" """
@ -541,13 +532,23 @@ class TypedObject(SharedMemoryModel):
def errmsg(message): def errmsg(message):
""" """
Helper function to display error. Helper function to display error.
We cannot use self.msg() here since we cannot be sure
it's actually available when error occurs; so we have
to go to the sessionhandler and echo to all connections.
""" """
from src.server.sessionhandler import SESSIONS infochan = None
for session in SESSIONS: try:
session.msg(message) from src.comms.models import Channel
infochan = settings.CHANNEL_MUDINFO
infochan = Channel.objects.get_channel(infochan[0])
except Exception, e:
print e
pass
if infochan:
cname = infochan.key
cmessage = "\n".join(["[%s]: %s" % (cname, line) for line in message.split('\n')])
infochan.msg(message)
else:
# no mudinfo channel is found. Log instead.
cmessage = "\n".join(["[NO MUDINFO CHANNEL]: %s" % line for line in message.split('\n')])
logger.log_errmsg(cmessage)
path = self.db_typeclass_path path = self.db_typeclass_path
@ -570,7 +571,7 @@ class TypedObject(SharedMemoryModel):
if hasattr(typeclass, '__file__'): if hasattr(typeclass, '__file__'):
errstring += "\nThis seems to be just the path to a module. You need" errstring += "\nThis seems to be just the path to a module. You need"
errstring += " to specify the actual typeclass name inside the module too." errstring += " to specify the actual typeclass name inside the module too."
errstring += "\n Typeclass '%s' failed to load." % path errstring += "\n Typeclass '%s' failed to load." % path
defpath = self.default_typeclass_path defpath = self.default_typeclass_path
errstring += " Using Default class '%s'." % defpath errstring += " Using Default class '%s'." % defpath
self.db_typeclass_path = defpath self.db_typeclass_path = defpath
@ -593,6 +594,7 @@ class TypedObject(SharedMemoryModel):
else: else:
TYPECLASS_CACHE[path] = typeclass TYPECLASS_CACHE[path] = typeclass
return typeclass return typeclass
#@typeclass.deleter #@typeclass.deleter
def typeclass_del(self): def typeclass_del(self):
"Deleter. Allows for del self.typeclass (don't allow deletion)" "Deleter. Allows for del self.typeclass (don't allow deletion)"

View file

@ -23,11 +23,10 @@ from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import IntegrityError from django.db import IntegrityError
from src.permissions.permissions import set_perm from src.permissions.permissions import set_perm
from src.permissions.models import PermissionGroup from src.permissions.models import PermissionGroup
from src.utils import logger from src.utils import logger
from src.utils.utils import is_iter from src.utils.utils import is_iter, has_parent
# #
# Game Object creation # Game Object creation

View file

@ -131,6 +131,7 @@ def cemit_info(message):
""" """
logger.log_infomsg(message) logger.log_infomsg(message)
infochan = None
try: try:
infochan = settings.CHANNEL_MUDINFO infochan = settings.CHANNEL_MUDINFO
infochan = Channel.objects.get_channel(infochan[0]) infochan = Channel.objects.get_channel(infochan[0])

View file

@ -432,3 +432,13 @@ def check_evennia_dependencies():
if errstring: if errstring:
print "%s\n %s\n%s" % ("-"*78, errstring, '-'*78) print "%s\n %s\n%s" % ("-"*78, errstring, '-'*78)
return no_error return no_error
def has_parent(basepath, obj):
"Checks if basepath is somewhere in objs parent tree."
try:
return any(cls for cls in obj.__class__.mro()
if basepath == "%s.%s" % (cls.__module__, cls.__name__))
except (TypeError, AttributeError):
# this can occur if we tried to store a class object, not an
# instance. Not sure if one should defend against this.
return False