Ran black on sources

This commit is contained in:
Griatch 2022-09-18 23:58:32 +02:00
parent 6fa68745ba
commit 43378b4c41
30 changed files with 473 additions and 275 deletions

View file

@ -7,13 +7,13 @@ import evennia.accounts.manager
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('accounts', '0009_auto_20191025_0831'), ("accounts", "0009_auto_20191025_0831"),
] ]
operations = [ operations = [
migrations.AlterField( migrations.AlterField(
model_name='accountdb', model_name="accountdb",
name='first_name', name="first_name",
field=models.CharField(blank=True, max_length=150, verbose_name='first name'), field=models.CharField(blank=True, max_length=150, verbose_name="first name"),
), ),
] ]

View file

@ -41,7 +41,7 @@ PATH_REMAP_PREFIX = {
"auditing": "evennia.contrib.utils", "auditing": "evennia.contrib.utils",
"fieldfill": "evennia.contrib.utils", "fieldfill": "evennia.contrib.utils",
"random_string_generator": "evennia.contrib.utils", "random_string_generator": "evennia.contrib.utils",
"tree_select": "evennia.contrib.utils" "tree_select": "evennia.contrib.utils",
} }
@ -52,43 +52,45 @@ def convert_contrib_typeclass_paths(apps, schema_editor):
try: try:
package_path = obj.db_typeclass_path.split(".")[2:] package_path = obj.db_typeclass_path.split(".")[2:]
package_name = package_path[0] package_name = package_path[0]
if package_path[0] == 'security': if package_path[0] == "security":
# renamed package and changed path # renamed package and changed path
package_name = 'auditing' package_name = "auditing"
package_path.pop(0) # no longer security/auditing package_path.pop(0) # no longer security/auditing
if package_path[-1] == ".Clothing": if package_path[-1] == ".Clothing":
# renamed Clothing class to ContribClothing # renamed Clothing class to ContribClothing
package_path[-1] = "ContribClothing" package_path[-1] = "ContribClothing"
package_path = '.'.join(package_path) package_path = ".".join(package_path)
except IndexError: except IndexError:
print(f"obj.db_typeclass_path={obj.db_typeclass_path} could not be parsed " print(
"for converting to the new contrib location.") f"obj.db_typeclass_path={obj.db_typeclass_path} could not be parsed "
"for converting to the new contrib location."
)
continue continue
if package_name in PATH_REMAP_PREFIX: if package_name in PATH_REMAP_PREFIX:
obj.db_typeclass_path = f"{PATH_REMAP_PREFIX[package_name]}.{package_path}" obj.db_typeclass_path = f"{PATH_REMAP_PREFIX[package_name]}.{package_path}"
obj.save(update_fields=['db_typeclass_path']) obj.save(update_fields=["db_typeclass_path"])
for obj in AccountDB.objects.filter(db_cmdset_storage__startswith="evennia.contrib."): for obj in AccountDB.objects.filter(db_cmdset_storage__startswith="evennia.contrib."):
try: try:
package_path = obj.db_cmdset_storage.split(".")[2:] package_path = obj.db_cmdset_storage.split(".")[2:]
package_name = package_path[0] package_name = package_path[0]
package_path = '.'.join(package_path) package_path = ".".join(package_path)
except IndexError: except IndexError:
print(f"obj.db_cmdset_storage={obj.db_cmdset_storage} could not be parsed " print(
"for converting to the new contrib location.") f"obj.db_cmdset_storage={obj.db_cmdset_storage} could not be parsed "
"for converting to the new contrib location."
)
continue continue
if package_name in PATH_REMAP_PREFIX: if package_name in PATH_REMAP_PREFIX:
obj.db_cmdset_storage = f"{PATH_REMAP_PREFIX[package_name]}.{package_path}" obj.db_cmdset_storage = f"{PATH_REMAP_PREFIX[package_name]}.{package_path}"
obj.save(update_fields=['db_cmdset_storage']) obj.save(update_fields=["db_cmdset_storage"])
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('accounts', '0010_auto_20210520_2137'), ("accounts", "0010_auto_20210520_2137"),
] ]
operations = [ operations = [migrations.RunPython(convert_contrib_typeclass_paths, migrations.RunPython.noop)]
migrations.RunPython(convert_contrib_typeclass_paths, migrations.RunPython.noop)
]

View file

@ -63,7 +63,7 @@ def build_matches(raw_string, cmdset, include_prefixes=False):
try: try:
orig_string = raw_string orig_string = raw_string
if not include_prefixes and len(raw_string) > 1: if not include_prefixes and len(raw_string) > 1:
raw_string = raw_string.lstrip(_CMD_IGNORE_PREFIXES) raw_string = raw_string.lstrip(_CMD_IGNORE_PREFIXES)
search_string = raw_string.lower() search_string = raw_string.lower()
for cmd in cmdset: for cmd in cmdset:
cmdname, raw_cmdname = cmd.match(search_string, include_prefixes=include_prefixes) cmdname, raw_cmdname = cmd.match(search_string, include_prefixes=include_prefixes)

View file

@ -359,11 +359,15 @@ class Command(metaclass=CommandMeta):
""" """
if include_prefixes: if include_prefixes:
for cmd_key in self._keyaliases: for cmd_key in self._keyaliases:
if cmdname.startswith(cmd_key) and (not self.arg_regex or self.arg_regex.match(cmdname[len(cmd_key) :])): if cmdname.startswith(cmd_key) and (
not self.arg_regex or self.arg_regex.match(cmdname[len(cmd_key) :])
):
return cmd_key, cmd_key return cmd_key, cmd_key
else: else:
for k, v in self._noprefix_aliases.items(): for k, v in self._noprefix_aliases.items():
if cmdname.startswith(k) and (not self.arg_regex or self.arg_regex.match(cmdname[len(k) :])): if cmdname.startswith(k) and (
not self.arg_regex or self.arg_regex.match(cmdname[len(k) :])
):
return k, v return k, v
return None, None return None, None

View file

@ -1950,7 +1950,12 @@ class CmdSetAttribute(ObjManipCommand):
if self.rhs is None: if self.rhs is None:
# no = means we inspect the attribute(s) # no = means we inspect the attribute(s)
if not attrs: if not attrs:
attrs = [attr.key for attr in obj.attributes.get(category=None, return_obj=True, return_list=True)] attrs = [
attr.key
for attr in obj.attributes.get(
category=None, return_obj=True, return_list=True
)
]
for attr in attrs: for attr in attrs:
if not self.check_attr(obj, attr, category): if not self.check_attr(obj, attr, category):
continue continue
@ -2001,7 +2006,9 @@ class CmdSetAttribute(ObjManipCommand):
result.append(self.set_attr(obj, attr, value, category)) result.append(self.set_attr(obj, attr, value, category))
# check if anything was done # check if anything was done
if not result: if not result:
caller.msg("No valid attributes were found. Usage: set obj/attr[:category] = value. Use empty value to clear.") caller.msg(
"No valid attributes were found. Usage: set obj/attr[:category] = value. Use empty value to clear."
)
else: else:
# send feedback # send feedback
caller.msg("".join(result).strip("\n")) caller.msg("".join(result).strip("\n"))
@ -3732,7 +3739,7 @@ class CmdTeleport(COMMAND_DEFAULT_CLASS):
quiet="quiet" in self.switches, quiet="quiet" in self.switches,
emit_to_obj=caller, emit_to_obj=caller,
use_destination="intoexit" not in self.switches, use_destination="intoexit" not in self.switches,
move_type="teleport" move_type="teleport",
): ):
if obj_to_teleport == caller: if obj_to_teleport == caller:

View file

@ -1584,8 +1584,9 @@ class TestBuilding(BaseEvenniaCommandTest):
self.call( self.call(
building.CmdTeleport(), building.CmdTeleport(),
"Obj = Room2", "Obj = Room2",
"Obj(#{}) is leaving Room(#{}), heading for Room2(#{}).|Teleported Obj -> Room2." "Obj(#{}) is leaving Room(#{}), heading for Room2(#{}).|Teleported Obj -> Room2.".format(
.format(oid, rid, rid2), oid, rid, rid2
),
) )
self.call(building.CmdTeleport(), "NotFound = Room", "Could not find 'NotFound'.") self.call(building.CmdTeleport(), "NotFound = Room", "Could not find 'NotFound'.")
self.call( self.call(
@ -1701,8 +1702,7 @@ class TestBuilding(BaseEvenniaCommandTest):
self.call( self.call(
building.CmdSpawn(), building.CmdSpawn(),
"{'prototype_key':'GOBLIN', 'typeclass':'evennia.objects.objects.DefaultCharacter', " "{'prototype_key':'GOBLIN', 'typeclass':'evennia.objects.objects.DefaultCharacter', "
"'key':'goblin', 'location':'%s'}" "'key':'goblin', 'location':'%s'}" % spawnLoc.dbref,
% spawnLoc.dbref,
"Spawned goblin", "Spawned goblin",
) )
goblin = get_object(self, "goblin") goblin = get_object(self, "goblin")
@ -1750,8 +1750,7 @@ class TestBuilding(BaseEvenniaCommandTest):
self.call( self.call(
building.CmdSpawn(), building.CmdSpawn(),
"/noloc {'prototype_parent':'TESTBALL', 'key': 'Ball', 'prototype_key': 'foo'," "/noloc {'prototype_parent':'TESTBALL', 'key': 'Ball', 'prototype_key': 'foo',"
" 'location':'%s'}" " 'location':'%s'}" % spawnLoc.dbref,
% spawnLoc.dbref,
"Spawned Ball", "Spawned Ball",
) )
ball = get_object(self, "Ball") ball = get_object(self, "Ball")

View file

@ -13,6 +13,7 @@ def migrate_channel_aliases(apps, schema_editor):
""" """
from evennia.comms.models import ChannelDB from evennia.comms.models import ChannelDB
# ChannelDB = apps.get_model("comms", "ChannelDB") # ChannelDB = apps.get_model("comms", "ChannelDB")
for channel in ChannelDB.objects.all(): for channel in ChannelDB.objects.all():
@ -20,8 +21,12 @@ def migrate_channel_aliases(apps, schema_editor):
chan_key = channel.db_key.lower() chan_key = channel.db_key.lower()
channel_aliases = [chan_key] + [alias.lower() for alias in channel.aliases.all()] channel_aliases = [chan_key] + [alias.lower() for alias in channel.aliases.all()]
for subscriber in channel.subscriptions.all(): for subscriber in channel.subscriptions.all():
nicktuples = subscriber.nicks.get(category="channel", return_tuple=True, return_list=True) nicktuples = subscriber.nicks.get(
all_aliases = channel_aliases + [tup[2] for tup in nicktuples if tup[3].lower() == chan_key] category="channel", return_tuple=True, return_list=True
)
all_aliases = channel_aliases + [
tup[2] for tup in nicktuples if tup[3].lower() == chan_key
]
for key_or_alias in all_aliases: for key_or_alias in all_aliases:
channel.add_user_channel_alias(subscriber, key_or_alias) channel.add_user_channel_alias(subscriber, key_or_alias)
except Exception as err: except Exception as err:
@ -33,9 +38,7 @@ def migrate_channel_aliases(apps, schema_editor):
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('comms', '0018_auto_20191025_0831'), ("comms", "0018_auto_20191025_0831"),
] ]
operations = [ operations = [migrations.RunPython(migrate_channel_aliases)]
migrations.RunPython(migrate_channel_aliases)
]

View file

@ -6,21 +6,28 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('comms', '0019_auto_20210514_2032'), ("comms", "0019_auto_20210514_2032"),
] ]
operations = [ operations = [
migrations.RemoveField( migrations.RemoveField(
model_name='msg', model_name="msg",
name='db_hide_from_channels', name="db_hide_from_channels",
), ),
migrations.RemoveField( migrations.RemoveField(
model_name='msg', model_name="msg",
name='db_receivers_channels', name="db_receivers_channels",
), ),
migrations.AddField( migrations.AddField(
model_name='msg', model_name="msg",
name='db_receiver_external', name="db_receiver_external",
field=models.CharField(blank=True, db_index=True, help_text='identifier for single external receiver, for use with receivers without a database existence.', max_length=1024, null=True, verbose_name='external receiver'), field=models.CharField(
blank=True,
db_index=True,
help_text="identifier for single external receiver, for use with receivers without a database existence.",
max_length=1024,
null=True,
verbose_name="external receiver",
),
), ),
] ]

View file

@ -7,51 +7,101 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('scripts', '0014_auto_20210520_2137'), ("scripts", "0014_auto_20210520_2137"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('objects', '0011_auto_20191025_0831'), ("objects", "0011_auto_20191025_0831"),
('comms', '0020_auto_20210514_2210'), ("comms", "0020_auto_20210514_2210"),
] ]
operations = [ operations = [
migrations.AlterField( migrations.AlterField(
model_name='msg', model_name="msg",
name='db_receiver_external', name="db_receiver_external",
field=models.CharField(blank=True, db_index=True, help_text='Identifier for single external receiver, for use with recievers not represented by a regular database model.', max_length=1024, null=True, verbose_name='external receiver'), field=models.CharField(
blank=True,
db_index=True,
help_text="Identifier for single external receiver, for use with recievers not represented by a regular database model.",
max_length=1024,
null=True,
verbose_name="external receiver",
),
), ),
migrations.AlterField( migrations.AlterField(
model_name='msg', model_name="msg",
name='db_receivers_accounts', name="db_receivers_accounts",
field=models.ManyToManyField(blank=True, help_text='account receivers', related_name='receiver_account_set', to=settings.AUTH_USER_MODEL, verbose_name='Receivers (Accounts)'), field=models.ManyToManyField(
blank=True,
help_text="account receivers",
related_name="receiver_account_set",
to=settings.AUTH_USER_MODEL,
verbose_name="Receivers (Accounts)",
),
), ),
migrations.AlterField( migrations.AlterField(
model_name='msg', model_name="msg",
name='db_receivers_objects', name="db_receivers_objects",
field=models.ManyToManyField(blank=True, help_text='object receivers', related_name='receiver_object_set', to='objects.ObjectDB', verbose_name='Receivers (Objects)'), field=models.ManyToManyField(
blank=True,
help_text="object receivers",
related_name="receiver_object_set",
to="objects.ObjectDB",
verbose_name="Receivers (Objects)",
),
), ),
migrations.AlterField( migrations.AlterField(
model_name='msg', model_name="msg",
name='db_receivers_scripts', name="db_receivers_scripts",
field=models.ManyToManyField(blank=True, help_text='script_receivers', related_name='receiver_script_set', to='scripts.ScriptDB', verbose_name='Receivers (Scripts)'), field=models.ManyToManyField(
blank=True,
help_text="script_receivers",
related_name="receiver_script_set",
to="scripts.ScriptDB",
verbose_name="Receivers (Scripts)",
),
), ),
migrations.AlterField( migrations.AlterField(
model_name='msg', model_name="msg",
name='db_sender_accounts', name="db_sender_accounts",
field=models.ManyToManyField(blank=True, db_index=True, related_name='sender_account_set', to=settings.AUTH_USER_MODEL, verbose_name='Senders (Accounts)'), field=models.ManyToManyField(
blank=True,
db_index=True,
related_name="sender_account_set",
to=settings.AUTH_USER_MODEL,
verbose_name="Senders (Accounts)",
),
), ),
migrations.AlterField( migrations.AlterField(
model_name='msg', model_name="msg",
name='db_sender_external', name="db_sender_external",
field=models.CharField(blank=True, db_index=True, help_text='Identifier for single external sender, for use with senders not represented by a regular database model.', max_length=255, null=True, verbose_name='external sender'), field=models.CharField(
blank=True,
db_index=True,
help_text="Identifier for single external sender, for use with senders not represented by a regular database model.",
max_length=255,
null=True,
verbose_name="external sender",
),
), ),
migrations.AlterField( migrations.AlterField(
model_name='msg', model_name="msg",
name='db_sender_objects', name="db_sender_objects",
field=models.ManyToManyField(blank=True, db_index=True, related_name='sender_object_set', to='objects.ObjectDB', verbose_name='Senders (Objects)'), field=models.ManyToManyField(
blank=True,
db_index=True,
related_name="sender_object_set",
to="objects.ObjectDB",
verbose_name="Senders (Objects)",
),
), ),
migrations.AlterField( migrations.AlterField(
model_name='msg', model_name="msg",
name='db_sender_scripts', name="db_sender_scripts",
field=models.ManyToManyField(blank=True, db_index=True, related_name='sender_script_set', to='scripts.ScriptDB', verbose_name='Senders (Scripts)'), field=models.ManyToManyField(
blank=True,
db_index=True,
related_name="sender_script_set",
to="scripts.ScriptDB",
verbose_name="Senders (Scripts)",
),
), ),
] ]

View file

@ -234,7 +234,9 @@ class EventCharacter(DefaultCharacter):
if not string: if not string:
return return
super().announce_move_from(destination, msg=string, move_type=move_type, mapping=mapping, **kwargs) super().announce_move_from(
destination, msg=string, move_type=move_type, mapping=mapping, **kwargs
)
def announce_move_to(self, source_location, msg=None, move_type="move", mapping=None, **kwargs): def announce_move_to(self, source_location, msg=None, move_type="move", mapping=None, **kwargs):
""" """
@ -292,7 +294,9 @@ class EventCharacter(DefaultCharacter):
if not string: if not string:
return return
super().announce_move_to(source_location, msg=string, move_type=move_type, mapping=mapping, **kwargs) super().announce_move_to(
source_location, msg=string, move_type=move_type, mapping=mapping, **kwargs
)
def at_pre_move(self, destination, move_type="move", **kwargs): def at_pre_move(self, destination, move_type="move", **kwargs):
""" """

View file

@ -236,7 +236,9 @@ class CmdGiveUp(CmdEvscapeRoom):
# manually call move hooks # manually call move hooks
self.room.msg_room(self.caller, f"|r{self.caller.key} gave up and was whisked away!|n") self.room.msg_room(self.caller, f"|r{self.caller.key} gave up and was whisked away!|n")
self.room.at_object_leave(self.caller, self.caller.home) self.room.at_object_leave(self.caller, self.caller.home)
self.caller.move_to(self.caller.home, quiet=True, move_hooks=False, move_type="teleport") self.caller.move_to(
self.caller.home, quiet=True, move_hooks=False, move_type="teleport"
)
# back to menu # back to menu
run_evscaperoom_menu(self.caller) run_evscaperoom_menu(self.caller)

View file

@ -236,6 +236,7 @@ class RecogError(Exception):
class LanguageError(Exception): class LanguageError(Exception):
pass pass
def _get_case_ref(string): def _get_case_ref(string):
""" """
Helper function which parses capitalization and Helper function which parses capitalization and
@ -257,6 +258,7 @@ def _get_case_ref(string):
return case return case
# emoting mechanisms # emoting mechanisms
def parse_language(speaker, emote): def parse_language(speaker, emote):
""" """
@ -405,7 +407,7 @@ def parse_sdescs_and_recogs(sender, candidates, string, search_mode=False, case_
match_index = marker_match.start() match_index = marker_match.start()
# split the emote string at the reference marker, to process everything after it # split the emote string at the reference marker, to process everything after it
head = string[:match_index] head = string[:match_index]
tail = string[match_index + 1:] tail = string[match_index + 1 :]
if search_mode: if search_mode:
# match the candidates against the whole search string after the marker # match the candidates against the whole search string after the marker
@ -451,7 +453,7 @@ def parse_sdescs_and_recogs(sender, candidates, string, search_mode=False, case_
# save search string # save search string
matched_text = "".join(tail[1:iend]) matched_text = "".join(tail[1:iend])
# recombine remainder of emote back into a string # recombine remainder of emote back into a string
tail = "".join(tail[iend + 1:]) tail = "".join(tail[iend + 1 :])
nmatches = len(bestmatches) nmatches = len(bestmatches)
@ -1275,19 +1277,19 @@ class ContribRPObject(DefaultObject):
self.sdesc.add("Something") self.sdesc.add("Something")
def search( def search(
self, self,
searchdata, searchdata,
global_search=False, global_search=False,
use_nicks=True, use_nicks=True,
typeclass=None, typeclass=None,
location=None, location=None,
attribute_name=None, attribute_name=None,
quiet=False, quiet=False,
exact=False, exact=False,
candidates=None, candidates=None,
nofound_string=None, nofound_string=None,
multimatch_string=None, multimatch_string=None,
use_dbref=None, use_dbref=None,
): ):
""" """
Returns an Object matching a search string/condition, taking Returns an Object matching a search string/condition, taking
@ -1371,10 +1373,10 @@ class ContribRPObject(DefaultObject):
) )
if global_search or ( if global_search or (
is_string is_string
and searchdata.startswith("#") and searchdata.startswith("#")
and len(searchdata) > 1 and len(searchdata) > 1
and searchdata[1:].isdigit() and searchdata[1:].isdigit()
): ):
# only allow exact matching if searching the entire database # only allow exact matching if searching the entire database
# or unique #dbrefs # or unique #dbrefs

View file

@ -151,7 +151,13 @@ class TestRPSystem(BaseEvenniaTest):
id2 = f"#{self.receiver2.id}" id2 = f"#{self.receiver2.id}"
candidates = (self.receiver1, self.receiver2) candidates = (self.receiver1, self.receiver2)
result = ( result = (
'With a flair, {'+id0+'} looks at {'+id1+'} and {'+id2+'}. She says "This is a test."', "With a flair, {"
+ id0
+ "} looks at {"
+ id1
+ "} and {"
+ id2
+ '}. She says "This is a test."',
{ {
id2: self.receiver2, id2: self.receiver2,
id1: self.receiver1, id1: self.receiver1,
@ -178,7 +184,7 @@ class TestRPSystem(BaseEvenniaTest):
id2 = f"#{self.receiver2.id}" id2 = f"#{self.receiver2.id}"
candidates = (self.receiver1, self.receiver2) candidates = (self.receiver1, self.receiver2)
result = ( result = (
"{"+id0+"} frowns at {"+id1+"} for trying to steal {"+id0+"}'s test.", "{" + id0 + "} frowns at {" + id1 + "} for trying to steal {" + id0 + "}'s test.",
{ {
id1: self.receiver1, id1: self.receiver1,
id0: speaker, id0: speaker,

View file

@ -332,11 +332,9 @@ class EvAdventureRollEngine:
setattr(character, abi, current_abi) setattr(character, abi, current_abi)
character.msg( character.msg(
"~" * 78 "~" * 78 + "\n|yYou survive your brush with death, "
+ "\n|yYou survive your brush with death, "
f"but are |r{result.upper()}|y and permanently |rlose {loss} {abi}|y.|n\n" f"but are |r{result.upper()}|y and permanently |rlose {loss} {abi}|y.|n\n"
f"|GYou recover |g{new_hp}|G health|.\n" f"|GYou recover |g{new_hp}|G health|.\n" + "~" * 78
+ "~" * 78
) )

View file

@ -76,48 +76,121 @@ from evennia.utils.utils import is_iter
# Load name data from Behind the Name lists # Load name data from Behind the Name lists
dirpath = path.dirname(path.abspath(__file__)) dirpath = path.dirname(path.abspath(__file__))
_FIRSTNAME_LIST = [] _FIRSTNAME_LIST = []
with open(path.join(dirpath, "btn_givennames.txt"),'r', encoding='utf-8') as file: with open(path.join(dirpath, "btn_givennames.txt"), "r", encoding="utf-8") as file:
_FIRSTNAME_LIST = [ line.strip().rsplit(" ") for line in file if line and not line.startswith("#") ] _FIRSTNAME_LIST = [
line.strip().rsplit(" ") for line in file if line and not line.startswith("#")
]
_SURNAME_LIST = [] _SURNAME_LIST = []
with open(path.join(dirpath, "btn_surnames.txt"),'r', encoding='utf-8') as file: with open(path.join(dirpath, "btn_surnames.txt"), "r", encoding="utf-8") as file:
_SURNAME_LIST = [ line.strip() for line in file if line and not line.startswith("#") ] _SURNAME_LIST = [line.strip() for line in file if line and not line.startswith("#")]
_REQUIRED_KEYS = { "syllable", "consonants", "vowels", "length" } _REQUIRED_KEYS = {"syllable", "consonants", "vowels", "length"}
# Define phoneme structure for built-in fantasy name generators. # Define phoneme structure for built-in fantasy name generators.
_FANTASY_NAME_STRUCTURES = { _FANTASY_NAME_STRUCTURES = {
"harsh": { "harsh": {
"syllable": "CV(C)", "syllable": "CV(C)",
"consonants": [ "k", "k", "k", "z", "zh", "g", "v", "t", "th", "w", "n", "d", "d", ], "consonants": [
"start": ["dh", "kh", "kh", "kh", "vh", ], "k",
"end": ["n", "x", ], "k",
"vowels": [ "o", "o", "o", "a", "y", "u", "u", "u", "ä", "ö", "e", "i", "i", ], "k",
"length": (1,3), "z",
"zh",
"g",
"v",
"t",
"th",
"w",
"n",
"d",
"d",
],
"start": [
"dh",
"kh",
"kh",
"kh",
"vh",
],
"end": [
"n",
"x",
],
"vowels": [
"o",
"o",
"o",
"a",
"y",
"u",
"u",
"u",
"ä",
"ö",
"e",
"i",
"i",
],
"length": (1, 3),
}, },
"fluid": { "fluid": {
"syllable": "V(C)", "syllable": "V(C)",
"consonants": [ 'r','r','l','l','l','l','s','s','s','sh','m','n','n','f','v','w','th' ], "consonants": [
"start": [], "r",
"end": [], "r",
"vowels": [ "a","a","a","a","a","e","i","i","i","y","u","o", ], "l",
"length": (3,5), "l",
"l",
"l",
"s",
"s",
"s",
"sh",
"m",
"n",
"n",
"f",
"v",
"w",
"th",
],
"start": [],
"end": [],
"vowels": [
"a",
"a",
"a",
"a",
"a",
"e",
"i",
"i",
"i",
"y",
"u",
"o",
],
"length": (3, 5),
}, },
"alien": { "alien": {
"syllable": "C(C(V))(')(C)", "syllable": "C(C(V))(')(C)",
"consonants": [ 'q','q','x','z','v','w','k','h','b' ], "consonants": ["q", "q", "x", "z", "v", "w", "k", "h", "b"],
"start": ['x',], "start": [
"end": [], "x",
"vowels": [ 'y','w','o','y' ], ],
"length": (1,5), "end": [],
"vowels": ["y", "w", "o", "y"],
"length": (1, 5),
}, },
} }
_RE_DOUBLES = re.compile(r'(\w)\1{2,}') _RE_DOUBLES = re.compile(r"(\w)\1{2,}")
# Load in optional settings # Load in optional settings
custom_first_names = settings.NAMEGEN_FIRST_NAMES if hasattr(settings, "NAMEGEN_FIRST_NAMES") else [] custom_first_names = (
settings.NAMEGEN_FIRST_NAMES if hasattr(settings, "NAMEGEN_FIRST_NAMES") else []
)
custom_last_names = settings.NAMEGEN_LAST_NAMES if hasattr(settings, "NAMEGEN_LAST_NAMES") else [] custom_last_names = settings.NAMEGEN_LAST_NAMES if hasattr(settings, "NAMEGEN_LAST_NAMES") else []
if hasattr(settings, "NAMEGEN_FANTASY_RULES"): if hasattr(settings, "NAMEGEN_FANTASY_RULES"):
@ -132,7 +205,6 @@ else:
_SURNAME_LIST += custom_last_names _SURNAME_LIST += custom_last_names
def fantasy_name(num=1, style="harsh", return_list=False): def fantasy_name(num=1, style="harsh", return_list=False):
""" """
Generate made-up names in one of a number of "styles". Generate made-up names in one of a number of "styles".
@ -146,7 +218,9 @@ def fantasy_name(num=1, style="harsh", return_list=False):
def _validate(style_name): def _validate(style_name):
if style_name not in _FANTASY_NAME_STRUCTURES: if style_name not in _FANTASY_NAME_STRUCTURES:
raise ValueError(f"Invalid style name: '{style_name}'. Available style names: {' '.join(_FANTASY_NAME_STRUCTURES.keys())}") raise ValueError(
f"Invalid style name: '{style_name}'. Available style names: {' '.join(_FANTASY_NAME_STRUCTURES.keys())}"
)
style_dict = _FANTASY_NAME_STRUCTURES[style_name] style_dict = _FANTASY_NAME_STRUCTURES[style_name]
if type(style_dict) is not dict: if type(style_dict) is not dict:
@ -155,13 +229,17 @@ def fantasy_name(num=1, style="harsh", return_list=False):
keys = set(style_dict.keys()) keys = set(style_dict.keys())
missing_keys = _REQUIRED_KEYS - keys missing_keys = _REQUIRED_KEYS - keys
if len(missing_keys): if len(missing_keys):
raise KeyError(f"Style dictionary {style_name} is missing required keys: {' '.join(missing_keys)}") raise KeyError(
f"Style dictionary {style_name} is missing required keys: {' '.join(missing_keys)}"
)
if not (type(style_dict['consonants']) is list and type(style_dict['vowels']) is list): if not (type(style_dict["consonants"]) is list and type(style_dict["vowels"]) is list):
raise TypeError(f"'consonants' and 'vowels' for style {style_name} must be lists.") raise TypeError(f"'consonants' and 'vowels' for style {style_name} must be lists.")
if not (is_iter(style_dict['length']) and len(style_dict['length']) == 2): if not (is_iter(style_dict["length"]) and len(style_dict["length"]) == 2):
raise ValueError(f"'length' key for {style_name} must have a minimum and maximum number of syllables.") raise ValueError(
f"'length' key for {style_name} must have a minimum and maximum number of syllables."
)
return style_dict return style_dict
@ -178,9 +256,9 @@ def fantasy_name(num=1, style="harsh", return_list=False):
for key in style_dict["syllable"]: for key in style_dict["syllable"]:
# parentheses mean optional - allow nested parens # parentheses mean optional - allow nested parens
if key == "(": if key == "(":
weight = weight/2 weight = weight / 2
elif key == ")": elif key == ")":
weight = weight*2 weight = weight * 2
else: else:
if key == "C": if key == "C":
sound_type = "consonants" sound_type = "consonants"
@ -189,21 +267,21 @@ def fantasy_name(num=1, style="harsh", return_list=False):
else: else:
sound_type = key sound_type = key
# append the sound type and weight # append the sound type and weight
syllable.append( (sound_type, int(weight)) ) syllable.append((sound_type, int(weight)))
name_list = [] name_list = []
# time to generate a name! # time to generate a name!
for n in range(num): for n in range(num):
# build a list of syllables # build a list of syllables
length = random.randint(*style_dict['length']) length = random.randint(*style_dict["length"])
name = "" name = ""
for i in range(length): for i in range(length):
# build the syllable itself # build the syllable itself
syll = "" syll = ""
for sound, weight in syllable: for sound, weight in syllable:
# random chance to skip this key; lower weights mean less likely # random chance to skip this key; lower weights mean less likely
if random.randint(0,8) > weight: if random.randint(0, 8) > weight:
continue continue
if sound not in style_dict: if sound not in style_dict:
@ -217,17 +295,17 @@ def fantasy_name(num=1, style="harsh", return_list=False):
if sound == "consonants": if sound == "consonants":
# if it's a starting consonant, add starting-sounds to the options # if it's a starting consonant, add starting-sounds to the options
if not len(syll): if not len(syll):
choices += style_dict.get('start',[]) choices += style_dict.get("start", [])
# if it's an ending consonant, add ending-sounds to the options # if it's an ending consonant, add ending-sounds to the options
elif i+1 == length: elif i + 1 == length:
choices += style_dict.get('end',[]) choices += style_dict.get("end", [])
syll += random.choice(choices) syll += random.choice(choices)
name += syll name += syll
# condense repeating letters down to a maximum of 2 # condense repeating letters down to a maximum of 2
name = _RE_DOUBLES.sub(lambda m: m.group(1)*2, name) name = _RE_DOUBLES.sub(lambda m: m.group(1) * 2, name)
# capitalize the first letter # capitalize the first letter
name = name[0].upper() + name[1:] if len(name) > 1 else name.upper() name = name[0].upper() + name[1:] if len(name) > 1 else name.upper()
name_list.append(name) name_list.append(name)
@ -236,7 +314,12 @@ def fantasy_name(num=1, style="harsh", return_list=False):
return name_list[0] return name_list[0]
return name_list return name_list
def first_name(num=1, gender=None, return_list=False, ):
def first_name(
num=1,
gender=None,
return_list=False,
):
""" """
Generate first names, also known as personal names. Generate first names, also known as personal names.
@ -254,14 +337,18 @@ def first_name(num=1, gender=None, return_list=False, ):
if gender: if gender:
# filter the options by gender # filter the options by gender
name_options = [ name_data[0] for name_data in _FIRSTNAME_LIST if all([gender_key in gender for gender_key in name_data[1]])] name_options = [
name_data[0]
for name_data in _FIRSTNAME_LIST
if all([gender_key in gender for gender_key in name_data[1]])
]
if not len(name_options): if not len(name_options):
raise ValueError(f"Invalid gender '{gender}'.") raise ValueError(f"Invalid gender '{gender}'.")
else: else:
name_options = [ name_data[0] for name_data in _FIRSTNAME_LIST ] name_options = [name_data[0] for name_data in _FIRSTNAME_LIST]
# take a random selection of `num` names, without repeats # take a random selection of `num` names, without repeats
results = random.sample(name_options,num) results = random.sample(name_options, num)
if len(results) == 1 and not return_list: if len(results) == 1 and not return_list:
# return single value as a string # return single value as a string
@ -285,7 +372,7 @@ def last_name(num=1, return_list=False):
raise ValueError("Number of names to generate must be positive.") raise ValueError("Number of names to generate must be positive.")
# take a random selection of `num` names, without repeats # take a random selection of `num` names, without repeats
results = random.sample(_SURNAME_LIST,num) results = random.sample(_SURNAME_LIST, num)
if len(results) == 1 and not return_list: if len(results) == 1 and not return_list:
# return single value as a string # return single value as a string
@ -293,6 +380,7 @@ def last_name(num=1, return_list=False):
return results return results
def full_name(num=1, parts=2, gender=None, return_list=False, surname_first=False): def full_name(num=1, parts=2, gender=None, return_list=False, surname_first=False):
""" """
Generate complete names with a personal name, family name, and optionally middle names. Generate complete names with a personal name, family name, and optionally middle names.
@ -318,21 +406,21 @@ def full_name(num=1, parts=2, gender=None, return_list=False, surname_first=Fals
name_lists = [] name_lists = []
middle = parts-2 middle = parts - 2
if middle: if middle:
# calculate "middle" names. # calculate "middle" names.
# we want them to be an intelligent mix of personal names and family names # we want them to be an intelligent mix of personal names and family names
# first, split the total number of middle-name parts into "personal" and "family" at a random point # first, split the total number of middle-name parts into "personal" and "family" at a random point
total_mids = middle*num total_mids = middle * num
personals = random.randint(1,total_mids) personals = random.randint(1, total_mids)
familys = total_mids - personals familys = total_mids - personals
# then get the names for each # then get the names for each
personal_mids = first_name(num=personals, gender=gender, return_list=True) personal_mids = first_name(num=personals, gender=gender, return_list=True)
family_mids = last_name(num=familys, return_list=True) if familys else [] family_mids = last_name(num=familys, return_list=True) if familys else []
# splice them together according to surname_first.... # splice them together according to surname_first....
middle_names = family_mids+personal_mids if surname_first else personal_mids+family_mids middle_names = family_mids + personal_mids if surname_first else personal_mids + family_mids
# ...and then split into `num`-length lists to be used for the final names # ...and then split into `num`-length lists to be used for the final names
name_lists = [ middle_names[num*i:num*(i+1)] for i in range(0,middle) ] name_lists = [middle_names[num * i : num * (i + 1)] for i in range(0, middle)]
# get personal and family names # get personal and family names
personal_names = first_name(num=num, gender=gender, return_list=True) personal_names = first_name(num=num, gender=gender, return_list=True)
@ -346,7 +434,7 @@ def full_name(num=1, parts=2, gender=None, return_list=False, surname_first=Fals
# lastly, zip them all up and join them together # lastly, zip them all up and join them together
names = list(zip(*name_lists)) names = list(zip(*name_lists))
names = [ " ".join(name) for name in names ] names = [" ".join(name) for name in names]
if len(names) == 1 and not return_list: if len(names) == 1 and not return_list:
# return single value as a string # return single value as a string

View file

@ -1,4 +1,3 @@
""" """
Tests for the Random Name Generator Tests for the Random Name Generator
""" """
@ -8,25 +7,26 @@ from evennia.contrib.utils.name_generator import namegen
_INVALID_STYLES = { _INVALID_STYLES = {
"missing_keys": { "missing_keys": {
"consonants": ['c','d'], "consonants": ["c", "d"],
"length": (1,2), "length": (1, 2),
}, },
"invalid_vowels": { "invalid_vowels": {
"syllable": "CVC", "syllable": "CVC",
"consonants": ['c','d'], "consonants": ["c", "d"],
"vowels": "aeiou", "vowels": "aeiou",
"length": (1,2), "length": (1, 2),
}, },
"invalid_length": { "invalid_length": {
"syllable": "CVC", "syllable": "CVC",
"consonants": ['c','d'], "consonants": ["c", "d"],
"vowels": ['a','e'], "vowels": ["a", "e"],
"length": 2, "length": 2,
}, },
} }
namegen._FANTASY_NAME_STRUCTURES |= _INVALID_STYLES namegen._FANTASY_NAME_STRUCTURES |= _INVALID_STYLES
class TestNameGenerator(BaseEvenniaTest): class TestNameGenerator(BaseEvenniaTest):
def test_fantasy_name(self): def test_fantasy_name(self):
""" """
@ -64,13 +64,13 @@ class TestNameGenerator(BaseEvenniaTest):
Verify that validation raises the correct errors for invalid inputs. Verify that validation raises the correct errors for invalid inputs.
""" """
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
namegen.fantasy_name(style="missing_keys") namegen.fantasy_name(style="missing_keys")
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
namegen.fantasy_name(style="invalid_vowels") namegen.fantasy_name(style="invalid_vowels")
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
namegen.fantasy_name(style="invalid_length") namegen.fantasy_name(style="invalid_length")
def test_first_name(self): def test_first_name(self):
""" """
@ -88,7 +88,7 @@ class TestNameGenerator(BaseEvenniaTest):
self.assertEqual(type(three_names), list) self.assertEqual(type(three_names), list)
self.assertEqual(len(three_names), 3) self.assertEqual(len(three_names), 3)
gendered_name = namegen.first_name(gender='f') gendered_name = namegen.first_name(gender="f")
self.assertEqual(type(gendered_name), str) self.assertEqual(type(gendered_name), str)
single_list = namegen.first_name(return_list=True) single_list = namegen.first_name(return_list=True)
@ -96,7 +96,7 @@ class TestNameGenerator(BaseEvenniaTest):
self.assertEqual(len(single_list), 1) self.assertEqual(len(single_list), 1)
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
namegen.first_name(gender='x') namegen.first_name(gender="x")
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
namegen.first_name(num=-1) namegen.first_name(num=-1)
@ -139,7 +139,7 @@ class TestNameGenerator(BaseEvenniaTest):
self.assertEqual(type(three_names), list) self.assertEqual(type(three_names), list)
self.assertEqual(len(three_names), 3) self.assertEqual(len(three_names), 3)
gendered_name = namegen.full_name(gender='f') gendered_name = namegen.full_name(gender="f")
self.assertEqual(type(gendered_name), str) self.assertEqual(type(gendered_name), str)
single_list = namegen.full_name(return_list=True) single_list = namegen.full_name(return_list=True)

View file

@ -17,12 +17,14 @@ at_server_cold_stop()
""" """
def at_server_init(): def at_server_init():
""" """
This is called first as the server is starting up, regardless of how. This is called first as the server is starting up, regardless of how.
""" """
pass pass
def at_server_start(): def at_server_start():
""" """
This is called every time the server starts up, regardless of This is called every time the server starts up, regardless of

View file

@ -6,17 +6,17 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('help', '0003_auto_20190128_1820'), ("help", "0003_auto_20190128_1820"),
] ]
operations = [ operations = [
migrations.RemoveField( migrations.RemoveField(
model_name='helpentry', model_name="helpentry",
name='db_staff_only', name="db_staff_only",
), ),
migrations.AddField( migrations.AddField(
model_name='helpentry', model_name="helpentry",
name='db_date_created', name="db_date_created",
field=models.DateTimeField(auto_now=True, verbose_name='creation date'), field=models.DateTimeField(auto_now=True, verbose_name="creation date"),
), ),
] ]

View file

@ -2,6 +2,7 @@
from django.db import migrations from django.db import migrations
def update_help_entries(apps, schema_editor): def update_help_entries(apps, schema_editor):
""" """
Change all help-entry files that use view: locks to read: locks Change all help-entry files that use view: locks to read: locks
@ -11,8 +12,10 @@ def update_help_entries(apps, schema_editor):
HelpEntry = apps.get_model("help", "HelpEntry") HelpEntry = apps.get_model("help", "HelpEntry")
for help_entry in HelpEntry.objects.all(): for help_entry in HelpEntry.objects.all():
lock_storage = help_entry.db_lock_storage lock_storage = help_entry.db_lock_storage
lock_storage = dict(lstring.split(":", 1) if ":" in lstring else (lstring, "") lock_storage = dict(
for lstring in str(lock_storage).split(";")) lstring.split(":", 1) if ":" in lstring else (lstring, "")
for lstring in str(lock_storage).split(";")
)
if "read" in lock_storage: if "read" in lock_storage:
# already in place - skip # already in place - skip
continue continue
@ -26,9 +29,7 @@ def update_help_entries(apps, schema_editor):
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('help', '0004_auto_20210520_2137'), ("help", "0004_auto_20210520_2137"),
] ]
operations = [ operations = [migrations.RunPython(update_help_entries)]
migrations.RunPython(update_help_entries)
]

View file

@ -41,7 +41,7 @@ PATH_REMAP_PREFIX = {
"auditing": "evennia.contrib.utils", "auditing": "evennia.contrib.utils",
"fieldfill": "evennia.contrib.utils", "fieldfill": "evennia.contrib.utils",
"random_string_generator": "evennia.contrib.utils", "random_string_generator": "evennia.contrib.utils",
"tree_select": "evennia.contrib.utils" "tree_select": "evennia.contrib.utils",
} }
@ -52,43 +52,45 @@ def convert_contrib_typeclass_paths(apps, schema_editor):
try: try:
package_path = obj.db_typeclass_path.split(".")[2:] package_path = obj.db_typeclass_path.split(".")[2:]
package_name = package_path[0] package_name = package_path[0]
if package_path[0] == 'security': if package_path[0] == "security":
# renamed package and changed path # renamed package and changed path
package_name = 'auditing' package_name = "auditing"
package_path.pop(0) # no longer security/auditing package_path.pop(0) # no longer security/auditing
if package_path[-1] == ".Clothing": if package_path[-1] == ".Clothing":
# renamed Clothing class to ContribClothing # renamed Clothing class to ContribClothing
package_path[-1] = "ContribClothing" package_path[-1] = "ContribClothing"
package_path = '.'.join(package_path) package_path = ".".join(package_path)
except IndexError: except IndexError:
print(f"obj.db_typeclass_path={obj.db_typeclass_path} could not be parsed " print(
"for converting to the new contrib location.") f"obj.db_typeclass_path={obj.db_typeclass_path} could not be parsed "
"for converting to the new contrib location."
)
continue continue
if package_name in PATH_REMAP_PREFIX: if package_name in PATH_REMAP_PREFIX:
obj.db_typeclass_path = f"{PATH_REMAP_PREFIX[package_name]}.{package_path}" obj.db_typeclass_path = f"{PATH_REMAP_PREFIX[package_name]}.{package_path}"
obj.save(update_fields=['db_typeclass_path']) obj.save(update_fields=["db_typeclass_path"])
for obj in ObjectDB.objects.filter(db_cmdset_storage__startswith="evennia.contrib."): for obj in ObjectDB.objects.filter(db_cmdset_storage__startswith="evennia.contrib."):
try: try:
package_path = obj.db_cmdset_storage.split(".")[2:] package_path = obj.db_cmdset_storage.split(".")[2:]
package_name = package_path[0] package_name = package_path[0]
package_path = '.'.join(package_path) package_path = ".".join(package_path)
except IndexError: except IndexError:
print(f"obj.db_cmdset_storage={obj.db_cmdset_storage} could not be parsed " print(
"for converting to the new contrib location.") f"obj.db_cmdset_storage={obj.db_cmdset_storage} could not be parsed "
"for converting to the new contrib location."
)
continue continue
if package_name in PATH_REMAP_PREFIX: if package_name in PATH_REMAP_PREFIX:
obj.db_cmdset_storage = f"{PATH_REMAP_PREFIX[package_name]}.{package_path}" obj.db_cmdset_storage = f"{PATH_REMAP_PREFIX[package_name]}.{package_path}"
obj.save(update_fields=['db_cmdset_storage']) obj.save(update_fields=["db_cmdset_storage"])
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('objects', '0011_auto_20191025_0831'), ("objects", "0011_auto_20191025_0831"),
] ]
operations = [ operations = [migrations.RunPython(convert_contrib_typeclass_paths, migrations.RunPython.noop)]
migrations.RunPython(convert_contrib_typeclass_paths, migrations.RunPython.noop)
]

View file

@ -2,8 +2,7 @@ from evennia import DefaultCharacter, DefaultExit, DefaultObject, DefaultRoom
from evennia.objects.models import ObjectDB from evennia.objects.models import ObjectDB
from evennia.objects.objects import DefaultObject from evennia.objects.objects import DefaultObject
from evennia.typeclasses.attributes import AttributeProperty from evennia.typeclasses.attributes import AttributeProperty
from evennia.typeclasses.tags import (AliasProperty, PermissionProperty, from evennia.typeclasses.tags import AliasProperty, PermissionProperty, TagProperty
TagProperty)
from evennia.utils import create from evennia.utils import create
from evennia.utils.test_resources import BaseEvenniaTest, EvenniaTestCase from evennia.utils.test_resources import BaseEvenniaTest, EvenniaTestCase
@ -240,6 +239,7 @@ class SubAttributeProperty(AttributeProperty):
class SubTagProperty(TagProperty): class SubTagProperty(TagProperty):
pass pass
class CustomizedProperty(AttributeProperty): class CustomizedProperty(AttributeProperty):
def at_set(self, value, obj): def at_set(self, value, obj):
obj.settest = value obj.settest = value
@ -248,6 +248,7 @@ class CustomizedProperty(AttributeProperty):
def at_get(self, value, obj): def at_get(self, value, obj):
return value + obj.awaretest return value + obj.awaretest
class TestObjectPropertiesClass(DefaultObject): class TestObjectPropertiesClass(DefaultObject):
attr1 = AttributeProperty(default="attr1") attr1 = AttributeProperty(default="attr1")
attr2 = AttributeProperty(default="attr2", category="attrcategory") attr2 = AttributeProperty(default="attr2", category="attrcategory")
@ -266,6 +267,7 @@ class TestObjectPropertiesClass(DefaultObject):
def base_property(self): def base_property(self):
self.property_initialized = True self.property_initialized = True
class TestProperties(EvenniaTestCase): class TestProperties(EvenniaTestCase):
""" """
Test Properties. Test Properties.
@ -273,7 +275,9 @@ class TestProperties(EvenniaTestCase):
""" """
def setUp(self): def setUp(self):
self.obj: TestObjectPropertiesClass = create.create_object(TestObjectPropertiesClass, key="testobj") self.obj: TestObjectPropertiesClass = create.create_object(
TestObjectPropertiesClass, key="testobj"
)
def tearDown(self): def tearDown(self):
self.obj.delete() self.obj.delete()
@ -317,7 +321,7 @@ class TestProperties(EvenniaTestCase):
self.assertFalse(hasattr(obj, "property_initialized")) self.assertFalse(hasattr(obj, "property_initialized"))
def test_object_awareness(self): def test_object_awareness(self):
'''Test the "object-awareness" of customized AttributeProperty getter/setters''' """Test the "object-awareness" of customized AttributeProperty getter/setters"""
obj = self.obj obj = self.obj
# attribute properties receive on obj ref in the getter/setter that can customize return # attribute properties receive on obj ref in the getter/setter that can customize return

View file

@ -6,18 +6,22 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('scripts', '0013_auto_20191025_0831'), ("scripts", "0013_auto_20191025_0831"),
] ]
operations = [ operations = [
migrations.AlterField( migrations.AlterField(
model_name='scriptdb', model_name="scriptdb",
name='db_interval', name="db_interval",
field=models.IntegerField(default=-1, help_text='how often to repeat script, in seconds. <= 0 means off.', verbose_name='interval'), field=models.IntegerField(
default=-1,
help_text="how often to repeat script, in seconds. <= 0 means off.",
verbose_name="interval",
),
), ),
migrations.AlterField( migrations.AlterField(
model_name='scriptdb', model_name="scriptdb",
name='db_persistent', name="db_persistent",
field=models.BooleanField(default=True, verbose_name='survive server reboot'), field=models.BooleanField(default=True, verbose_name="survive server reboot"),
), ),
] ]

View file

@ -41,7 +41,7 @@ PATH_REMAP_PREFIX = {
"auditing": "evennia.contrib.utils", "auditing": "evennia.contrib.utils",
"fieldfill": "evennia.contrib.utils", "fieldfill": "evennia.contrib.utils",
"random_string_generator": "evennia.contrib.utils", "random_string_generator": "evennia.contrib.utils",
"tree_select": "evennia.contrib.utils" "tree_select": "evennia.contrib.utils",
} }
@ -52,30 +52,30 @@ def convert_contrib_typeclass_paths(apps, schema_editor):
try: try:
package_path = obj.db_typeclass_path.split(".")[2:] package_path = obj.db_typeclass_path.split(".")[2:]
package_name = package_path[0] package_name = package_path[0]
if package_path[0] == 'security': if package_path[0] == "security":
# renamed package and changed path # renamed package and changed path
package_name = 'auditing' package_name = "auditing"
package_path.pop(0) # no longer security/auditing package_path.pop(0) # no longer security/auditing
if package_path[-1] == ".Clothing": if package_path[-1] == ".Clothing":
# renamed Clothing class to ContribClothing # renamed Clothing class to ContribClothing
package_path[-1] = "ContribClothing" package_path[-1] = "ContribClothing"
package_path = '.'.join(package_path) package_path = ".".join(package_path)
except IndexError: except IndexError:
print(f"obj.db_typeclass_path={obj.db_typeclass_path} could not be parsed " print(
"for converting to the new contrib location.") f"obj.db_typeclass_path={obj.db_typeclass_path} could not be parsed "
"for converting to the new contrib location."
)
continue continue
if package_name in PATH_REMAP_PREFIX: if package_name in PATH_REMAP_PREFIX:
obj.db_typeclass_path = f"{PATH_REMAP_PREFIX[package_name]}.{package_path}" obj.db_typeclass_path = f"{PATH_REMAP_PREFIX[package_name]}.{package_path}"
obj.save(update_fields=['db_typeclass_path']) obj.save(update_fields=["db_typeclass_path"])
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('scripts', '0014_auto_20210520_2137'), ("scripts", "0014_auto_20210520_2137"),
] ]
operations = [ operations = [migrations.RunPython(convert_contrib_typeclass_paths, migrations.RunPython.noop)]
migrations.RunPython(convert_contrib_typeclass_paths, migrations.RunPython.noop)
]

View file

@ -47,8 +47,11 @@ _SA = object.__setattr__
SERVER_RESTART = os.path.join(settings.GAME_DIR, "server", "server.restart") SERVER_RESTART = os.path.join(settings.GAME_DIR, "server", "server.restart")
# modules containing hook methods called during start_stop # modules containing hook methods called during start_stop
SERVER_STARTSTOP_MODULES = [mod_import(mod) for mod in make_iter(settings.AT_SERVER_STARTSTOP_MODULE) SERVER_STARTSTOP_MODULES = [
if isinstance(mod, str)] mod_import(mod)
for mod in make_iter(settings.AT_SERVER_STARTSTOP_MODULE)
if isinstance(mod, str)
]
# modules containing plugin services # modules containing plugin services
SERVER_SERVICES_PLUGIN_MODULES = make_iter(settings.SERVER_SERVICES_PLUGIN_MODULES) SERVER_SERVICES_PLUGIN_MODULES = make_iter(settings.SERVER_SERVICES_PLUGIN_MODULES)

View file

@ -233,13 +233,16 @@ class AttributeProperty:
""" """
value = self._default value = self._default
try: try:
value = self.at_get(getattr(instance, self.attrhandler_name).get( value = self.at_get(
key=self._key, getattr(instance, self.attrhandler_name).get(
default=self._default, key=self._key,
category=self._category, default=self._default,
strattr=self._strattr, category=self._category,
raise_exception=self._autocreate, strattr=self._strattr,
), instance) raise_exception=self._autocreate,
),
instance,
)
except AttributeError: except AttributeError:
if self._autocreate: if self._autocreate:
# attribute didn't exist and autocreate is set # attribute didn't exist and autocreate is set

View file

@ -6,13 +6,20 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('typeclasses', '0013_auto_20191015_1922'), ("typeclasses", "0013_auto_20191015_1922"),
] ]
operations = [ operations = [
migrations.AlterField( migrations.AlterField(
model_name='tag', model_name="tag",
name='db_category', name="db_category",
field=models.CharField(blank=True, db_index=True, help_text='tag category', max_length=64, null=True, verbose_name='category'), field=models.CharField(
blank=True,
db_index=True,
help_text="tag category",
max_length=64,
null=True,
verbose_name="category",
),
), ),
] ]

View file

@ -6,12 +6,12 @@ from django.db import migrations
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('typeclasses', '0014_alter_tag_db_category'), ("typeclasses", "0014_alter_tag_db_category"),
] ]
operations = [ operations = [
migrations.AlterModelOptions( migrations.AlterModelOptions(
name='attribute', name="attribute",
options={'verbose_name': 'Attribute'}, options={"verbose_name": "Attribute"},
), ),
] ]

View file

@ -2,8 +2,8 @@ from evennia.scripts.scripts import DefaultScript
from evennia.utils.test_resources import EvenniaTest from evennia.utils.test_resources import EvenniaTest
from evennia.utils.search import search_script_attribute, search_script_tag, search_script from evennia.utils.search import search_script_attribute, search_script_tag, search_script
class TestSearch(EvenniaTest):
class TestSearch(EvenniaTest):
def test_search_script_tag(self): def test_search_script_tag(self):
"""Check that a script can be found by its tag.""" """Check that a script can be found by its tag."""
script, errors = DefaultScript.create("a-script") script, errors = DefaultScript.create("a-script")
@ -61,4 +61,3 @@ class TestSearch(EvenniaTest):
script, errors = DefaultScript.create("a-script") script, errors = DefaultScript.create("a-script")
found = search_script("wrong_key") found = search_script("wrong_key")
self.assertEqual(len(found), 0, errors) self.assertEqual(len(found), 0, errors)

View file

@ -80,7 +80,9 @@ class TestListToString(TestCase):
self.assertEqual("1, 2 and 3", utils.list_to_string([1, 2, 3], endsep="and")) self.assertEqual("1, 2 and 3", utils.list_to_string([1, 2, 3], endsep="and"))
self.assertEqual("1, 2 3", utils.list_to_string([1, 2, 3], endsep="")) self.assertEqual("1, 2 3", utils.list_to_string([1, 2, 3], endsep=""))
self.assertEqual("1; 2; 3", utils.list_to_string([1, 2, 3], sep=";", endsep=";")) self.assertEqual("1; 2; 3", utils.list_to_string([1, 2, 3], sep=";", endsep=";"))
self.assertEqual('"1", "2", "3"', utils.list_to_string([1, 2, 3], endsep=",", addquote=True)) self.assertEqual(
'"1", "2", "3"', utils.list_to_string([1, 2, 3], endsep=",", addquote=True)
)
self.assertEqual( self.assertEqual(
'"1", "2" and "3"', utils.list_to_string([1, 2, 3], endsep="and", addquote=True) '"1", "2" and "3"', utils.list_to_string([1, 2, 3], endsep="and", addquote=True)
) )

View file

@ -275,8 +275,7 @@ class CharacterPuppetView(EvenniaWebTest):
self.assertTrue( self.assertTrue(
response.status_code >= 400, response.status_code >= 400,
"Invalid access should return a 4xx code-- either obj not found or permission denied!" "Invalid access should return a 4xx code-- either obj not found or permission denied!"
" (Returned %s)" " (Returned %s)" % response.status_code,
% response.status_code,
) )