diff --git a/game/gamesrc/commands/default/cmdset_default.py b/game/gamesrc/commands/default/cmdset_default.py index 103aedb704..082fdd4dc2 100644 --- a/game/gamesrc/commands/default/cmdset_default.py +++ b/game/gamesrc/commands/default/cmdset_default.py @@ -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()) diff --git a/game/gamesrc/commands/default/objmanip.py b/game/gamesrc/commands/default/objmanip.py index 62c1039895..d5d9390a7a 100644 --- a/game/gamesrc/commands/default/objmanip.py +++ b/game/gamesrc/commands/default/objmanip.py @@ -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] - - 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] ") - 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)) diff --git a/game/gamesrc/commands/default/tests.py b/game/gamesrc/commands/default/tests.py index 0d885f9554..9b32f1a2a6 100644 --- a/game/gamesrc/commands/default/tests.py +++ b/game/gamesrc/commands/default/tests.py @@ -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] + + 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] ") + 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)) diff --git a/src/utils/debug.py b/src/utils/debug.py index 214d6e5160..37337a4a37 100644 --- a/src/utils/debug.py +++ b/src/utils/debug.py @@ -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()