mirror of
https://github.com/evennia/evennia.git
synced 2026-03-17 05:16:31 +01:00
ev-API cleanups. ev can now be imported also from a non-django initiated python interpreter (it initiates itself). Gave some more info text and made sure wrapped db_ methods correctly forward their doc strings for introspection.
This commit is contained in:
parent
9409f835bc
commit
da51cb063f
3 changed files with 42 additions and 15 deletions
47
ev.py
47
ev.py
|
|
@ -1,14 +1,16 @@
|
|||
"""
|
||||
|
||||
Central API for Evennia MUD/MUX/MU* system.
|
||||
Central API for the Evennia MUD/MUX/MU* creation system.
|
||||
|
||||
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
|
||||
from your code or explore 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
|
||||
the following:
|
||||
Notes:
|
||||
|
||||
1) You should import things explicitly from the root of this module - you can not use
|
||||
dot-notation to import deeper. Hence, to access a default command, you can do the
|
||||
following:
|
||||
|
||||
import ev
|
||||
ev.default_cmds.CmdLook
|
||||
|
|
@ -29,7 +31,10 @@ python shell if you set DJANGO_SETTINGS_MODULE manually).
|
|||
-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.
|
||||
4) The API accesses all relevant and most-neeeded functions/classes from src/, but might not
|
||||
4) "settings" links to Evennia's game/settings file. "settings_full" shows all of django's available
|
||||
settings. Note that you cannot change settings from here in a meaningful way, you need to update
|
||||
game/settings.py and restart the server.
|
||||
5) 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.
|
||||
|
|
@ -42,14 +47,30 @@ import sys, os
|
|||
# not yet initialized)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print \
|
||||
info = __doc__ + \
|
||||
"""
|
||||
This module gives access to Evennia's programming API.
|
||||
It should not be run on its own, but be imported and accessed as you develop your game.
|
||||
To start the server, see game/manage.py and game/evennia.py.
|
||||
More help can be found at http://www.evennia.com.
|
||||
| This module gives access to Evennia's programming API. It should
|
||||
| not be run on its own, but be imported and accessed as described
|
||||
| above.
|
||||
|
|
||||
| To start the Evennia server, see game/manage.py and game/evennia.py.
|
||||
| More help can be found at http://www.evennia.com.
|
||||
"""
|
||||
print info
|
||||
sys.exit()
|
||||
|
||||
# make sure settings is available, also if starting this API stand-alone
|
||||
# make settings available, and also the full django settings
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from django.core.management import setup_environ
|
||||
from game import settings
|
||||
setup_environ(settings)
|
||||
del setup_environ
|
||||
from django.conf import settings as settings_full
|
||||
|
||||
# set Evennia version in __version__ property
|
||||
|
||||
try:
|
||||
f = open(os.path.dirname(os.path.abspath(__file__)) + os.sep + "VERSION", 'r')
|
||||
__version__ = "Evennia %s-r%s" % (f.read().strip(), os.popen("hg id -i").read().strip())
|
||||
|
|
@ -59,9 +80,11 @@ except IOError:
|
|||
__version__ = "Evennia (unknown version)"
|
||||
del sys, os
|
||||
|
||||
#
|
||||
# Start Evennia API (easiest is to import this module interactively to explore it)
|
||||
#
|
||||
|
||||
README = "Evennia flat API. See the module header for usage information."
|
||||
README = __doc__
|
||||
|
||||
# help entries
|
||||
from src.help.models import HelpEntry
|
||||
|
|
|
|||
|
|
@ -10,9 +10,10 @@ character object, so you should customize that
|
|||
instead for most things).
|
||||
|
||||
"""
|
||||
from django.conf import settings
|
||||
from src.typeclasses.typeclass import TypeClass
|
||||
|
||||
from settings import CMDSET_OOC
|
||||
CMDSET_OOC = settings.CMDSET_OOC
|
||||
|
||||
class Player(TypeClass):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ This implements the common managers that are used by the
|
|||
abstract models in dbobjects.py (and which are thus shared by
|
||||
all Attributes and TypedObjects).
|
||||
"""
|
||||
from functools import update_wrapper
|
||||
from django.db import models
|
||||
from src.utils import idmapper
|
||||
from src.utils.utils import make_iter
|
||||
|
|
@ -39,9 +40,10 @@ def returns_typeclass_list(method):
|
|||
"""
|
||||
def func(self, *args, **kwargs):
|
||||
"decorator. Returns a list."
|
||||
self.__doc__ = method.__doc__
|
||||
matches = method(self, *args, **kwargs)
|
||||
return [(hasattr(dbobj, "typeclass") and dbobj.typeclass) or dbobj for dbobj in make_iter(matches)]
|
||||
return func
|
||||
return update_wrapper(func, method)
|
||||
|
||||
def returns_typeclass(method):
|
||||
"""
|
||||
|
|
@ -49,12 +51,13 @@ def returns_typeclass(method):
|
|||
"""
|
||||
def func(self, *args, **kwargs):
|
||||
"decorator. Returns result or None."
|
||||
self.__doc__ = method.__doc__
|
||||
rfunc = returns_typeclass_list(method)
|
||||
try:
|
||||
return rfunc(self, *args, **kwargs)[0]
|
||||
except IndexError:
|
||||
return None
|
||||
return func
|
||||
return update_wrapper(func, method)
|
||||
|
||||
|
||||
#class TypedObjectManager(idmap.CachingManager):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue