@@ -137,11 +137,6 @@ def read_file(cls, file_path, config_name):
137137 with io_open (file_path , encoding = "utf-8" ) as file_stream :
138138 return file_stream .read ()
139139
140- @staticmethod
141- def read_config_file (file_path ):
142- with open (file_path ) as file_stream :
143- return yaml .safe_load (file_stream )
144-
145140 def invoke_all (self , name , * args , ** kargs ):
146141 results = []
147142 for cls in type (self ).mro ():
@@ -159,9 +154,8 @@ def generate_config(
159154 ):
160155 """Build a default configuration file
161156
162- This is used both when the user explicitly asks us to generate a config file
163- (eg with --generate_config), and before loading the config at runtime (to give
164- a base which the config files override)
157+ This is used when the user explicitly asks us to generate a config file
158+ (eg with --generate_config).
165159
166160 Args:
167161 config_dir_path (str): The path where the config files are kept. Used to
@@ -183,10 +177,10 @@ def generate_config(
183177 Returns:
184178 str: the yaml config file
185179 """
186- default_config = "\n \n " .join (
180+ return "\n \n " .join (
187181 dedent (conf )
188182 for conf in self .invoke_all (
189- "default_config " ,
183+ "generate_config_section " ,
190184 config_dir_path = config_dir_path ,
191185 data_dir_path = data_dir_path ,
192186 server_name = server_name ,
@@ -195,8 +189,6 @@ def generate_config(
195189 )
196190 )
197191
198- return default_config
199-
200192 @classmethod
201193 def load_config (cls , description , argv ):
202194 """Parse the commandline and config files
@@ -241,9 +233,7 @@ def load_config(cls, description, argv):
241233 config_dir_path = os .path .abspath (config_dir_path )
242234 data_dir_path = os .getcwd ()
243235
244- config_dict = obj .read_config_files (
245- config_files , config_dir_path = config_dir_path , data_dir_path = data_dir_path
246- )
236+ config_dict = read_config_files (config_files )
247237 obj .parse_config_dict (
248238 config_dict , config_dir_path = config_dir_path , data_dir_path = data_dir_path
249239 )
@@ -355,8 +345,8 @@ def load_or_generate_config(cls, description, argv):
355345 config_file .write ("# vim:ft=yaml\n \n " )
356346 config_file .write (config_str )
357347
358- config = yaml .safe_load (config_str )
359- obj .invoke_all ( "generate_files" , config )
348+ config_dict = yaml .safe_load (config_str )
349+ obj .generate_missing_files ( config_dict , config_dir_path )
360350
361351 print (
362352 (
@@ -386,12 +376,9 @@ def load_or_generate_config(cls, description, argv):
386376 obj .invoke_all ("add_arguments" , parser )
387377 args = parser .parse_args (remaining_args )
388378
389- config_dict = obj .read_config_files (
390- config_files , config_dir_path = config_dir_path , data_dir_path = data_dir_path
391- )
392-
379+ config_dict = read_config_files (config_files )
393380 if generate_missing_configs :
394- obj .generate_missing_files (config_dict )
381+ obj .generate_missing_files (config_dict , config_dir_path )
395382 return None
396383
397384 obj .parse_config_dict (
@@ -401,53 +388,6 @@ def load_or_generate_config(cls, description, argv):
401388
402389 return obj
403390
404- def read_config_files (self , config_files , config_dir_path , data_dir_path ):
405- """Read the config files into a dict
406-
407- Args:
408- config_files (iterable[str]): A list of the config files to read
409-
410- config_dir_path (str): The path where the config files are kept. Used to
411- create filenames for things like the log config and the signing key.
412-
413- data_dir_path (str): The path where the data files are kept. Used to create
414- filenames for things like the database and media store.
415-
416- Returns: dict
417- """
418- # first we read the config files into a dict
419- specified_config = {}
420- for config_file in config_files :
421- yaml_config = self .read_config_file (config_file )
422- specified_config .update (yaml_config )
423-
424- # not all of the options have sensible defaults in code, so we now need to
425- # generate a default config file suitable for the specified server name...
426- if "server_name" not in specified_config :
427- raise ConfigError (MISSING_SERVER_NAME )
428- server_name = specified_config ["server_name" ]
429- config_string = self .generate_config (
430- config_dir_path = config_dir_path ,
431- data_dir_path = data_dir_path ,
432- server_name = server_name ,
433- generate_secrets = False ,
434- )
435-
436- # ... and read it into a base config dict ...
437- config = yaml .safe_load (config_string )
438-
439- # ... and finally, overlay it with the actual configuration.
440- config .pop ("log_config" )
441- config .update (specified_config )
442-
443- if "report_stats" not in config :
444- raise ConfigError (
445- MISSING_REPORT_STATS_CONFIG_INSTRUCTIONS
446- + "\n "
447- + MISSING_REPORT_STATS_SPIEL
448- )
449- return config
450-
451391 def parse_config_dict (self , config_dict , config_dir_path , data_dir_path ):
452392 """Read the information from the config dict into this Config object.
453393
@@ -467,8 +407,32 @@ def parse_config_dict(self, config_dict, config_dir_path, data_dir_path):
467407 data_dir_path = data_dir_path ,
468408 )
469409
470- def generate_missing_files (self , config_dict ):
471- self .invoke_all ("generate_files" , config_dict )
410+ def generate_missing_files (self , config_dict , config_dir_path ):
411+ self .invoke_all ("generate_files" , config_dict , config_dir_path )
412+
413+
414+ def read_config_files (config_files ):
415+ """Read the config files into a dict
416+
417+ Args:
418+ config_files (iterable[str]): A list of the config files to read
419+
420+ Returns: dict
421+ """
422+ specified_config = {}
423+ for config_file in config_files :
424+ with open (config_file ) as file_stream :
425+ yaml_config = yaml .safe_load (file_stream )
426+ specified_config .update (yaml_config )
427+
428+ if "server_name" not in specified_config :
429+ raise ConfigError (MISSING_SERVER_NAME )
430+
431+ if "report_stats" not in specified_config :
432+ raise ConfigError (
433+ MISSING_REPORT_STATS_CONFIG_INSTRUCTIONS + "\n " + MISSING_REPORT_STATS_SPIEL
434+ )
435+ return specified_config
472436
473437
474438def find_config_files (search_paths ):
0 commit comments