Fixed a bug in @debug (resolves issue107). Also moved @debug command to commands/default/tests.py instead.

This commit is contained in:
Griatch 2010-09-12 16:37:00 +00:00
parent af89dd1ef7
commit 27b7570aab
4 changed files with 73 additions and 71 deletions

View file

@ -74,7 +74,6 @@ class DefaultCmdSet(CmdSet):
self.add(objmanip.CmdDestroy())
self.add(objmanip.CmdExamine())
self.add(objmanip.CmdTypeclass())
self.add(objmanip.CmdDebug())
# Comm commands
self.add(comms.CmdAddCom())
@ -95,4 +94,4 @@ class DefaultCmdSet(CmdSet):
self.add(tests.CmdTestState())
self.add(tests.CmdTestPerms())
self.add(tests.TestCom())
self.add(tests.CmdDebug())

View file

@ -6,8 +6,6 @@ from src.permissions.permissions import has_perm, has_perm_string
from src.objects.models import ObjectDB, ObjAttribute
from game.gamesrc.commands.default.muxcommand import MuxCommand
from src.utils import create
from src.utils import utils
from src.utils import debug
class ObjManipCommand(MuxCommand):
"""
@ -1637,64 +1635,3 @@ class CmdTypeclass(MuxCommand):
string += "same-named attributes on the existing object."
caller.msg(string)
class CmdDebug(MuxCommand):
"""
Debug game entities
Usage:
@debug[/switch] <path to code>
Switches:
obj - debug an object
script - debug a script
Examples:
@debug/script game.gamesrc.scripts.myscript.MyScript
@debug/script myscript.MyScript
@debug/obj examples.red_button.RedButton
This command helps when debugging the codes of objects and scripts.
It creates the given object and runs tests on its hooks. You can
supply both full paths (starting from the evennia base directory),
otherwise the system will start from the defined root directory
for scripts and objects respectively (defined in settings file).
"""
key = "@debug"
permissions = "cmd:debug"
help_category = "Building"
def func(self):
"Running the debug"
if not self.args or not self.switches:
self.caller.msg("Usage: @debug[/obj][/script] <path>")
return
path = self.args
if 'obj' in self.switches or 'object' in self.switches:
# analyze path. If it starts at the evennia basedir,
# (i.e. starts with game or src) we let it be, otherwise we
# add a base path as defined in settings
if path and not (path.startswith('src.') or
path.startswith('game.')):
path = "%s.%s" % (settings.BASE_TYPECLASS_PATH,
path)
# create and debug the object
self.caller.msg(debug.debug_object(path, self.caller))
self.caller.msg(debug.debug_object_scripts(path, self.caller))
elif 'script' in self.switches:
# analyze path. If it starts at the evennia basedir,
# (i.e. starts with game or src) we let it be, otherwise we
# add a base path as defined in settings
if path and not (path.startswith('src.') or
path.startswith('game.')):
path = "%s.%s" % (settings.BASE_SCRIPT_PATH,
path)
self.caller.msg(debug.debug_syntax_script(path))

View file

@ -1,14 +1,16 @@
"""
This defines some test commands for use while testing the MUD.
Just remove these commands from the default state when they
are not needed anymore.
This defines some test commands for use while testing the MUD and its components.
"""
from django.conf import settings
from django.db import IntegrityError
from src.comms.models import Msg
from game.gamesrc.commands.default.muxcommand import MuxCommand
from src.permissions import permissions
from src.utils import create
from src.utils import debug
from game.gamesrc.commands.default.muxcommand import MuxCommand
# Test permissions
@ -188,3 +190,66 @@ class TestCom(MuxCommand):
caller.msg(string)
return
caller.msg("Usage: @testcom/create channel")
#TODO: make @debug more clever with arbitrary hooks?
class CmdDebug(MuxCommand):
"""
Debug game entities
Usage:
@debug[/switch] <path to code>
Switches:
obj - debug an object
script - debug a script
Examples:
@debug/script game.gamesrc.scripts.myscript.MyScript
@debug/script myscript.MyScript
@debug/obj examples.red_button.RedButton
This command helps when debugging the codes of objects and scripts.
It creates the given object and runs tests on its hooks. You can
supply both full paths (starting from the evennia base directory),
otherwise the system will start from the defined root directory
for scripts and objects respectively (defined in settings file).
"""
key = "@debug"
permissions = "cmd:debug"
help_category = "Building"
def func(self):
"Running the debug"
if not self.args or not self.switches:
self.caller.msg("Usage: @debug[/obj][/script] <path>")
return
path = self.args
if 'obj' in self.switches or 'object' in self.switches:
# analyze path. If it starts at the evennia basedir,
# (i.e. starts with game or src) we let it be, otherwise we
# add a base path as defined in settings
if path and not (path.startswith('src.') or
path.startswith('game.')):
path = "%s.%s" % (settings.BASE_TYPECLASS_PATH,
path)
# create and debug the object
self.caller.msg(debug.debug_object(path, self.caller))
self.caller.msg(debug.debug_object_scripts(path, self.caller))
elif 'script' in self.switches:
# analyze path. If it starts at the evennia basedir,
# (i.e. starts with game or src) we let it be, otherwise we
# add a base path as defined in settings
if path and not (path.startswith('src.') or
path.startswith('game.')):
path = "%s.%s" % (settings.BASE_SCRIPT_PATH,
path)
self.caller.msg(debug.debug_syntax_script(path))

View file

@ -31,7 +31,7 @@ def trace():
def debug_script(script_path, obj=None, auto_delete=True):
"""
This function takes a script database object (ScriptDB) tests
This function takes a script database object (ScriptDB) and tests
all its hooks for syntax errors. Note that no run-time errors
will be caught, only weird python syntax.
@ -226,7 +226,8 @@ def debug_object_scripts(obj_path, caller):
try:
string = "\n Testing scripts on {w%s{n ... " % obj_path
obj = create.create_object(obj_path)
obj.location = caller.location
obj.location = caller.location
obj = obj.dbobj
string += "{gOk{n."
except Exception:
string += trace()