Typo, whitespace, comments to PEP 8 comply

This commit is contained in:
BlauFeuer 2017-03-19 11:52:09 -04:00 committed by Griatch
parent 8b0232d610
commit 8700659097

View file

@ -82,9 +82,9 @@ many traits with a normal *goblin*.
from __future__ import print_function from __future__ import print_function
import copy import copy
#TODO # TODO
#sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) # sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
#os.environ['DJANGO_SETTINGS_MODULE'] = 'game.settings' # os.environ['DJANGO_SETTINGS_MODULE'] = 'game.settings'
from django.conf import settings from django.conf import settings
from random import randint from random import randint
@ -134,6 +134,7 @@ def _get_prototype(dic, prot, protparents):
prot.pop("prototype", None) # we don't need this anymore prot.pop("prototype", None) # we don't need this anymore
return prot return prot
def _batch_create_object(*objparams): def _batch_create_object(*objparams):
""" """
This is a cut-down version of the create_object() function, 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! so make sure the spawned Typeclass works before using this!
Args: 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 for the respective creation/add handlers in the following
order: (create, permissions, locks, aliases, nattributes, order: (create, permissions, locks, aliases, nattributes,
attributes) attributes)
@ -153,8 +154,8 @@ def _batch_create_object(*objparams):
# bulk create all objects in one go # bulk create all objects in one go
# unfortunately this doesn't work since bulk_create doesn't creates pks; # unfortunately this doesn't work since bulk_create doesn't creates pks;
# the result are double objects at the next stage # the result are database objects at the next stage
#dbobjs = _ObjectDB.objects.bulk_create(dbobjs) # dbobjs = _ObjectDB.objects.bulk_create(dbobjs)
dbobjs = [ObjectDB(**objparam[0]) for objparam in objparams] dbobjs = [ObjectDB(**objparam[0]) for objparam in objparams]
objs = [] objs = []
@ -167,7 +168,7 @@ def _batch_create_object(*objparams):
"aliases": objparam[3], "aliases": objparam[3],
"nattributes": objparam[4], "nattributes": objparam[4],
"attributes": objparam[5], "attributes": objparam[5],
"tags":objparam[6]} "tags": objparam[6]}
# this triggers all hooks # this triggers all hooks
obj.save() obj.save()
# run eventual extra code # run eventual extra code
@ -201,9 +202,9 @@ def spawn(*prototypes, **kwargs):
if not protmodules and hasattr(settings, "PROTOTYPE_MODULES"): if not protmodules and hasattr(settings, "PROTOTYPE_MODULES"):
protmodules = make_iter(settings.PROTOTYPE_MODULES) protmodules = make_iter(settings.PROTOTYPE_MODULES)
for prototype_module in protmodules: for prototype_module in protmodules:
protparents.update(dict((key, val) protparents.update(dict((key, val) for key, val in
for key, val in all_from_module(prototype_module).items() if isinstance(val, dict))) all_from_module(prototype_module).items() if isinstance(val, dict)))
#overload module's protparents with specifically given protparents # overload module's protparents with specifically given protparents
protparents.update(kwargs.get("prototype_parents", {})) protparents.update(kwargs.get("prototype_parents", {}))
for key, prototype in protparents.items(): for key, prototype in protparents.items():
_validate_prototype(key, prototype, protparents, []) _validate_prototype(key, prototype, protparents, [])
@ -223,7 +224,7 @@ def spawn(*prototypes, **kwargs):
# extract the keyword args we need to create the object itself. If we get a callable, # 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) # call that to get the value (don't catch errors)
create_kwargs = {} 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 create_kwargs["db_key"] = keyval() if callable(keyval) else keyval
locval = prot.pop("location", None) locval = prot.pop("location", None)
@ -260,8 +261,8 @@ def spawn(*prototypes, **kwargs):
if not (key in _CREATE_OBJECT_KWARGS or key.startswith("ndb_"))) if not (key in _CREATE_OBJECT_KWARGS or key.startswith("ndb_")))
# pack for call into _batch_create_object # pack for call into _batch_create_object
objsparams.append( (create_kwargs, permission_string, lock_string, objsparams.append((create_kwargs, permission_string, lock_string,
alias_string, nattributes, attributes, tags, execs) ) alias_string, nattributes, attributes, tags, execs))
return _batch_create_object(*objsparams) return _batch_create_object(*objsparams)
@ -271,33 +272,35 @@ if __name__ == "__main__":
protparents = { protparents = {
"NOBODY": {}, "NOBODY": {},
#"INFINITE" : { # "INFINITE" : {
# "prototype":"INFINITE" # "prototype":"INFINITE"
#}, # },
"GOBLIN" : { "GOBLIN": {
"key": "goblin grunt", "key": "goblin grunt",
"health": lambda: randint(20,30), "health": lambda: randint(20, 30),
"resists": ["cold", "poison"], "resists": ["cold", "poison"],
"attacks": ["fists"], "attacks": ["fists"],
"weaknesses": ["fire", "light"] "weaknesses": ["fire", "light"]
}, },
"GOBLIN_WIZARD" : { "GOBLIN_WIZARD": {
"prototype": "GOBLIN", "prototype": "GOBLIN",
"key": "goblin wizard", "key": "goblin wizard",
"spells": ["fire ball", "lighting bolt"] "spells": ["fire ball", "lighting bolt"]
}, },
"GOBLIN_ARCHER" : { "GOBLIN_ARCHER": {
"prototype": "GOBLIN", "prototype": "GOBLIN",
"key": "goblin archer", "key": "goblin archer",
"attacks": ["short bow"] "attacks": ["short bow"]
}, },
"ARCHWIZARD" : { "ARCHWIZARD": {
"attacks": ["archwizard staff"], "attacks": ["archwizard staff"],
}, },
"GOBLIN_ARCHWIZARD" : { "GOBLIN_ARCHWIZARD": {
"key": "goblin archwizard", "key": "goblin archwizard",
"prototype" : ("GOBLIN_WIZARD", "ARCHWIZARD") "prototype": ("GOBLIN_WIZARD", "ARCHWIZARD")
} }
} }
# test # 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)])