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