@@ -29,20 +29,32 @@ def get_all_settings():
2929
3030
3131def save_profile (profile_name , shortcut = None ):
32+ backup_profile (profile_name )
33+ return save_profile_raw (profile_name , shortcut = shortcut )
34+
35+
36+ def save_profile_raw (profile_name , shortcut = None ):
3237 """Save current settings to a named profile.
3338
3439 Args:
35- profile_name: Name of the profile
36- shortcut: Optional numeric shortcut (e.g., '1', '2', '3')
40+ profile_name: Name of the profile
41+ shortcut: Optional numeric shortcut (e.g., '1', '2', '3')
3742 """
3843 r = interprocess .get_redis_client ()
3944 current_settings = get_all_settings ()
4045
4146 # Store profile data
4247 profile_data = {
43- 'name' : profile_name ,
44- 'settings' : current_settings ,
48+ 'name' : profile_name ,
49+ 'settings' : current_settings ,
4550 }
51+ return save_profile_data (profile_name , profile_data , shortcut = shortcut )
52+
53+
54+ def save_profile_data (profile_name , profile_data , shortcut = None ):
55+ r = interprocess .get_redis_client ()
56+ current_settings = get_all_settings ()
57+
4658 if shortcut is not None :
4759 profile_data ['shortcut' ] = shortcut
4860
@@ -58,6 +70,23 @@ def save_profile(profile_name, shortcut=None):
5870 return current_settings
5971
6072
73+ def backup_profile (profile_name ):
74+ profile_data = get_profile_data (profile_name )
75+ if profile_data is not None :
76+ save_profile_data (f'{ profile_name } .backup' , profile_data )
77+
78+
79+ def get_profile_data (profile_name ):
80+ r = interprocess .get_redis_client ()
81+
82+ profile_json = r .get (get_redis_key (profile_name ))
83+ if profile_json is None :
84+ return None
85+
86+ profile_data = json .loads (profile_json )
87+ return profile_data
88+
89+
6190def load_profile (profile_name ):
6291 """Load settings from a named profile.
6392
@@ -71,11 +100,9 @@ def load_profile(profile_name):
71100 save_profile ('backup' , shortcut = None )
72101
73102 # Load the requested profile
74- profile_json = r . get ( get_redis_key ( profile_name ) )
75- if profile_json is None :
103+ profile_data = get_profile_data ( profile_name )
104+ if profile_data is None :
76105 return None
77-
78- profile_data = json .loads (profile_json )
79106 profile_settings = profile_data .get ('settings' , profile_data ) # Backward compat
80107
81108 # Clear all current settings and load profile settings
@@ -130,7 +157,7 @@ def list_profiles():
130157 profile_name = key_str [len (f'{ PROFILES_KEY } :' ):]
131158 shortcut = name_to_shortcut .get (profile_name )
132159 if shortcut :
133- profiles_info .append (f"{ profile_name } (: { shortcut } )" )
160+ profiles_info .append (f"{ profile_name } ({ shortcut } )" )
134161 else :
135162 profiles_info .append (profile_name )
136163
0 commit comments