Add secret_settings and mechanisms for managing it. This allows for easier hiding game- and server-specific settings when sharing the game dir with others.
This commit is contained in:
parent
b269ef265e
commit
167d09b4cd
5 changed files with 50 additions and 24 deletions
|
|
@ -506,7 +506,7 @@ def create_secret_key():
|
|||
return secret_key
|
||||
|
||||
|
||||
def create_settings_file(init=True):
|
||||
def create_settings_file(init=True, secret_settings=False):
|
||||
"""
|
||||
Uses the template settings file to build a working settings file.
|
||||
|
||||
|
|
@ -514,18 +514,27 @@ def create_settings_file(init=True):
|
|||
init (bool): This is part of the normal evennia --init
|
||||
operation. If false, this function will copy a fresh
|
||||
template file in (asking if it already exists).
|
||||
secret_settings (bool, optional): If False, create settings.py, otherwise
|
||||
create the secret_settings.py file.
|
||||
|
||||
"""
|
||||
settings_path = os.path.join(GAMEDIR, "server", "conf", "settings.py")
|
||||
if secret_settings:
|
||||
settings_path = os.path.join(GAMEDIR, "server", "conf", "secret_settings.py")
|
||||
setting_dict = {"secret_key": "\'%s\'" % create_secret_key()}
|
||||
else:
|
||||
settings_path = os.path.join(GAMEDIR, "server", "conf", "settings.py")
|
||||
setting_dict = {
|
||||
"settings_default": os.path.join(EVENNIA_LIB, "settings_default.py"),
|
||||
"servername": "\"%s\"" % GAMEDIR.rsplit(os.path.sep, 1)[1].capitalize(),
|
||||
"secret_key": "\'%s\'" % create_secret_key()}
|
||||
|
||||
if not init:
|
||||
# if not --init mode, settings file may already exist from before
|
||||
if os.path.exists(settings_path):
|
||||
inp = input("server/conf/settings.py already exists. "
|
||||
"Do you want to reset it? y/[N]> ")
|
||||
inp = input("%s already exists. Do you want to reset it? y/[N]> " % settings_path)
|
||||
if not inp.lower() == 'y':
|
||||
print ("Aborted.")
|
||||
sys.exit()
|
||||
return
|
||||
else:
|
||||
print ("Reset the settings file.")
|
||||
|
||||
|
|
@ -535,12 +544,6 @@ def create_settings_file(init=True):
|
|||
with open(settings_path, 'r') as f:
|
||||
settings_string = f.read()
|
||||
|
||||
# tweak the settings
|
||||
setting_dict = {
|
||||
"settings_default": os.path.join(EVENNIA_LIB, "settings_default.py"),
|
||||
"servername": "\"%s\"" % GAMEDIR.rsplit(os.path.sep, 1)[1].capitalize(),
|
||||
"secret_key": "\'%s\'" % create_secret_key()}
|
||||
|
||||
settings_string = settings_string.format(**setting_dict)
|
||||
|
||||
with open(settings_path, 'w') as f:
|
||||
|
|
@ -564,8 +567,13 @@ def create_game_directory(dirname):
|
|||
sys.exit()
|
||||
# copy template directory
|
||||
shutil.copytree(EVENNIA_TEMPLATE, GAMEDIR)
|
||||
# rename gitignore to .gitignore
|
||||
os.rename(os.path.join(GAMEDIR, 'gitignore'),
|
||||
os.path.join(GAMEDIR, '.gitignore'))
|
||||
|
||||
# pre-build settings file in the new GAMEDIR
|
||||
create_settings_file()
|
||||
create_settings_file(secret_settings=True)
|
||||
|
||||
|
||||
def create_superuser():
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ class Evennia(object):
|
|||
# (see https://github.com/evennia/evennia/issues/1128)
|
||||
def _wrap_sigint_handler(*args):
|
||||
from twisted.internet.defer import Deferred
|
||||
if WEBSERVER_ENABLED:
|
||||
if hasattr(self, "webroot"):
|
||||
d = self.web_root.empty_threadpool()
|
||||
d.addCallback(lambda _: self.shutdown(_reactor_stopping=True))
|
||||
else:
|
||||
|
|
@ -399,7 +399,7 @@ class Evennia(object):
|
|||
# for Windows we need to remove pid files manually
|
||||
os.remove(SERVER_PIDFILE)
|
||||
|
||||
if WEBSERVER_ENABLED:
|
||||
if hasattr(self, "web_root"): # not set very first start
|
||||
yield self.web_root.empty_threadpool()
|
||||
|
||||
if not _reactor_stopping:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue