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. Central API for Evennia MUD/MUX/MU* system.
This basically a set of shortcuts to the main modules in src/. This basically a set of shortcuts to the main modules in src/. Import this
Import this from ./manage.py shell or set DJANGO_SETTINGS_MODULE manually for proper from your code or eplore it interactively from ./manage.py shell (or a normal
functionality. python shell if you set DJANGO_SETTINGS_MODULE manually).
1) You should import things explicitly from the root of this module - you can generally 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 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) 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 return database objects. You can convert between the two easily via dbobj.typeclass and
typeclass.dbobj, but it's worth to remember this difference. 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 3) You -have- to use the create_* functions (shortcuts to src.utils.create) to create new
entities (Objects, Scripts or Players). Just initializing e.g. the Player class will 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 -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. can be created normally, but there are conveniant create_* functions for those too, making
4) The API accesses all relevant methods/classes, but might not always include all helper-methods some more error checking.
referenced from each such entity. To get to those, access the modules in src/ directly. You 4) The API accesses all relevant and most-neeeded functions/classes from src/, but might not
can always do this anyway, if you do not want to go through this API. 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: Available variables in @py environment:
self, me : caller self, me : caller
here : caller.location here : caller.location
obj : dummy obj instance ev : the evennia API
script : dummy script instance
config : dummy conf instance
ObjectDB : ObjectDB class
ScriptDB : ScriptDB class
ServerConfig : ServerConfig class
inherits_from(obj, parent) : check object inheritance inherits_from(obj, parent) : check object inheritance
{rNote: In the wrong hands this command is a severe security risk. {rNote: In the wrong hands this command is a severe security risk.
@ -140,25 +135,14 @@ class CmdPy(MuxCommand):
string = "Usage: @py <code>" string = "Usage: @py <code>"
caller.msg(string) caller.msg(string)
return 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, available_vars = {'self':caller,
'me':caller, 'me':caller,
'here':caller.location, 'here':caller.location,
'obj':obj, 'ev':ev,
'script':script, 'inherits_from':utils.inherits_from}
'config':conf,
'inherits_from':utils.inherits_from,
'ObjectDB':ObjectDB,
'ScriptDB':ScriptDB,
'ServerConfig':ServerConfig}
caller.msg(">>> %s" % pycode) caller.msg(">>> %s" % pycode)
try: try:
@ -174,12 +158,6 @@ class CmdPy(MuxCommand):
errlist = errlist[4:] errlist = errlist[4:]
ret = "\n".join("<<< %s" % line for line in errlist if line) ret = "\n".join("<<< %s" % line for line in errlist if line)
caller.msg(ret) 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 # helper function. Kept outside so it can be imported and run
# by other commands. # by other commands.