docstrings and typos in "\utils\" and "\scripts\"

This commit is contained in:
tajmone 2015-03-09 11:06:48 +01:00 committed by Griatch
parent e13a9b2749
commit 972b5cd2e2
5 changed files with 50 additions and 40 deletions

View file

@ -1,8 +1,8 @@
"""
The script handler makes sure to check through all stored scripts
to make sure they are still relevant.
An scripthandler is automatically added to all game objects. You
access it through the property 'scripts' on the game object.
A scripthandler is automatically added to all game objects. You
access it through the property `scripts` on the game object.
"""
from evennia.scripts.models import ScriptDB
@ -21,7 +21,7 @@ class ScriptHandler(object):
obj - a reference to the object this handler is attached to.
We retrieve all scripts attached to this object and check
if they are all peristent. If they are not, they are just
if they are all persistent. If they are not, they are just
cruft left over from a server shutdown.
"""
self.obj = obj
@ -49,7 +49,7 @@ class ScriptHandler(object):
def add(self, scriptclass, key=None, autostart=True):
"""
Add an script to this object.
Add a script to this object.
scriptclass - either a class object
inheriting from Script, an instantiated script object
@ -83,7 +83,7 @@ class ScriptHandler(object):
def get(self, scriptid):
"""
Return one or all scripts on this object matching scriptid. Will return
Return one or all scripts on this object matching `scriptid`. Will return
a list.
"""
return ScriptDB.objects.get_all_scripts_on_obj(self.obj, key=scriptid)

View file

@ -24,7 +24,7 @@ _SESSIONS = None
class ExtendedLoopingCall(LoopingCall):
"""
LoopingCall that can start at a delay different
than self.interval.
than `self.interval`.
"""
start_delay = None
callcount = 0
@ -63,8 +63,8 @@ class ExtendedLoopingCall(LoopingCall):
self()
else:
if start_delay is not None and start_delay >= 0:
# we set start_delay after the _reshedule call to make
# next_call_time() find it until next reshedule.
# we set `start_delay` after the `_reschedule` call to make
# next_call_time() find it until next reschedule.
self.interval = start_delay
self._reschedule()
self.interval = interval
@ -81,7 +81,7 @@ class ExtendedLoopingCall(LoopingCall):
def _reschedule(self):
"""
Handle call rescheduling including
nulling start_delay and stopping if
nulling `start_delay` and stopping if
number of repeats is reached.
"""
self.start_delay = None
@ -99,7 +99,7 @@ class ExtendedLoopingCall(LoopingCall):
def next_call_time(self):
"""
Return the time in seconds until the next call. This takes
start_delay into account.
`start_delay` into account.
"""
if self.running:
currentTime = self.clock.seconds()
@ -112,7 +112,7 @@ class ExtendedLoopingCall(LoopingCall):
class ScriptBase(ScriptDB):
"""
Base class for scripts. Don't inherit from this, inherit
from the class 'Script' instead.
from the class `Script` instead.
"""
__metaclass__ = TypeclassBase
objects = ScriptManager()
@ -193,7 +193,7 @@ class ScriptBase(ScriptDB):
def time_until_next_repeat(self):
"""
Returns the time in seconds until the script will be
run again. If this is not a stepping script, returns None.
run again. If this is not a stepping script, returns `None`.
This is not used in any way by the script's stepping
system; it's only here for the user to be able to
check in on their scripts and when they will next be run.
@ -207,7 +207,7 @@ class ScriptBase(ScriptDB):
return None
def remaining_repeats(self):
"Get the number of returning repeats. Returns None if unlimited repeats."
"Get the number of returning repeats. Returns `None` if unlimited repeats."
task = self.ndb._task
if task:
return max(0, self.db_repeats - task.callcount)
@ -280,7 +280,7 @@ class ScriptBase(ScriptDB):
def pause(self):
"""
This stops a running script and stores its active state.
It WILL NOT call that at_stop() hook.
It WILL NOT call that `at_stop()` hook.
"""
if not self.db._paused_time:
# only allow pause if not already paused
@ -293,7 +293,7 @@ class ScriptBase(ScriptDB):
def unpause(self):
"""
Restart a paused script. This WILL call the at_start() hook.
Restart a paused script. This WILL call the `at_start()` hook.
"""
if self.db._paused_time:
# only unpause if previously paused
@ -367,7 +367,7 @@ class DefaultScript(ScriptBase):
desc (string) - optional description of script, shown in listings
obj (Object) - optional object that this script is connected to
and acts on (set automatically
by obj.scripts.add())
by `obj.scripts.add()`)
interval (int) - how often script should run, in seconds.
<=0 turns off ticker
start_delay (bool) - if the script should start repeating right

View file

@ -11,23 +11,27 @@ server reloads and be started automaticall on boot.
Example:
```python
from evennia.scripts.tickerhandler import TICKER_HANDLER
# tick myobj every 15 seconds
TICKER_HANDLER.add(myobj, 15)
```
The handler will by default try to call a hook "at_tick()"
The handler will by default try to call a hook `at_tick()`
on the subscribing object. The hook's name can be changed
if the "hook_key" keyword is given to the add() method (only
if the `hook_key` keyword is given to the `add()` method (only
one such alternate name per interval though). The
handler will transparently set up and add new timers behind
the scenes to tick at given intervals, using a TickerPool.
To remove:
```python
TICKER_HANDLER.remove(myobj, 15)
```
The interval must be given since a single object can be subcribed
The interval must be given since a single object can be subscribed
to many different tickers at the same time.
@ -35,6 +39,7 @@ The TickerHandler's functionality can be overloaded by modifying the
Ticker class and then changing TickerPool and TickerHandler to use the
custom classes
```python
class MyTicker(Ticker):
# [doing custom stuff]
@ -42,10 +47,11 @@ class MyTickerPool(TickerPool):
ticker_class = MyTicker
class MyTickerHandler(TickerHandler):
ticker_pool_class = MyTickerPool
```
If one wants to duplicate TICKER_HANDLER's auto-saving feature in
a custom handler one can make a custom AT_STARTSTOP_MODULE entry to
call the handler's save() and restore() methods when the server reboots.
a custom handler one can make a custom `AT_STARTSTOP_MODULE` entry to
call the handler's `save()` and `restore()` methods when the server reboots.
"""
from twisted.internet.defer import inlineCallbacks
@ -68,15 +74,15 @@ Ticker was not added."""
class Ticker(object):
"""
Represents a repeatedly running task that calls
hooks repeatedly. Overload _callback to change the
hooks repeatedly. Overload `_callback` to change the
way it operates.
"""
@inlineCallbacks
def _callback(self):
"""
This will be called repeatedly every self.interval seconds.
self.subscriptions contain tuples of (obj, args, kwargs) for
This will be called repeatedly every `self.interval` seconds.
`self.subscriptions` contain tuples of (obj, args, kwargs) for
each subscribing object.
If overloading, this callback is expected to handle all