@@ -49,6 +49,8 @@ def _copy_or_migrate_user_settings(settings_dir, source_path, dest_file_name):
4949 m_error = None
5050 if not os .path .exists (source_path ):
5151 raise (FileNotFoundError (source_path ))
52+ else :
53+ shutil .copyfile (source_path , source_path + '._backup' )
5254 if not dest_file_name :
5355 dest_file_name = os .path .basename (source_path )
5456 settings_path = os .path .join (settings_dir , dest_file_name )
@@ -60,12 +62,12 @@ def _copy_or_migrate_user_settings(settings_dir, source_path, dest_file_name):
6062 SettingsMigrator (source_path , settings_path ).migrate ()
6163 # print(f"DEBUG: settings After migration {source_path} with {settings_path}")
6264 except ConfigObjError as parsing_error :
63- print ("WARNING! corrupted configuration file replaced with defaults" )
65+ print ("WARNING! corrupted configuration file replaced with defaults\n "
66+ f"A backup of the settings is at: { source_path + '._backup' } " )
6467 print (parsing_error )
6568 m_error = parsing_error
6669 shutil .copyfile (settings_path , settings_path + '_old_broken' )
67- print ("(backed up corrupted configuration file at: %s)" %
68- (settings_path + '_old_broken' ))
70+ print (f"(backed up corrupted configuration file at: { settings_path + '_old_broken' } " )
6971 shutil .copyfile (source_path , settings_path )
7072 # print("DEBUG: source %s corrupted settings %s\n" % (source_path, settings_path))
7173 finally : # DEBUG Try to merge some settings
@@ -362,22 +364,24 @@ def __init__(self, path=None):
362364 elif path .endswith ('.cfg' ) and os .path .exists (path ):
363365 self ._default_path = path
364366 # print(f"DEBUG: settings.py RideSettings SETTINGS {self._default_path=}")
365- user_path = initialize_settings (self ._default_path )
366- Settings .__init__ (self , user_path )
367- self ._settings_dir = os .path .dirname (user_path )
367+ self . user_path = initialize_settings (self ._default_path )
368+ Settings .__init__ (self , self . user_path )
369+ self ._settings_dir = os .path .dirname (self . user_path )
368370 # print(f"DEBUG: RideSettings, self._settings_dir={self._settings_dir}")
369371 self .get ('install root' , os .path .dirname (os .path .dirname (__file__ )))
370372 self .executable = self .get ('executable' , EXECUTABLE )
371373 if self .executable != EXECUTABLE :
372374 digest = 0
373375 for c in EXECUTABLE :
374376 digest += ord (c )
375- new_user_path = user_path .replace ("settings.cfg" , f"settings_{ digest } .cfg" )
376- new_user_path = initialize_settings (user_path , new_user_path )
377+ new_user_path = self .user_path .replace ("settings.cfg" , f"settings_{ digest } .cfg" )
378+ new_user_path = initialize_settings (self .user_path , new_user_path )
379+ self .user_path = new_user_path
377380 Settings .__init__ (self , new_user_path )
378381 self ._settings_dir = os .path .dirname (new_user_path )
379382 self .set ('install root' , os .path .dirname (os .path .dirname (__file__ )))
380- self .executable = self .set ('executable' , EXECUTABLE )
383+ self .set ('executable' , EXECUTABLE )
384+ self .set ('last_settings_path' , self .user_path )
381385
382386 def get_path (self , * parts ):
383387 """Returns path which combines settings directory and given parts."""
0 commit comments