Some minor performance enhancements and an experimental profiler.

This commit is contained in:
Greg Taylor 2007-01-02 01:14:07 +00:00
parent c5975f522f
commit 18cf29b0cf
5 changed files with 53 additions and 47 deletions

View file

@ -23,6 +23,12 @@ class Attribute(models.Model):
class Admin:
list_display = ('object', 'name', 'value',)
search_fields = ['name']
def get_name(self):
"""
Returns an attribute's name.
"""
return self.name
class Object(models.Model):
"""
@ -51,6 +57,9 @@ class Object(models.Model):
Used to figure out if one object is the same as another.
"""
return self.id == other.id
def __str__(self):
return "%s" % (self.get_name(),)
class Meta:
permissions = (
@ -186,18 +195,18 @@ class Object(models.Model):
Returns an object's name.
"""
if fullname:
return ansi.parse_ansi(self.name, strip_ansi=True)
return "%s(#%d%s)" % (ansi.parse_ansi(self.name, strip_ansi=True),self.id, self.flag_string())
else:
return ansi.parse_ansi(self.name.split(';')[0], strip_ansi=True)
return "%s(#%d%s)" % (ansi.parse_ansi(self.name.split(';')[0], strip_ansi=True),self.id, self.flag_string())
def get_ansiname(self, fullname=False):
"""
Returns an object's ANSI'd name.
"""
if fullname:
return ansi.parse_ansi(self.ansi_name)
return "%s(#%d%s)" % (ansi.parse_ansi(self.ansi_name), self.id, self.flag_string())
else:
return ansi.parse_ansi(self.ansi_name.split(';')[0])
return "%s(#%d%s)" % (ansi.parse_ansi(self.ansi_name.split(';')[0]), self.id, self.flag_string())
def set_description(self, new_desc):
"""
@ -222,7 +231,7 @@ class Object(models.Model):
else:
return retval
except:
return None
return ""
def get_flags(self):
"""
@ -250,20 +259,19 @@ class Object(models.Model):
else:
return False
def clear_all_attributes(self):
"""
Clears all of an object's attributes.
"""
attribs = Attribute.objects.filter(object=self)
for attrib in attribs:
self.delete()
def get_all_attributes(self):
"""
Returns a QuerySet of an object's attributes.
"""
attribs = Attribute.objects.filter(object=self)
return attribs
return self.attribute_set.all()
def clear_all_attributes(self):
"""
Clears all of an object's attributes.
"""
self.get_all_attributes()
for attrib in attribs:
self.delete()
def destroy(self):
"""
@ -584,8 +592,5 @@ class Object(models.Model):
type_string = global_defines.OBJECT_TYPES[self.type][1][0]
return type_string
def __str__(self):
return "%s(#%d%s)" % (self.get_ansiname(), self.id, self.flag_string())
import functions_db
import session_mgr

View file

@ -11,6 +11,13 @@ import os
Generic command module. Pretty much every command should go here for
now.
"""
def cmd_idle(cdat):
"""
Returns nothing, this lets the player set an idle timer without spamming
his screen.
"""
pass
def cmd_inventory(cdat):
"""
Shows a player's inventory.
@ -46,7 +53,7 @@ def cmd_look(cdat):
if len(results) > 1:
session.msg("More than one match found (please narrow target):")
for result in results:
session.msg(" %s" % (result,))
session.msg(" %s" % (result.get_ansiname(),))
return
elif len(results) == 0:
session.msg("I don't see that here.")
@ -54,11 +61,8 @@ def cmd_look(cdat):
else:
target_obj = results[0]
retval = "%s%s(#%i%s)\r\n%s" % (
retval = "%s\r\n%s" % (
target_obj.get_ansiname(),
ansi.ansi["normal"],
target_obj.id,
target_obj.flag_string(),
target_obj.get_description(),
)
session.msg(retval)
@ -79,15 +83,15 @@ def cmd_look(cdat):
if con_players:
session.msg("%sPlayers:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
for player in con_players:
session.msg('%s' %(player,))
session.msg('%s' %(player.get_ansiname(),))
if con_things:
session.msg("%sContents:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
for thing in con_things:
session.msg('%s' %(thing,))
session.msg('%s' %(thing.get_ansiname(),))
if con_exits:
session.msg("%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
for exit in con_exits:
session.msg('%s' %(exit,))
session.msg('%s' %(exit.get_ansiname(),))
def cmd_examine(cdat):
"""
@ -105,18 +109,15 @@ def cmd_examine(cdat):
if len(results) > 1:
session.msg("More than one match found (please narrow target):")
for result in results:
session.msg(" %s" % (result,))
session.msg(" %s" % (result.get_ansiname(),))
return
elif len(results) == 0:
session.msg("I don't see that here.")
return
else:
target_obj = results[0]
session.msg("%s%s(#%i%s)\r\n%s" % (
session.msg("%s\r\n%s" % (
target_obj.get_ansiname(fullname=True),
ansi.ansi["normal"],
target_obj.id,
target_obj.flag_string(),
target_obj.get_description(no_parsing=True),
))
session.msg("Type: %s Flags: %s" % (target_obj.get_type(), target_obj.get_flags()))
@ -124,31 +125,31 @@ def cmd_examine(cdat):
session.msg("Zone: %s" % (target_obj.get_zone(),))
for attribute in target_obj.get_all_attributes():
session.msg("%s%s%s: %s" % (ansi.ansi["hilite"], attribute.name, ansi.ansi["normal"], attribute.value))
session.msg("%s%s%s: %s" % (ansi.ansi["hilite"], attribute.get_name(), ansi.ansi["normal"], attribute.value))
con_players = []
con_things = []
con_exits = []
for obj in target_obj.get_contents():
if obj.is_player:
if obj.is_player():
con_players.append(obj)
elif obj.is_exit:
elif obj.is_exit():
con_exits.append(obj)
else:
elif obj.is_thing():
con_things.append(obj)
if con_players or con_things:
session.msg("Contents:")
session.msg("%sContents:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
for player in con_players:
session.msg('%s' %(player,))
session.msg('%s' % (player.get_ansiname(fullname=True),))
for thing in con_things:
session.msg('%s' %(thing,))
session.msg('%s' % (thing.get_ansiname(fullname=True),))
if con_exits:
session.msg("%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
for exit in con_exits:
session.msg('%s' %(exit,))
session.msg('%s' %(exit.get_ansiname(fullname=True),))
if not target_obj.is_room():
if target_obj.is_exit():

View file

@ -39,7 +39,7 @@ def cmd_destroy(cdat):
if len(results) > 1:
session.msg("More than one match found (please narrow target):")
for result in results:
session.msg(" %s" % (result,))
session.msg(" %s" % (result.get_ansiname(),))
return
elif len(results) == 0:
session.msg("I don't see that here.")
@ -106,7 +106,7 @@ def cmd_description(cdat):
if len(results) > 1:
session.msg("More than one match found (please narrow target):")
for result in results:
session.msg(" %s" % (result,))
session.msg(" %s" % (result.get_ansiname(),))
return
elif len(results) == 0:
session.msg("I don't see that here.")
@ -141,7 +141,7 @@ def cmd_newpassword(cdat):
if len(results) > 1:
session.msg("More than one match found (please narrow target):")
for result in results:
session.msg(" %s" % (result,))
session.msg(" %s" % (result.get_ansiname(),))
elif len(results) == 0:
session.msg("I don't see that here.")
elif not pobject.controls_other(results[0]):
@ -206,7 +206,7 @@ def cmd_name(cdat):
if len(results) > 1:
session.msg("More than one match found (please narrow target):")
for result in results:
session.msg(" %s" % (result,))
session.msg(" %s" % (result.get_ansiname(),))
return
elif len(results) == 0:
session.msg("I don't see that here.")
@ -422,7 +422,7 @@ def cmd_unlink(cdat):
if len(results) > 1:
session.msg("More than one match found (please narrow target):")
for result in results:
session.msg(" %s" % (result,))
session.msg(" %s" % (result.get_ansiname(),))
return
elif len(results) == 0:
session.msg("I don't see that here.")
@ -491,7 +491,7 @@ def cmd_teleport(cdat):
if len(results) > 1:
session.msg("More than one match found (please narrow target):")
for result in results:
session.msg(" %s" % (result,))
session.msg(" %s" % (result.get_ansiname(),))
elif len(results) == 0:
session.msg("I don't see that here.")
return
@ -596,7 +596,7 @@ def cmd_find(cdat):
if len(results) > 0:
session.msg("Name matches for: %s" % (searchstring,))
for result in results:
session.msg(" %s" % (result,))
session.msg(" %s" % (result.get_ansiname(fullname=True),))
session.msg("%d matches returned." % (len(results),))
else:
session.msg("No name matches found for: %s" % (searchstring,))

Binary file not shown.

View file

@ -1,3 +1,3 @@
#!/bin/bash
export DJANGO_SETTINGS_MODULE="settings"
python2.5 server.py
python2.5 -m cProfile -o profiler.log -s time server.py