Some cleanup of ev.py.

This commit is contained in:
Griatch 2014-04-21 17:11:17 +02:00
parent 033552cd04
commit 5bf1c03d2a

91
ev.py
View file

@ -1,60 +1,31 @@
"""
Central API for the Evennia MUD/MUX/MU* creation system.
This is basically a set of shortcuts for accessing things in src/ with less
boiler plate. Import this from your code, use it with @py from in-game or
explore it interactively from a python shell.
This is a set of shortcuts for accessing common features in src/ with
less boiler-plate. Import this from your code, use it with @py from
in-game or explore it interactively from a python shell.
Notes:
0) Use ev.help(), ev.managers.help(), ev.default_cmds.help() and
syscmdkeys.help() to view the API structure and explore which
variables/methods are available.
1) You should import things explicitly from the root of this module - you
can not use ot-notation to import deeper. Hence, to access a default c
ommand, you can do
import ev
ev.default_cmds.CmdLook
or
from ev import default_cmds
default_cmds.CmdLook
But trying to import CmdLook directly with
from ev.default_cmds import CmdLook
will not work since default_cmds is a property on the "ev" module,
not a module of its own.
2) "managers" is a container object that contains shortcuts to initiated
versions of Evennia's django database managers (e.g. managers.objects
is an alias for ObjectDB.objects). These allow for exploring the database
in various ways. To use in code, do 'from ev import managers', then access
the managers on the managers object. Please note that the evennia-specific
methods inmanagers return 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) "syscmdkeys" is a container object holding the names of system commands.
Import with 'from ev import syscmdkeys', then access the variables on
the syscmdkeys object.
4) You -have- to use the create_* functions (shortcuts to src.utils.create)
to create new ypeclassed game entities (Objects, Scripts, Channels 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 there are conveniant create_*
functions for those too, making some more error checking.
5) "settings" links to Evennia's game/settings file. "settings_full" shows
all of django's available settings. Note that this is for viewing only -
you cannot *change* settings from here in a meaningful way but have to
update game/settings.py and restart the server.
6) 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.
0) Use ev.help, ev.managers.help, ev.default_cmds.help and
syscmdkeys.help to view the API structure and explore which
variables/methods are available.
1) This module holds variables, not modules in their own right. This
means you cannot use import dot-notation to import nested things via
this API.
2) "managers" is a container object that contains shortcuts to
initiated versions of Evennia's django database managers (e.g.
managers.objects is an alias for ObjectDB.objects). These allow for
exploring the database in various ways.
3) "syscmdkeys" is a container object holding the names of system
commands. the syscmdkeys object.
4) You -have- to use the create_* functions (shortcuts to
src.utils.create) to create new typeclassed game entities (Objects,
Scripts, Channels or Players).
5) "settings" links to Evennia's game/settings file. "settings_full"
shows all of django's available settings. Note that this is for
viewing only - you cannot *change* settings from here in a meaningful
way but have to update game/settings.py and restart the server.
"""
import sys
@ -143,7 +114,7 @@ from src.locks import lockfuncs
from src.scripts.scripts import Script
# comms
from src.comms.models import Msg, ChannelDB#, PlayerChannelConnection, ExternalChannelConnection
from src.comms.models import Msg, ChannelDB
from src.comms.comms import Channel
# objects
@ -179,7 +150,7 @@ def help(header=False):
return __doc__
else:
import ev
names = [var for var in ev.__dict__ if not var.startswith('_')]
names = [str(var) for var in ev.__dict__ if not var.startswith('_')]
return ", ".join(names)
@ -188,11 +159,12 @@ class _EvContainer(object):
Parent for other containers
"""
def help(self):
def _help(self):
"Returns list of contents"
names = [name for name in self.__class__.__dict__ if not name.startswith('_')]
names += [name for name in self.__dict__ if not name.startswith('_')]
return self.__doc__ + "-" * 60 + "\n" + ", ".join(names)
print self.__doc__ + "-" * 60 + "\n" + ", ".join(names)
help = property(_help)
class DBmanagers(_EvContainer):
@ -204,9 +176,8 @@ class DBmanagers(_EvContainer):
scripts - ScriptDB.objects
msgs - Msg.objects
channels - Channel.objects
connections - PlayerChannelConnection.objects
externalconnections - ExternalChannelConnection.objects
objects - ObjectDB.objects
serverconfigs = ServerConfig.objects
tags - Tags.objects
attributes - Attributes.objects
@ -214,7 +185,7 @@ class DBmanagers(_EvContainer):
from src.help.models import HelpEntry
from src.players.models import PlayerDB
from src.scripts.models import ScriptDB
from src.comms.models import Msg, ChannelDB#, PlayerChannelConnection, ExternalChannelConnection
from src.comms.models import Msg, ChannelDB
from src.objects.models import ObjectDB
from src.server.models import ServerConfig
from src.typeclasses.models import Tag, Attribute
@ -225,14 +196,12 @@ class DBmanagers(_EvContainer):
scripts = ScriptDB.objects
msgs = Msg.objects
channels = ChannelDB.objects
#connections = PlayerChannelConnection.objects
#externalconnections = ExternalChannelConnection.objects
objects = ObjectDB.objects
serverconfigs = ServerConfig.objects
attributes = Attribute.objects
tags = Tag.objects
# remove these so they are not visible as properties
del HelpEntry, PlayerDB, ScriptDB, Msg, ChannelDB#, PlayerChannelConnection,
del HelpEntry, PlayerDB, ScriptDB, Msg, ChannelDB
#del ExternalChannelConnection
del ObjectDB, ServerConfig, Tag, Attribute