From ad155f1f178fac8865f48b910ef076b3d568c32c Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Thu, 30 Aug 2018 12:30:22 +1000 Subject: [PATCH] Only create default conf file after options are parsed. --- butterfly.server.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/butterfly.server.py b/butterfly.server.py index 5fa77ea..7ec151c 100755 --- a/butterfly.server.py +++ b/butterfly.server.py @@ -98,17 +98,6 @@ butterfly_dir = os.path.join(ev, 'butterfly') conf_file = os.path.join(butterfly_dir, 'butterfly.conf') ssl_dir = os.path.join(butterfly_dir, 'ssl') -if not os.path.exists(conf_file): - try: - import butterfly - shutil.copy( - os.path.join( - os.path.abspath(os.path.dirname(butterfly.__file__)), - 'butterfly.conf.default'), conf_file) - print('butterfly.conf installed in %s' % conf_file) - except: - pass - tornado.options.define("conf", default=conf_file, help="Butterfly configuration file. " "Contains the same options as command line.") @@ -125,6 +114,21 @@ if os.path.exists(tornado.options.options.conf): # Do it again to overwrite conf with args tornado.options.parse_command_line() +# For next time, create them a conf file from template. +# Need to do this after parsing options so we do not trigger +# code import for butterfly module, in case that code is +# dependent on the set of parsed options. +if not os.path.exists(conf_file): + try: + import butterfly + shutil.copy( + os.path.join( + os.path.abspath(os.path.dirname(butterfly.__file__)), + 'butterfly.conf.default'), conf_file) + print('butterfly.conf installed in %s' % conf_file) + except: + pass + options = tornado.options.options for logger in ('tornado.access', 'tornado.application',