I18n string cleanup and refactoring

This commit is contained in:
Griatch 2021-05-26 21:55:05 +02:00
parent 59dd0b007a
commit 7ff8cbb341
62 changed files with 890 additions and 738 deletions

View file

@ -62,22 +62,28 @@ class TaskHandlerTask:
return TASK_HANDLER.get_deferred(self.task_id)
def pause(self):
"""Pause the callback of a task.
To resume use TaskHandlerTask.unpause
"""
Pause the callback of a task.
To resume use `TaskHandlerTask.unpause`.
"""
d = self.deferred
if d:
d.pause()
def unpause(self):
"""Unpause a task, run the task if it has passed delay time."""
"""
Unpause a task, run the task if it has passed delay time.
"""
d = self.deferred
if d:
d.unpause()
@property
def paused(self):
"""A task attribute to check if the deferred instance of a task has been paused.
"""
A task attribute to check if the deferred instance of a task has been paused.
This exists to mock usage of a twisted deferred object.
@ -93,7 +99,8 @@ class TaskHandlerTask:
return None
def do_task(self):
"""Execute the task (call its callback).
"""
Execute the task (call its callback).
If calling before timedelay, cancel the deferred instance affliated to this task.
Remove the task from the dictionary of current tasks on a successful
callback.
@ -106,7 +113,8 @@ class TaskHandlerTask:
return TASK_HANDLER.do_task(self.task_id)
def call(self):
"""Call the callback of a task.
"""
Call the callback of a task.
Leave the task unaffected otherwise.
This does not use the task's deferred instance.
The only requirement is that the task exist in task handler.
@ -173,7 +181,8 @@ class TaskHandlerTask:
return None
def exists(self):
"""Check if a task exists.
"""
Check if a task exists.
Most task handler methods check for existence for you.
Returns:
@ -183,7 +192,8 @@ class TaskHandlerTask:
return TASK_HANDLER.exists(self.task_id)
def get_id(self):
""" Returns the global id for this task. For use with
"""
Returns the global id for this task. For use with
`evennia.scripts.taskhandler.TASK_HANDLER`.
Returns:
@ -215,7 +225,7 @@ class TaskHandler(object):
self.clock = reactor
# number of seconds before an uncalled canceled task is removed from TaskHandler
self.stale_timeout = 60
self._now = False # used in unit testing to manually set now time
self._now = False # used in unit testing to manually set now time
def load(self):
"""Load from the ServerConfig.
@ -271,7 +281,10 @@ class TaskHandler(object):
return True
def save(self):
"""Save the tasks in ServerConfig."""
"""
Save the tasks in ServerConfig.
"""
for task_id, (date, callback, args, kwargs, persistent, _) in self.tasks.items():
if task_id in self.to_save:
@ -286,14 +299,12 @@ class TaskHandler(object):
callback = (obj, name)
# Check if callback can be pickled. args and kwargs have been checked
safe_callback = None
self.to_save[task_id] = dbserialize((date, callback, args, kwargs))
ServerConfig.objects.conf("delayed_tasks", self.to_save)
def add(self, timedelay, callback, *args, **kwargs):
"""Add a new task.
"""
Add a new task.
If the persistent kwarg is truthy:
The callback, args and values for kwarg will be serialized. Type
@ -399,7 +410,8 @@ class TaskHandler(object):
return TaskHandlerTask(task_id)
def exists(self, task_id):
"""Check if a task exists.
"""
Check if a task exists.
Most task handler methods check for existence for you.
Args:
@ -415,7 +427,8 @@ class TaskHandler(object):
return False
def active(self, task_id):
"""Check if a task is active (has not been called yet).
"""
Check if a task is active (has not been called yet).
Args:
task_id (int): an existing task ID.
@ -433,7 +446,8 @@ class TaskHandler(object):
return False
def cancel(self, task_id):
"""Stop a task from automatically executing.
"""
Stop a task from automatically executing.
This will not remove the task.
Args:
@ -459,7 +473,8 @@ class TaskHandler(object):
return False
def remove(self, task_id):
"""Remove a task without executing it.
"""
Remove a task without executing it.
Deletes the instance of the task's deferred.
Args:
@ -485,8 +500,8 @@ class TaskHandler(object):
return True
def clear(self, save=True, cancel=True):
"""clear all tasks.
By default tasks are canceled and removed from the database also.
"""
Clear all tasks. By default tasks are canceled and removed from the database as well.
Args:
save=True (bool): Should changes to persistent tasks be saved to database.
@ -508,7 +523,8 @@ class TaskHandler(object):
return True
def call_task(self, task_id):
"""Call the callback of a task.
"""
Call the callback of a task.
Leave the task unaffected otherwise.
This does not use the task's deferred instance.
The only requirement is that the task exist in task handler.
@ -528,7 +544,8 @@ class TaskHandler(object):
return callback(*args, **kwargs)
def do_task(self, task_id):
"""Execute the task (call its callback).
"""
Execute the task (call its callback).
If calling before timedelay cancel the deferred instance affliated to this task.
Remove the task from the dictionary of current tasks on a successful
callback.
@ -573,7 +590,8 @@ class TaskHandler(object):
return None
def create_delays(self):
"""Create the delayed tasks for the persistent tasks.
"""
Create the delayed tasks for the persistent tasks.
This method should be automatically called when Evennia starts.
"""