From 8700659097579140a256123fad69923f286c8170 Mon Sep 17 00:00:00 2001 From: BlauFeuer Date: Sun, 19 Mar 2017 11:52:09 -0400 Subject: [PATCH] Typo, whitespace, comments to PEP 8 comply --- evennia/utils/spawner.py | 63 +++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/evennia/utils/spawner.py b/evennia/utils/spawner.py index 1dd2361e5..a0d5f5601 100644 --- a/evennia/utils/spawner.py +++ b/evennia/utils/spawner.py @@ -82,9 +82,9 @@ many traits with a normal *goblin*. from __future__ import print_function import copy -#TODO -#sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) -#os.environ['DJANGO_SETTINGS_MODULE'] = 'game.settings' +# TODO +# sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +# os.environ['DJANGO_SETTINGS_MODULE'] = 'game.settings' from django.conf import settings from random import randint @@ -131,9 +131,10 @@ def _get_prototype(dic, prot, protparents): new_prot = _get_prototype(protparents.get(prototype, {}), prot, protparents) prot.update(new_prot) prot.update(dic) - prot.pop("prototype", None) # we don't need this anymore + prot.pop("prototype", None) # we don't need this anymore return prot + def _batch_create_object(*objparams): """ This is a cut-down version of the create_object() function, @@ -141,7 +142,7 @@ def _batch_create_object(*objparams): so make sure the spawned Typeclass works before using this! Args: - objsparams (any): Aach argument should be a tuple of arguments + objsparams (any): Each argument should be a tuple of arguments for the respective creation/add handlers in the following order: (create, permissions, locks, aliases, nattributes, attributes) @@ -153,8 +154,8 @@ def _batch_create_object(*objparams): # bulk create all objects in one go # unfortunately this doesn't work since bulk_create doesn't creates pks; - # the result are double objects at the next stage - #dbobjs = _ObjectDB.objects.bulk_create(dbobjs) + # the result are database objects at the next stage + # dbobjs = _ObjectDB.objects.bulk_create(dbobjs) dbobjs = [ObjectDB(**objparam[0]) for objparam in objparams] objs = [] @@ -167,7 +168,7 @@ def _batch_create_object(*objparams): "aliases": objparam[3], "nattributes": objparam[4], "attributes": objparam[5], - "tags":objparam[6]} + "tags": objparam[6]} # this triggers all hooks obj.save() # run eventual extra code @@ -201,9 +202,9 @@ def spawn(*prototypes, **kwargs): if not protmodules and hasattr(settings, "PROTOTYPE_MODULES"): protmodules = make_iter(settings.PROTOTYPE_MODULES) for prototype_module in protmodules: - protparents.update(dict((key, val) - for key, val in all_from_module(prototype_module).items() if isinstance(val, dict))) - #overload module's protparents with specifically given protparents + protparents.update(dict((key, val) for key, val in + all_from_module(prototype_module).items() if isinstance(val, dict))) + # overload module's protparents with specifically given protparents protparents.update(kwargs.get("prototype_parents", {})) for key, prototype in protparents.items(): _validate_prototype(key, prototype, protparents, []) @@ -223,10 +224,10 @@ def spawn(*prototypes, **kwargs): # extract the keyword args we need to create the object itself. If we get a callable, # call that to get the value (don't catch errors) create_kwargs = {} - keyval = prot.pop("key", "Spawned Object %06i" % randint(1,100000)) + keyval = prot.pop("key", "Spawned Object %06i" % randint(1, 100000)) create_kwargs["db_key"] = keyval() if callable(keyval) else keyval - locval = prot.pop("location", None) + locval = prot.pop("location", None) create_kwargs["db_location"] = locval() if callable(locval) else _handle_dbref(locval) homval = prot.pop("home", settings.DEFAULT_HOME) @@ -244,7 +245,7 @@ def spawn(*prototypes, **kwargs): lockval = prot.pop("locks", "") lock_string = lockval() if callable(lockval) else lockval aliasval = prot.pop("aliases", "") - alias_string = aliasval() if callable(aliasval) else aliasval + alias_string = aliasval() if callable(aliasval) else aliasval tagval = prot.pop("tags", "") tags = tagval() if callable(tagval) else tagval exval = prot.pop("exec", "") @@ -252,16 +253,16 @@ def spawn(*prototypes, **kwargs): # extract ndb assignments nattributes = dict((key.split("_", 1)[1], value() if callable(value) else value) - for key, value in prot.items() if key.startswith("ndb_")) + for key, value in prot.items() if key.startswith("ndb_")) # the rest are attributes attributes = dict((key, value() if callable(value) else value) - for key, value in prot.items() - if not (key in _CREATE_OBJECT_KWARGS or key.startswith("ndb_"))) + for key, value in prot.items() + if not (key in _CREATE_OBJECT_KWARGS or key.startswith("ndb_"))) # pack for call into _batch_create_object - objsparams.append( (create_kwargs, permission_string, lock_string, - alias_string, nattributes, attributes, tags, execs) ) + objsparams.append((create_kwargs, permission_string, lock_string, + alias_string, nattributes, attributes, tags, execs)) return _batch_create_object(*objsparams) @@ -271,33 +272,35 @@ if __name__ == "__main__": protparents = { "NOBODY": {}, - #"INFINITE" : { - # "prototype":"INFINITE" - #}, - "GOBLIN" : { + # "INFINITE" : { + # "prototype":"INFINITE" + # }, + "GOBLIN": { "key": "goblin grunt", - "health": lambda: randint(20,30), + "health": lambda: randint(20, 30), "resists": ["cold", "poison"], "attacks": ["fists"], "weaknesses": ["fire", "light"] }, - "GOBLIN_WIZARD" : { + "GOBLIN_WIZARD": { "prototype": "GOBLIN", "key": "goblin wizard", "spells": ["fire ball", "lighting bolt"] }, - "GOBLIN_ARCHER" : { + "GOBLIN_ARCHER": { "prototype": "GOBLIN", "key": "goblin archer", "attacks": ["short bow"] }, - "ARCHWIZARD" : { + "ARCHWIZARD": { "attacks": ["archwizard staff"], }, - "GOBLIN_ARCHWIZARD" : { + "GOBLIN_ARCHWIZARD": { "key": "goblin archwizard", - "prototype" : ("GOBLIN_WIZARD", "ARCHWIZARD") + "prototype": ("GOBLIN_WIZARD", "ARCHWIZARD") } } # test - print([o.key for o in spawn(protparents["GOBLIN"], protparents["GOBLIN_ARCHWIZARD"], prototype_parents=protparents)]) + print([o.key for o in spawn(protparents["GOBLIN"], + protparents["GOBLIN_ARCHWIZARD"], + prototype_parents=protparents)])