Make PEP8 cleanup of line spaces and character distances as well as indents

This commit is contained in:
Griatch 2017-08-19 23:16:36 +02:00
parent 7ff783fea1
commit b278337172
189 changed files with 2039 additions and 1583 deletions

View file

@ -46,10 +46,10 @@ class ScriptDBAdmin(admin.ModelAdmin):
fieldsets = (
(None, {
'fields': (('db_key', 'db_typeclass_path'), 'db_interval',
'db_repeats', 'db_start_delay', 'db_persistent',
'db_obj')}),
)
'fields': (('db_key', 'db_typeclass_path'), 'db_interval',
'db_repeats', 'db_start_delay', 'db_persistent',
'db_obj')}),
)
inlines = [ScriptTagInline, ScriptAttributeInline]
def save_model(self, request, obj, form, change):

View file

@ -34,6 +34,7 @@ class ScriptDBManager(TypedObjectManager):
copy_script
"""
def get_all_scripts_on_obj(self, obj, key=None):
"""
Find all Scripts related to a particular object.

View file

@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.db import models, migrations
def convert_defaults(apps, schema_editor):
ScriptDB = apps.get_model("scripts", "ScriptDB")
for script in ScriptDB.objects.filter(db_typeclass_path="src.scripts.scripts.Script"):
@ -12,6 +13,7 @@ def convert_defaults(apps, schema_editor):
script.db_typeclass_path = "evennia.utils.gametime.GameTime"
script.save()
class Migration(migrations.Migration):
dependencies = [
@ -19,5 +21,5 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(convert_defaults),
migrations.RunPython(convert_defaults),
]

View file

@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.db import models, migrations
def remove_manage_scripts(apps, schema_editor):
ScriptDB = apps.get_model("scripts", "ScriptDB")
for script in ScriptDB.objects.filter(db_typeclass_path__in=(u'evennia.scripts.scripts.CheckSessions',
@ -12,6 +13,7 @@ def remove_manage_scripts(apps, schema_editor):
u'evennia.utils.gametime.GameTime')):
script.delete()
class Migration(migrations.Migration):
dependencies = [

View file

@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.db import models, migrations
def remove_manage_scripts(apps, schema_editor):
ScriptDB = apps.get_model("scripts", "ScriptDB")
for script in ScriptDB.objects.filter(db_typeclass_path__in=(u'src.scripts.scripts.CheckSessions',
@ -12,6 +13,7 @@ def remove_manage_scripts(apps, schema_editor):
u'src.utils.gametime.GameTime')):
script.delete()
class Migration(migrations.Migration):
dependencies = [

View file

@ -71,7 +71,6 @@ class ScriptDB(TypedObject):
"""
#
# ScriptDB Database Model setup
#
@ -87,7 +86,7 @@ class ScriptDB(TypedObject):
db_obj = models.ForeignKey("objects.ObjectDB", null=True, blank=True, verbose_name='scripted object',
help_text='the object to store this script on, if not a global script.')
db_account = models.ForeignKey("accounts.AccountDB", null=True, blank=True, verbose_name="scripted account",
help_text='the account to store this script on (should not be set if db_obj is set)')
help_text='the account to store this script on (should not be set if db_obj is set)')
# how often to run Script (secs). -1 means there is no timer
db_interval = models.IntegerField('interval', default=-1, help_text='how often to repeat script, in seconds. -1 means off.')

View file

@ -23,11 +23,13 @@ _SA = object.__setattr__
_GA = object.__getattribute__
_DA = object.__delattr__
class MonitorHandler(object):
"""
This is a resource singleton that allows for registering
callbacks for when a field or Attribute is updated (saved).
"""
def __init__(self):
"""
Initialize the handler.
@ -149,7 +151,6 @@ class MonitorHandler(object):
else:
self.monitors[obj][fieldname][idstring] = (callback, persistent, kwargs)
def remove(self, obj, fieldname, idstring=""):
"""
Remove a monitor.

View file

@ -13,11 +13,13 @@ from evennia.utils import logger
from django.utils.translation import ugettext as _
class ScriptHandler(object):
"""
Implements the handler. This sits on each game object.
"""
def __init__(self, obj):
"""
Set up internal state.
@ -49,8 +51,8 @@ class ScriptHandler(object):
except Exception:
next_repeat = "?"
string += _("\n '%(key)s' (%(next_repeat)s/%(interval)s, %(repeats)s repeats): %(desc)s") % \
{"key": script.key, "next_repeat": next_repeat,
"interval": interval, "repeats": repeats, "desc": script.desc}
{"key": script.key, "next_repeat": next_repeat,
"interval": interval, "repeats": repeats, "desc": script.desc}
return string.strip()
def add(self, scriptclass, key=None, autostart=True):
@ -73,7 +75,7 @@ class ScriptHandler(object):
else:
# the normal - adding to an Object
script = create.create_script(scriptclass, key=key, obj=self.obj,
autostart=autostart)
autostart=autostart)
if not script:
logger.log_err("Script %s could not be created and/or started." % scriptclass)
return False

View file

@ -201,8 +201,8 @@ class DefaultScript(ScriptBase):
"""
cname = self.__class__.__name__
estring = _("Script %(key)s(#%(dbid)s) of type '%(cname)s': at_repeat() error '%(err)s'.") % \
{"key": self.key, "dbid": self.dbid, "cname": cname,
"err": e.getErrorMessage()}
{"key": self.key, "dbid": self.dbid, "cname": cname,
"err": e.getErrorMessage()}
try:
self.db_obj.msg(estring)
except Exception:
@ -596,6 +596,7 @@ class DoNothing(DefaultScript):
"""
A script that does nothing. Used as default fallback.
"""
def at_script_creation(self):
"""
Setup the script
@ -608,6 +609,7 @@ class Store(DefaultScript):
"""
Simple storage script
"""
def at_script_creation(self):
"""
Setup the script

View file

@ -11,6 +11,7 @@ from evennia.utils.dbserialize import dbserialize, dbunserialize
TASK_HANDLER = None
class TaskHandler(object):
"""
@ -71,9 +72,9 @@ class TaskHandler(object):
try:
dbserialize(callback)
except (TypeError, AttributeError):
raise ValueError("the specified callback {} cannot be pickled. " \
"It must be a top-level function in a module or an " \
"instance method.".format(callback))
raise ValueError("the specified callback {} cannot be pickled. "
"It must be a top-level function in a module or an "
"instance method.".format(callback))
else:
safe_callback = callback
@ -112,9 +113,9 @@ class TaskHandler(object):
try:
dbserialize(arg)
except (TypeError, AttributeError):
logger.log_err("The positional argument {} cannot be " \
"pickled and will not be present in the arguments " \
"fed to the callback {}".format(arg, callback))
logger.log_err("The positional argument {} cannot be "
"pickled and will not be present in the arguments "
"fed to the callback {}".format(arg, callback))
else:
safe_args.append(arg)
@ -122,9 +123,9 @@ class TaskHandler(object):
try:
dbserialize(value)
except (TypeError, AttributeError):
logger.log_err("The {} keyword argument {} cannot be " \
"pickled and will not be present in the arguments " \
"fed to the callback {}".format(key, value, callback))
logger.log_err("The {} keyword argument {} cannot be "
"pickled and will not be present in the arguments "
"fed to the callback {}".format(key, value, callback))
else:
safe_kwargs[key] = value
@ -185,4 +186,3 @@ class TaskHandler(object):
# Create the soft singleton
TASK_HANDLER = TaskHandler()

View file

@ -7,6 +7,7 @@ from evennia.scripts.scripts import DoNothing
class TestScriptDB(TestCase):
"Check the singleton/static ScriptDB object works correctly"
def setUp(self):
self.scr = create_script(DoNothing)

View file

@ -81,10 +81,11 @@ _SA = object.__setattr__
_ERROR_ADD_TICKER = \
"""TickerHandler: Tried to add an invalid ticker:
"""TickerHandler: Tried to add an invalid ticker:
{storekey}
Ticker was not added."""
class Ticker(object):
"""
Represents a repeatedly running task that calls
@ -145,7 +146,6 @@ class Ticker(object):
self._to_remove = []
self._to_add = []
def __init__(self, interval):
"""
Set up the ticker
@ -338,7 +338,7 @@ class TickerHandler(object):
outpath = "%s.%s" % (callback.__module__, callback.func_name)
outcallfunc = callback
else:
raise TypeError("%s is not a callable function or method." % callback)
raise TypeError("%s is not a callable function or method." % callback)
return outobj, outpath, outcallfunc
def _store_key(self, obj, path, interval, callfunc, idstring="", persistent=True):
@ -386,12 +386,12 @@ class TickerHandler(object):
if self.ticker_storage:
# get the current times so the tickers can be restarted with a delay later
start_delays = dict((interval, ticker.task.next_call_time())
for interval, ticker in self.ticker_pool.tickers.items())
for interval, ticker in self.ticker_pool.tickers.items())
# remove any subscriptions that lost its object in the interim
to_save = {store_key: (args, kwargs) for store_key, (args, kwargs) in self.ticker_storage.items()
if ((store_key[1] and ("_obj" in kwargs and kwargs["_obj"].pk) and
hasattr(kwargs["_obj"], store_key[1])) or # a valid method with existing obj
if ((store_key[1] and ("_obj" in kwargs and kwargs["_obj"].pk) and
hasattr(kwargs["_obj"], store_key[1])) or # a valid method with existing obj
store_key[2])} # a path given
# update the timers for the tickers
@ -491,12 +491,12 @@ class TickerHandler(object):
"""
if isinstance(callback, int):
raise RuntimeError("TICKER_HANDLER.add has changed: "
"the interval is now the first argument, callback the second.")
"the interval is now the first argument, callback the second.")
obj, path, callfunc = self._get_callback(callback)
store_key = self._store_key(obj, path, interval, callfunc, idstring, persistent)
kwargs["_obj"] = obj
kwargs["_callback"] = callfunc # either method-name or callable
kwargs["_callback"] = callfunc # either method-name or callable
self.ticker_storage[store_key] = (args, kwargs)
self.ticker_pool.add(store_key, *args, **kwargs)
self.save()
@ -515,7 +515,7 @@ class TickerHandler(object):
"""
if isinstance(callback, int):
raise RuntimeError("TICKER_HANDLER.remove has changed: "
"the interval is now the first argument, callback the second.")
"the interval is now the first argument, callback the second.")
obj, path, callfunc = self._get_callback(callback)
store_key = self._store_key(obj, path, interval, callfunc, idstring, persistent)
@ -539,8 +539,8 @@ class TickerHandler(object):
self.ticker_pool.stop(interval)
if interval:
self.ticker_storage = dict((store_key, store_key)
for store_key in self.ticker_storage
if store_key[1] != interval)
for store_key in self.ticker_storage
if store_key[1] != interval)
else:
self.ticker_storage = {}
self.save()
@ -562,13 +562,13 @@ class TickerHandler(object):
if interval is None:
# return dict of all, ordered by interval
return dict((interval, ticker.subscriptions)
for interval, ticker in self.ticker_pool.tickers.iteritems())
for interval, ticker in self.ticker_pool.tickers.iteritems())
else:
# get individual interval
ticker = self.ticker_pool.tickers.get(interval, None)
if ticker:
return {interval: ticker.subscriptions}
return None
return None
def all_display(self):
"""
@ -584,5 +584,6 @@ class TickerHandler(object):
store_keys.append((kwargs.get("_obj", None), callfunc, path, interval, idstring, persistent))
return store_keys
# main tickerhandler
TICKER_HANDLER = TickerHandler()