From 8d3817ccd4a4e58b535fd2e00125d4504e36ac14 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 9 Oct 2011 19:42:39 +0200 Subject: [PATCH] Added at_initial_setup hook. Create a module in game/ and point to it with settings.AT_INITIAL_SETUP_HOOK_MODULE. This module must contain at function at_initial_setup(), which will be called very last in the setup procedure. If no module is given or fail to load, this will fail quietly. --- src/server/initial_setup.py | 19 +++++++++++++++++-- src/settings_default.py | 5 +++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/server/initial_setup.py b/src/server/initial_setup.py index f534a26539..0b361ab765 100644 --- a/src/server/initial_setup.py +++ b/src/server/initial_setup.py @@ -178,6 +178,20 @@ def create_admin_media_links(): print _(" Admin-media symlinked to ADMIN_MEDIA_ROOT.") else: print _(" Admin-media files should be copied manually to ADMIN_MEDIA_ROOT.") + +def at_initial_setup(): + """ + Custom hook for users to overload some or all parts of the initial setup. Called very + last in the sequence. It tries to import and run a module + """ + try: + mod = __import__(settings.AT_INITIAL_SETUP_HOOK_MODULE, fromlist=[None]) + except ImportError: + return + print _(" Running at_initial_setup() hook.") + if mod.__dict__.get("at_initial_setup", None): + mod.at_initial_setup() + def handle_setup(last_step): """ @@ -202,12 +216,13 @@ def handle_setup(last_step): create_system_scripts, start_game_time, create_admin_media_links, - import_MUX_help_files] + import_MUX_help_files, + at_initial_setup] if not settings.IMPORT_MUX_HELP: # skip importing of the MUX helpfiles, they are # not interesting except for developers. - del setup_queue[-1] + del setup_queue[-2] #print " Initial setup: %s steps." % (len(setup_queue)) diff --git a/src/settings_default.py b/src/settings_default.py index 5779d756d6..2a5344e8be 100644 --- a/src/settings_default.py +++ b/src/settings_default.py @@ -159,6 +159,11 @@ SEARCH_AT_MULTIMATCH_INPUT = "src.commands.cmdparser.at_multimatch_input" # This module should contain one or more variables # with strings defining the look of the screen. CONNECTION_SCREEN_MODULE = "game.gamesrc.world.connection_screens" +# An option al module that, if existing, must hold a function +# named at_initial_setup(). This hook method can be used to customize +# the server's initial setup sequence (the very first startup of the system). +# The check will fail quietly if module doesn't exist or fails to load. +AT_INITIAL_SETUP_HOOK_MODULE = "game.gamesrc.world.at_initial_setup" ################################################### # Default command sets