Removed deprecated Attribute methods from evennia distro. Removed MUX help files.

This commit is contained in:
Griatch 2013-08-25 16:41:18 +02:00
parent 9620867031
commit 8bd431b385
13 changed files with 47 additions and 65 deletions

View file

@ -97,7 +97,7 @@ _LOGGER = None
#------------------------------------------------------------ #------------------------------------------------------------
# specifically forbidden symbols # specifically forbidden symbols
_EV_UNALLOWED_SYMBOLS = ["attr", "set_attribute", "delete"] _EV_UNALLOWED_SYMBOLS = ["attr", "attributes", "delete"]
try: _EV_UNALLOWED_SYMBOLS.expand(settings.EVLANG_UNALLOWED_SYMBOLS) try: _EV_UNALLOWED_SYMBOLS.expand(settings.EVLANG_UNALLOWED_SYMBOLS)
except AttributeError: pass except AttributeError: pass
@ -285,7 +285,7 @@ class Evlang(object):
if scripts: if scripts:
self.evlang_scripts.update(scripts) self.evlang_scripts.update(scripts)
if self.obj: if self.obj:
self.evlang_scripts.update(obj.attr(storage_attr)) self.evlang_scripts.update(obj.attributes.get(storage_attr))
self.safe_context = _EV_SAFE_CONTEXT # set by default + settings self.safe_context = _EV_SAFE_CONTEXT # set by default + settings
if safe_context: if safe_context:
self.safe_context.update(safe_context) self.safe_context.update(safe_context)
@ -401,7 +401,7 @@ class Evlang(object):
self.evlang_scripts[scriptname] = (codestring, scripter) self.evlang_scripts[scriptname] = (codestring, scripter)
if self.obj: if self.obj:
# save to database # save to database
self.obj.attr(self.evlang_storage_attr, self.evlang_scripts) self.obj.attributes.add(self.evlang_storage_attr, self.evlang_scripts)
def delete(self, scriptname): def delete(self, scriptname):
""" """
@ -411,7 +411,7 @@ class Evlang(object):
del self.evlang_scripts[scriptname] del self.evlang_scripts[scriptname]
if self.obj: if self.obj:
# update change to database # update change to database
self.obj.attr(self.evlang_storage_attr, self.evlang_scripts) self.obj.attributes.add(self.evlang_storage_attr, self.evlang_scripts)
#---------------------------------------------------------------------- #----------------------------------------------------------------------

View file

@ -642,7 +642,7 @@ class CmdEditor(Command):
return target and str(target) or "" return target and str(target) or ""
def save_attr(): def save_attr():
"Save line buffer to given attribute name. This should return True if successful and also report its status." "Save line buffer to given attribute name. This should return True if successful and also report its status."
self.obj.set_attribute(self.attrname, self.editor.buffer) self.obj.attributes.add(self.attrname, self.editor.buffer)
self.caller.msg("Saved.") self.caller.msg("Saved.")
return True return True
def quit_hook(): def quit_hook():

View file

@ -808,7 +808,7 @@ class CmdGetWeapon(Command):
"Implement the command" "Implement the command"
rack_id = self.obj.db.rack_id rack_id = self.obj.db.rack_id
if self.caller.get_attribute(rack_id): if self.caller.attributes.get(rack_id):
# we don't allow a player to take more than one weapon from rack. # we don't allow a player to take more than one weapon from rack.
self.caller.msg("%s has no more to offer you." % self.obj.name) self.caller.msg("%s has no more to offer you." % self.obj.name)
else: else:
@ -826,7 +826,7 @@ class CmdGetWeapon(Command):
else: else:
self.caller.msg(ostring) self.caller.msg(ostring)
# tag the caller so they cannot keep taking objects from the rack. # tag the caller so they cannot keep taking objects from the rack.
self.caller.set_attribute(rack_id, True) self.caller.attributes.add(rack_id, True)
class CmdSetWeaponRack(CmdSet): class CmdSetWeaponRack(CmdSet):

View file

@ -281,10 +281,10 @@ class CmdCpAttr(ObjManipCommand):
if not from_obj or not to_objs: if not from_obj or not to_objs:
caller.msg("You have to supply both source object and target(s).") caller.msg("You have to supply both source object and target(s).")
return return
if not from_obj.has_attribute(from_obj_attrs[0]): if not from_obj.attributes.has(from_obj_attrs[0]):
caller.msg("%s doesn't have an attribute %s." % (from_obj_name, from_obj_attrs[0])) caller.msg("%s doesn't have an attribute %s." % (from_obj_name, from_obj_attrs[0]))
return return
srcvalue = from_obj.get_attribute(from_obj_attrs[0]) srcvalue = from_obj.attributes.get(from_obj_attrs[0])
#copy to all to_obj:ects #copy to all to_obj:ects
if "move" in self.switches: if "move" in self.switches:
@ -307,7 +307,7 @@ class CmdCpAttr(ObjManipCommand):
# if there are too few attributes given # if there are too few attributes given
# on the to_obj, we copy the original name instead. # on the to_obj, we copy the original name instead.
to_attr = from_attr to_attr = from_attr
to_obj.set_attribute(to_attr, srcvalue) to_obj.attributes.add(to_attr, srcvalue)
if "move" in self.switches and not (from_obj == to_obj and from_attr == to_attr): if "move" in self.switches and not (from_obj == to_obj and from_attr == to_attr):
from_obj.del_attribute(from_attr) from_obj.del_attribute(from_attr)
string += "\nMoved %s.%s -> %s.%s." % (from_obj.name, from_attr, string += "\nMoved %s.%s -> %s.%s." % (from_obj.name, from_attr,
@ -1228,8 +1228,8 @@ class CmdSetAttribute(ObjManipCommand):
if not attrs: if not attrs:
attrs = [attr.key for attr in obj.get_all_attributes()] attrs = [attr.key for attr in obj.get_all_attributes()]
for attr in attrs: for attr in attrs:
if obj.has_attribute(attr): if obj.attributes.has(attr):
string += "\nAttribute %s/%s = %s" % (obj.name, attr, obj.get_attribute(attr)) string += "\nAttribute %s/%s = %s" % (obj.name, attr, obj.attributes.get(attr))
else: else:
string += "\n%s has no attribute '%s'." % (obj.name, attr) string += "\n%s has no attribute '%s'." % (obj.name, attr)
# we view it without parsing markup. # we view it without parsing markup.
@ -1238,9 +1238,9 @@ class CmdSetAttribute(ObjManipCommand):
else: else:
# deleting the attribute(s) # deleting the attribute(s)
for attr in attrs: for attr in attrs:
if obj.has_attribute(attr): if obj.attributes.has(attr):
val = obj.get_attribute(attr) val = obj.attributes.has(attr)
obj.del_attribute(attr) obj.attributes.remove(attr)
string += "\nDeleted attribute '%s' (= %s) from %s." % (attr, val, obj.name) string += "\nDeleted attribute '%s' (= %s) from %s." % (attr, val, obj.name)
else: else:
string += "\n%s has no attribute '%s'." % (obj.name, attr) string += "\n%s has no attribute '%s'." % (obj.name, attr)
@ -1248,7 +1248,7 @@ class CmdSetAttribute(ObjManipCommand):
# setting attribute(s). Make sure to convert to real Python type before saving. # setting attribute(s). Make sure to convert to real Python type before saving.
for attr in attrs: for attr in attrs:
try: try:
obj.set_attribute(attr, self.convert_from_string(value)) obj.attributes.add(attr, self.convert_from_string(value))
string += "\nCreated attribute %s/%s = %s" % (obj.name, attr, value) string += "\nCreated attribute %s/%s = %s" % (obj.name, attr, value)
except SyntaxError: except SyntaxError:
# this means literal_eval tried to parse a faulty string # this means literal_eval tried to parse a faulty string
@ -1406,7 +1406,7 @@ class CmdWipe(ObjManipCommand):
string = "Wiped all attributes on %s." % obj.name string = "Wiped all attributes on %s." % obj.name
else: else:
for attrname in attrs: for attrname in attrs:
obj.attr(attrname, delete=True ) obj.attributes.remove(attrname)
string = "Wiped attributes %s on %s." string = "Wiped attributes %s on %s."
string = string % (",".join(attrs), obj.name) string = string % (",".join(attrs), obj.name)
caller.msg(string) caller.msg(string)
@ -1538,7 +1538,7 @@ class CmdExamine(ObjManipCommand):
""" """
if attrname: if attrname:
db_attr = [(attrname, obj.attr(attrname))] db_attr = [(attrname, obj.attributes.get(attrname))]
try: try:
ndb_attr = [(attrname, object.__getattribute__(obj.ndb, attrname))] ndb_attr = [(attrname, object.__getattribute__(obj.ndb, attrname))]
except Exception: except Exception:

View file

@ -622,16 +622,16 @@ class CmdQuell(MuxPlayerCommand):
player = self.caller player = self.caller
permstr = player.is_superuser and " (superuser)" or " (%s)" % (", ".join(player.permissions.all())) permstr = player.is_superuser and " (superuser)" or " (%s)" % (", ".join(player.permissions.all()))
if self.cmdstring == '@unquell': if self.cmdstring == '@unquell':
if not player.get_attribute('_quell'): if not player.attributes.get('_quell'):
self.msg("Already using normal Player permissions%s." % permstr) self.msg("Already using normal Player permissions%s." % permstr)
else: else:
player.del_attribute('_quell') player.attributes.remove('_quell')
self.msg("Player permissions%s restored." % permstr) self.msg("Player permissions%s restored." % permstr)
else: else:
if player.get_attribute('_quell'): if player.get('_quell'):
self.msg("Already quelling Player%s permissions." % permstr) self.msg("Already quelling Player%s permissions." % permstr)
return return
player.set_attribute('_quell', True) player.add('_quell', True)
self.msg("Quelling Player permissions%s. Use @unquell to get them back." % permstr) self.msg("Quelling Player permissions%s. Use @unquell to get them back." % permstr)
self._recache_locks(player) self._recache_locks(player)

File diff suppressed because one or more lines are too long

View file

@ -153,7 +153,7 @@ def perm(accessing_obj, accessed_obj, *args, **kwargs):
if utils.inherits_from(accessing_obj, "src.objects.objects.Object") and accessing_obj.player: if utils.inherits_from(accessing_obj, "src.objects.objects.Object") and accessing_obj.player:
player = accessing_obj.player player = accessing_obj.player
perms_player = [p.lower() for p in player.permissions.all()] perms_player = [p.lower() for p in player.permissions.all()]
is_quell = player.get_attribute("_quell") is_quell = player.attributes.get("_quell")
if perm in _PERMISSION_HIERARCHY: if perm in _PERMISSION_HIERARCHY:
# check hierarchy without allowing escalation obj->player # check hierarchy without allowing escalation obj->player
@ -306,11 +306,11 @@ def attr(accessing_obj, accessed_obj, *args, **kwargs):
return valcompare(str(getattr(accessing_obj, attrname)), value, compare) return valcompare(str(getattr(accessing_obj, attrname)), value, compare)
return bool(getattr(accessing_obj, attrname)) # will return Fail on False value etc return bool(getattr(accessing_obj, attrname)) # will return Fail on False value etc
# check attributes, if they exist # check attributes, if they exist
if (hasattr(accessing_obj, 'has_attribute') and accessing_obj.has_attribute(attrname)): if (hasattr(accessing_obj, 'attributes') and accessing_obj.attributes.has(attrname)):
if value: if value:
return (hasattr(accessing_obj, 'get_attribute') return (hasattr(accessing_obj, 'attributes')
and valcompare(accessing_obj.get_attribute(attrname), value, compare)) and valcompare(accessing_obj.attributes.get(attrname), value, compare))
return bool(accessing_obj.get_attribute(attrname)) # fails on False/None values return bool(accessing_obj.attributes.get(attrname)) # fails on False/None values
return False return False
def objattr(accessing_obj, accessed_obj, *args, **kwargs): def objattr(accessing_obj, accessed_obj, *args, **kwargs):
@ -435,7 +435,7 @@ def holds(accessing_obj, accessed_obj, *args, **kwargs):
elif len(args = 2): elif len(args = 2):
# command is holds(attrname, value) check if any held object has the given attribute and value # command is holds(attrname, value) check if any held object has the given attribute and value
for obj in contents: for obj in contents:
if obj.attr(args[0]) == args[1]: if obj.attributes.get(args[0]) == args[1]:
return True return True

View file

@ -366,7 +366,7 @@ class ObjectManager(TypedObjectManager):
# copy over all attributes from old to new. # copy over all attributes from old to new.
for attr in original_object.get_all_attributes(): for attr in original_object.get_all_attributes():
new_object.set_attribute(attr.key, attr.value) new_object.attributes.add(attr.key, attr.value)
# copy over all cmdsets, if any # copy over all cmdsets, if any
for icmdset, cmdset in enumerate(original_object.cmdset.all()): for icmdset, cmdset in enumerate(original_object.cmdset.all()):

View file

@ -447,7 +447,7 @@ class ObjectDB(TypedObject):
def __is_superuser_get(self): def __is_superuser_get(self):
"Check if user has a player, and if so, if it is a superuser." "Check if user has a player, and if so, if it is a superuser."
return (_GA(self, "db_player") and _GA(_GA(self, "db_player"), "is_superuser") return (_GA(self, "db_player") and _GA(_GA(self, "db_player"), "is_superuser")
and not _GA(_GA(self, "db_player"), "get_attribute")("_quell")) and not _GA(_GA(self, "db_player"), "attributes").get("_quell"))
is_superuser = property(__is_superuser_get) is_superuser = property(__is_superuser_get)
# contents # contents

View file

@ -255,7 +255,7 @@ class Player(TypeClass):
""" """
# set an (empty) attribute holding the characters this player has # set an (empty) attribute holding the characters this player has
lockstring = "attrread:perm(Admins);attredit:perm(Admins);attrcreate:perm(Admins)" lockstring = "attrread:perm(Admins);attredit:perm(Admins);attrcreate:perm(Admins)"
self.set_attribute("_playable_characters", [], lockstring=lockstring) self.attributes.add("_playable_characters", [], lockstring=lockstring)
def at_init(self): def at_init(self):
""" """

View file

@ -193,7 +193,7 @@ def post_attr_update(sender, **kwargs):
# access methods # access methods
def get_attr_cache(obj, attrname): def get_attr_cache(obj, attrname):
"Called by get_attribute" "Called by getting attribute"
hid = hashid(obj, "-%s" % attrname) hid = hashid(obj, "-%s" % attrname)
return hid and _ATTR_CACHE.get(hid, None) or None return hid and _ATTR_CACHE.get(hid, None) or None

View file

@ -72,8 +72,8 @@ def create_objects():
god_character.permissions.add("Immortals") god_character.permissions.add("Immortals")
god_character.save() god_character.save()
god_player.set_attribute("_first_login", True) god_player.attributes.add("_first_login", True)
god_player.set_attribute("_last_puppet", god_character) god_player.attributes.add("_last_puppet", god_character)
god_player.db._playable_characters.append(god_character) god_player.db._playable_characters.append(god_character)
# Limbo is the default "nowhere" starting room # Limbo is the default "nowhere" starting room
@ -138,17 +138,6 @@ def create_channels():
PlayerChannelConnection.objects.create_connection(goduser, ichan) PlayerChannelConnection.objects.create_connection(goduser, ichan)
PlayerChannelConnection.objects.create_connection(goduser, cchan) PlayerChannelConnection.objects.create_connection(goduser, cchan)
def import_MUX_help_files():
"""
Imports the MUX help files.
"""
print " Importing MUX help database (devel reference only) ..."
management.call_command('loaddata', '../src/help/mux_help_db.json', verbosity=0)
# categorize the MUX help files into its own category.
default_category = "MUX"
print " Moving imported help db to help category '%(default)s'." % {'default': default_category}
HelpEntry.objects.all_to_category(default_category)
def create_system_scripts(): def create_system_scripts():
""" """
Setup the system repeat scripts. They are automatically started Setup the system repeat scripts. They are automatically started
@ -266,16 +255,10 @@ def handle_setup(last_step):
create_system_scripts, create_system_scripts,
start_game_time, start_game_time,
create_admin_media_links, create_admin_media_links,
import_MUX_help_files,
at_initial_setup, at_initial_setup,
reset_server reset_server
] ]
if not settings.IMPORT_MUX_HELP:
# skip importing of the MUX helpfiles, they are
# not interesting except for developers.
del setup_queue[-3]
#print " Initial setup: %s steps." % (len(setup_queue)) #print " Initial setup: %s steps." % (len(setup_queue))
# step through queue, from last completed function # step through queue, from last completed function

View file

@ -54,28 +54,28 @@ class GameTime(Script):
self.interval = REAL_MIN # update every minute self.interval = REAL_MIN # update every minute
self.persistent = True self.persistent = True
self.start_delay = True self.start_delay = True
self.attr("game_time", 0.0) #IC time self.attributes.add("game_time", 0.0) #IC time
self.attr("run_time", 0.0) #OOC time self.attributes.add("run_time", 0.0) #OOC time
self.attr("up_time", 0.0) #OOC time self.attributes.add("up_time", 0.0) #OOC time
def at_repeat(self): def at_repeat(self):
""" """
Called every minute to update the timers. Called every minute to update the timers.
""" """
# We store values as floats to avoid drift over time # We store values as floats to avoid drift over time
game_time = float(self.attr("game_time")) game_time = float(self.attributes.get("game_time"))
run_time = float(self.attr("run_time")) run_time = float(self.attributes.get("run_time"))
up_time = float(self.attr("up_time")) up_time = float(self.attributes.get("up_time"))
self.attr("game_time", game_time + MIN) self.attributes.add("game_time", game_time + MIN)
self.attr("run_time", run_time + REAL_MIN) self.attributes.add("run_time", run_time + REAL_MIN)
self.attr("up_time", up_time + REAL_MIN) self.attributes.add("up_time", up_time + REAL_MIN)
def at_start(self): def at_start(self):
""" """
This is called once every server restart. This is called once every server restart.
We reset the up time. We reset the up time.
""" """
self.attr("up_time", 0.0) self.attributes.add("up_time", 0.0)
# Access routines # Access routines
@ -131,7 +131,7 @@ def gametime(format=False):
logger.log_trace("GameTime script not found.") logger.log_trace("GameTime script not found.")
return return
# we return this as an integer (second-precision is good enough) # we return this as an integer (second-precision is good enough)
game_time = int(script.attr("game_time")) game_time = int(script.attributes.get("game_time"))
if format: if format:
return gametime_format(game_time) return gametime_format(game_time)
return game_time return game_time
@ -146,7 +146,7 @@ def runtime(format=False):
logger.log_trace("GameTime script not found.") logger.log_trace("GameTime script not found.")
return return
# we return this as an integer (second-precision is good enough) # we return this as an integer (second-precision is good enough)
run_time = int(script.attr("run_time")) run_time = int(script.attributes.get("run_time"))
if format: if format:
return realtime_format(run_time) return realtime_format(run_time)
return run_time return run_time
@ -161,7 +161,7 @@ def uptime(format=False):
logger.log_trace("GameTime script not found.") logger.log_trace("GameTime script not found.")
return return
# we return this as an integer (second-precision is good enough) # we return this as an integer (second-precision is good enough)
up_time = int(script.attr("up_time")) up_time = int(script.attributes.get("up_time"))
if format: if format:
return realtime_format(up_time) return realtime_format(up_time)
return up_time return up_time