Move gametime conversion factors to contrib and remove them from the settings file with the motivation that the gametime constats were always highly game specific and a remnant from another time. Reworked the gametime library and add server epoch building from vincent-lg's original PR. The gametime module now deals exclusively in seconds.

This commit is contained in:
Griatch 2017-02-12 18:51:56 +01:00
parent 2a48a4d645
commit 008566f358
7 changed files with 96 additions and 229 deletions

View file

@ -12,26 +12,11 @@ def check_errors(settings):
Args:
settings (Settings): The Django settings file
Raises:
DeprecationWarning
DeprecationWarning if a critical deprecation is found.
"""
from django.conf import settings
def imp(path, split=True):
mod, fromlist = path, "None"
if split:
mod, fromlist = path.rsplit('.', 1)
__import__(mod, fromlist=[fromlist])
# core modules
imp(settings.COMMAND_PARSER)
imp(settings.SEARCH_AT_RESULT)
imp(settings.CONNECTION_SCREEN_MODULE)
#imp(settings.AT_INITIAL_SETUP_HOOK_MODULE, split=False)
for path in settings.LOCK_FUNC_MODULES:
imp(path, split=False)
# cmdsets
deprstring = ("settings.%s should be renamed to %s. If defaults are used, "
"their path/classname must be updated "
"(see evennia/settings_default.py).")
@ -72,23 +57,22 @@ def check_errors(settings):
"Update your settings file (see evennia/settings_default.py "
"for more info).")
from evennia.commands import cmdsethandler
if not cmdsethandler.import_cmdset(settings.CMDSET_UNLOGGEDIN, None):
print("Warning: CMDSET_UNLOGGED failed to load!")
if not cmdsethandler.import_cmdset(settings.CMDSET_CHARACTER, None):
print("Warning: CMDSET_CHARACTER failed to load")
if not cmdsethandler.import_cmdset(settings.CMDSET_PLAYER, None):
print("Warning: CMDSET_PLAYER failed to load")
# typeclasses
imp(settings.BASE_PLAYER_TYPECLASS)
imp(settings.BASE_OBJECT_TYPECLASS)
imp(settings.BASE_CHARACTER_TYPECLASS)
imp(settings.BASE_ROOM_TYPECLASS)
imp(settings.BASE_EXIT_TYPECLASS)
imp(settings.BASE_SCRIPT_TYPECLASS)
gametime_deprecation = ("The settings TIME_SEC_PER_MIN, TIME_MIN_PER_HOUR,"
"TIME_HOUR_PER_DAY, TIME_DAY_PER_WEEK, \n"
"TIME_WEEK_PER_MONTH and TIME_MONTH_PER_YEAR "
"are no longer supported. Remove them from your "
"settings file to continue.\nIf you want to use "
"and manipulate these time units, the tools from utils.gametime "
"are now found in contrib/convert_gametime.py instead.")
if any(hasattr(settings, value) for value in ("TIME_SEC_PER_MIN", "TIME_MIN_PER_HOUR",
"TIME_HOUR_PER_DAY", "TIME_DAY_PER_WEEK", "TIME_WEEK_PER_MONTH",
"TIME_MONTH_PER_YEAR")):
raise DeprecationWarning(gametime_deprecation)
def check_warnings(settings):
"""
Check deprecations that should produce warnings but which
does not stop launch.
"""
pass

View file

@ -768,14 +768,11 @@ def error_check_python_modules():
python source files themselves). Best they fail already here
before we get any further.
Raises:
DeprecationWarning: For trying to access various modules
(usually in `settings.py`) which are no longer supported.
"""
from django.conf import settings
def imp(path, split=True):
def _imp(path, split=True):
"helper method"
mod, fromlist = path, "None"
if split:
mod, fromlist = path.rsplit('.', 1)
@ -783,16 +780,20 @@ def error_check_python_modules():
# check the historical deprecations
from evennia.server import deprecations
deprecations.check_errors(settings)
deprecations.check_warnings(settings)
try:
deprecations.check_errors(settings)
deprecations.check_warnings(settings)
except DeprecationWarning as err:
print(err)
sys.exit()
# core modules
imp(settings.COMMAND_PARSER)
imp(settings.SEARCH_AT_RESULT)
imp(settings.CONNECTION_SCREEN_MODULE)
_imp(settings.COMMAND_PARSER)
_imp(settings.SEARCH_AT_RESULT)
_imp(settings.CONNECTION_SCREEN_MODULE)
#imp(settings.AT_INITIAL_SETUP_HOOK_MODULE, split=False)
for path in settings.LOCK_FUNC_MODULES:
imp(path, split=False)
_imp(path, split=False)
from evennia.commands import cmdsethandler
if not cmdsethandler.import_cmdset(settings.CMDSET_UNLOGGEDIN, None):
@ -802,12 +803,12 @@ def error_check_python_modules():
if not cmdsethandler.import_cmdset(settings.CMDSET_PLAYER, None):
print("Warning: CMDSET_PLAYER failed to load")
# typeclasses
imp(settings.BASE_PLAYER_TYPECLASS)
imp(settings.BASE_OBJECT_TYPECLASS)
imp(settings.BASE_CHARACTER_TYPECLASS)
imp(settings.BASE_ROOM_TYPECLASS)
imp(settings.BASE_EXIT_TYPECLASS)
imp(settings.BASE_SCRIPT_TYPECLASS)
_imp(settings.BASE_PLAYER_TYPECLASS)
_imp(settings.BASE_OBJECT_TYPECLASS)
_imp(settings.BASE_CHARACTER_TYPECLASS)
_imp(settings.BASE_ROOM_TYPECLASS)
_imp(settings.BASE_EXIT_TYPECLASS)
_imp(settings.BASE_SCRIPT_TYPECLASS)
def init_game_directory(path, check_db=True):
"""

View file

@ -7,7 +7,7 @@ Everything starts at handle_setup()
"""
from __future__ import print_function
import django
import time
from django.conf import settings
from django.utils.translation import ugettext as _
from evennia.players.models import PlayerDB
@ -160,6 +160,7 @@ def reset_server():
also checks so the warm-reset mechanism works as it should.
"""
ServerConfig.objects.conf("server_epoch", time.time())
from evennia.server.sessionhandler import SESSIONS
logger.log_info(" Initial setup complete. Restarting Server once.")
SESSIONS.server.shutdown(mode='reset')