OBS: Run migrate! Made exit's destination into a database field for performance. Fixed a too greedy @reload that caused ContentTypes to loose information. Resolves issue 157.

Migrate with: "python manage.py migrate"
This commit is contained in:
Griatch 2011-04-08 23:10:04 +00:00
parent 0cff54f136
commit 6c53ec2bdb
11 changed files with 227 additions and 84 deletions

View file

@ -575,7 +575,7 @@ class CmdDig(ObjManipCommand):
caller = self.caller
if not self.lhs:
string = "Usage: @dig[/teleport] roomname[;alias;alias...][:parent] [= exit_there"
string = "Usage:@ dig[/teleport] roomname[;alias;alias...][:parent] [= exit_there"
string += "[;alias;alias..][:parent]] "
string += "[, exit_back_here[;alias;alias..][:parent]]"
caller.msg(string)
@ -586,7 +586,7 @@ class CmdDig(ObjManipCommand):
if not room["name"]:
caller.msg("You must supply a new room name.")
return
location = caller.location
location = caller.location
# Create the new room
typeclass = room['option']
@ -600,9 +600,13 @@ class CmdDig(ObjManipCommand):
typeclass.startswith('game.')):
typeclass = "%s.%s" % (settings.BASE_TYPECLASS_PATH,
typeclass)
lockstring = "control:id(%s) or perm(Immortal); delete:id(%s) or perm(Wizard); edit:id(%s) or perm(Wizard)"
lockstring = lockstring % (caller.dbref, caller.dbref, caller.dbref)
new_room = create.create_object(typeclass, room["name"],
aliases=room["aliases"])
new_room.locks.add(lockstring)
room_string = "Created room '%s' of type %s." % (new_room.name, typeclass)
exit_to_string = ""
@ -631,7 +635,8 @@ class CmdDig(ObjManipCommand):
new_to_exit = create.create_object(typeclass, to_exit["name"],
location,
aliases=to_exit["aliases"])
new_to_exit.db._destination = new_room
new_to_exit.destination = new_room
new_to_exit.locks.add(lockstring)
exit_to_string = "\nCreated new Exit to new room: %s (aliases: %s)."
exit_to_string = exit_to_string % (new_to_exit.name,
new_to_exit.aliases)
@ -659,7 +664,8 @@ class CmdDig(ObjManipCommand):
new_back_exit = create.create_object(typeclass, back_exit["name"],
new_room,
aliases=back_exit["aliases"])
new_back_exit.db._destination = location
new_back_exit.destination = location
new_back_exit.locks.add(lockstring)
exit_back_string = "\nExit back from new room: %s (aliases: %s)."
exit_back_string = exit_back_string % (new_back_exit.name,
new_back_exit.aliases)
@ -714,13 +720,13 @@ class CmdLink(MuxCommand):
target = caller.search(self.rhs, global_search=True)
if not target:
return
# if obj is an exit (has db attribute _destination),
# if obj is an exit (has property destination),
# set that, otherwise set home.
if obj.db._destination:
obj.db._destination = target
if obj.destination:
obj.destination = target
if "twoway" in self.switches:
if target.db._destination:
target.db._destination = obj
if target.destination:
target.destination = obj
string = "Link created %s <-> %s (two-way)." % (obj.name, target.name)
else:
string = "Cannot create two-way link to non-exit."
@ -728,7 +734,7 @@ class CmdLink(MuxCommand):
else:
string = "Link created %s -> %s (one way)." % (obj.name, target.name)
else:
# obj is not an exit (has not attribute _destination),
# obj is not an exit (has not property destination),
# so set home instead
obj.home = target
string = "Set %s's home to %s." % (obj.name, target.name)
@ -737,20 +743,19 @@ class CmdLink(MuxCommand):
# this means that no = was given (otherwise rhs
# would have been an empty string). So we inspect
# the home/destination on object
dest = obj.db._destination
dest = obj.destination
if dest:
"%s is an exit to %s." % (obj.name, dest.name)
else:
string = "%s has home %s." % (obj.name, obj.home)
else:
# We gave the command @link 'obj = ' which means we want to
# clear _destination or set home to None.
if obj.db._destination:
obj.db._destination = "None" # it can't be None, or _destination would
# be deleted and obj cease being an exit!
# clear destination or set home to None.
if obj.destination:
del obj.destination
string = "Exit %s no longer links anywhere." % obj.name
else:
obj.home = None
del obj.home
string = "%s no longer has a home." % obj.name
# give feedback
caller.msg(string)
@ -977,19 +982,19 @@ class CmdOpen(ObjManipCommand):
return
if exit_obj:
exit_obj = exit_obj[0]
if not exit_obj.db._destination:
if not exit_obj.destination:
# we are trying to link a non-exit
string = "'%s' already exists and is not an exit!\nIf you want to convert it "
string += "to an exit, you must assign it an attribute '_destination' first."
string += "to an exit, you must assign an object to the 'destination' property first."
caller.msg(string % exit_name)
return None
# we are re-linking an old exit.
old_destination = exit_obj.db._destination
old_destination = exit_obj.destination
if old_destination:
string = "Exit %s already exists." % exit_name
if old_destination.id != destination.id:
# reroute the old exit.
exit_obj.db._destination = destination
exit_obj.destination = destination
exit_obj.aliases = exit_aliases
string += " Rerouted its old destination '%s' to '%s' and changed aliases." % \
(old_destination.name, destination.name)
@ -1002,8 +1007,8 @@ class CmdOpen(ObjManipCommand):
location=location,
aliases=exit_aliases)
if exit_obj:
# storing an attribute _destination is what makes it an exit!
exit_obj.db._destination = destination
# storing a destination is what makes it an exit!
exit_obj.destination = destination
string = "Created new Exit '%s' to %s (aliases: %s)." % (exit_name,
destination.name,
exit_aliases)
@ -1453,6 +1458,8 @@ class CmdExamine(ObjManipCommand):
string += "\n{wTypeclass{n: %s (%s)" % (obj.typeclass, obj.typeclass_path)
string += "\n{wLocation{n: %s" % obj.location
if obj.destination:
string += "\n{wDestination{n: %s" % obj.destination
perms = obj.permissions
if perms:
string += "\n{wPermissions{n: %s" % (", ".join(perms))
@ -1470,7 +1477,7 @@ class CmdExamine(ObjManipCommand):
pobjs = []
things = []
for content in obj.contents:
if content.db._destination:
if content.destination:
# an exit
exits.append(content)
elif content.player:

View file

@ -255,7 +255,7 @@ class CmdGet(MuxCommand):
if caller == obj:
caller.msg("You can't get yourself.")
return
if obj.player or obj.db._destination:
if obj.player or obj.destination:
# don't allow picking up player objects, nor exits.
caller.msg("You can't get that.")
return

View file

@ -215,7 +215,7 @@ class SystemUseExit(MuxCommand):
exi = caller.search(exit_name)
if not exi:
return
destination = exi.attr('_destination')
destination = exi.destination
if not destination:
return
if exit.access(caller, 'traverse'):

View file

@ -36,33 +36,9 @@ class CmdReload(MuxCommand):
def func(self):
"""
Reload the system.
"""
caller = self.caller
"""
reloads.start_reload_loop()
#reloads.reload_modules()
# max_attempts = 4
# for attempt in range(max_attempts):
# # if reload modules take a long time,
# # we might end up in a situation where
# # the subsequent commands fail since they
# # can't find the reloads module (due to it
# # not yet fully loaded). So we retry a few
# # times before giving up.
# try:
# reloads.reload_scripts()
# reloads.reload_commands()
# break
# except AttributeError:
# if attempt < max_attempts-1:
# caller.msg(" Waiting for modules(s) to finish (%s) ..." % attempt)
# else:
# string = "{r ... The module(s) took too long to reload, "
# string += "\n so the remaining reloads where skipped."
# string += "\n Re-run @reload again when modules have fully "
# string += "\n re-initialized.{n"
# caller.msg(string)
class CmdPy(MuxCommand):
"""
Execute a snippet of python code
@ -296,14 +272,14 @@ class CmdObjects(MuxCommand):
nobjs = ObjectDB.objects.count()
base_typeclass = settings.BASE_CHARACTER_TYPECLASS
nchars = ObjectDB.objects.filter(db_typeclass_path=base_typeclass).count()
nrooms = ObjectDB.objects.filter(db_location=None).exclude(db_typeclass_path=base_typeclass).count()
nexits = sum([1 for obj in ObjectDB.objects.filter(db_location=None) if obj.get_attribute('_destination')])
nrooms = ObjectDB.objects.filter(db_location__isnull=True).exclude(db_typeclass_path=base_typeclass).count()
nexits = ObjectDB.objects.filter(db_location__isnull=False, db_destination__isnull=False).count()
string += "\n{wPlayers:{n %i" % nplayers
string += "\n{wObjects:{n %i" % nobjs
string += "\n{w Characters (base type):{n %i" % nchars
string += "\n{w Rooms (location==None):{n %i" % nrooms
string += "\n{w Exits (.db._destination!=None):{n %i" % nexits
string += "\n{w Exits (destination!=None):{n %i" % nexits
string += "\n{w Other:{n %i\n" % (nobjs - nchars - nrooms - nexits)
dbtotals = ObjectDB.objects.object_totals()
@ -319,8 +295,8 @@ class CmdObjects(MuxCommand):
srow = "{w%s{n" % srow
string += srow
string += "\n\n{wLast %s Objects created:{n" % nlim
objs = list(ObjectDB.objects.all())[-nlim:]
string += "\n\n{wLast %s Objects created:{n" % nlim
objs = ObjectDB.objects.all()[max(0, nobjs-nlim):]
table = [["Created"], ["dbref"], ["name"], ["typeclass"]]
for i, obj in enumerate(objs):