Added ev API support to @py command.

This commit is contained in:
Griatch 2012-03-25 18:36:23 +02:00
parent b2f45a7cf4
commit 07a17ac15e
2 changed files with 16 additions and 36 deletions

20
ev.py
View file

@ -2,9 +2,9 @@
Central API for Evennia MUD/MUX/MU* system.
This basically a set of shortcuts to the main modules in src/.
Import this from ./manage.py shell or set DJANGO_SETTINGS_MODULE manually for proper
functionality.
This basically a set of shortcuts to the main modules in src/. Import this
from your code or eplore it interactively from ./manage.py shell (or a normal
python shell if you set DJANGO_SETTINGS_MODULE manually).
1) You should import things explicitly from the root of this module - you can generally
not use dot-notation to import deeper. Hence, to access a default command, you can do
@ -24,13 +24,15 @@ functionality.
typeclasses (or lists of typeclasses), whereas the default django ones (filter etc)
return database objects. You can convert between the two easily via dbobj.typeclass and
typeclass.dbobj, but it's worth to remember this difference.
3) You -have- to use the methods of the "create" module to create new Typeclassed game
entities (Objects, Scripts or Players). Just initializing e.g. the Player class will
3) You -have- to use the create_* functions (shortcuts to src.utils.create) to create new
Typeclassed game entities (Objects, Scripts or Players). Just initializing e.g. the Player class will
-not- set up Typeclasses correctly and will lead to errors. Other types of database objects
can be created normally, but the "create" module offers convenient methods for those too.
4) The API accesses all relevant methods/classes, but might not always include all helper-methods
referenced from each such entity. To get to those, access the modules in src/ directly. You
can always do this anyway, if you do not want to go through this API.
can be created normally, but there are conveniant create_* functions for those too, making
some more error checking.
4) The API accesses all relevant and most-neeeded functions/classes from src/, but might not
always include all helper-functions referenced from each such entity. To get to those, access
the modules in src/ directly. You can always do this anyway, if you do not want to go through
this API.
"""

View file

@ -113,12 +113,7 @@ class CmdPy(MuxCommand):
Available variables in @py environment:
self, me : caller
here : caller.location
obj : dummy obj instance
script : dummy script instance
config : dummy conf instance
ObjectDB : ObjectDB class
ScriptDB : ScriptDB class
ServerConfig : ServerConfig class
ev : the evennia API
inherits_from(obj, parent) : check object inheritance
{rNote: In the wrong hands this command is a severe security risk.
@ -140,25 +135,14 @@ class CmdPy(MuxCommand):
string = "Usage: @py <code>"
caller.msg(string)
return
# create temporary test objects for playing with
script = create.create_script("src.scripts.scripts.DoNothing",
key='testscript')
obj = create.create_object("src.objects.objects.Object",
key='testobject')
conf = ServerConfig() # used to access conf values
# import useful checker
# import useful variables
import ev
available_vars = {'self':caller,
'me':caller,
'here':caller.location,
'obj':obj,
'script':script,
'config':conf,
'inherits_from':utils.inherits_from,
'ObjectDB':ObjectDB,
'ScriptDB':ScriptDB,
'ServerConfig':ServerConfig}
'ev':ev,
'inherits_from':utils.inherits_from}
caller.msg(">>> %s" % pycode)
try:
@ -174,12 +158,6 @@ class CmdPy(MuxCommand):
errlist = errlist[4:]
ret = "\n".join("<<< %s" % line for line in errlist if line)
caller.msg(ret)
obj.delete()
try:
script.delete()
except AssertionError: # this is a strange thing; the script looses its id somehow..?
pass
# helper function. Kept outside so it can be imported and run
# by other commands.