Skip to content

Commit ed7edf5

Browse files
committed
Clean up profiles code, ready to try it
1 parent 91173c4 commit ed7edf5

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

gonotego/command_center/profile_commands.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
say = system_commands.say
99

1010

11-
@register_command('{}')
11+
@register_command(r'p(\d)')
1212
def load_profile_shortcut(shortcut):
13-
"""Load a profile using numeric shortcut (e.g., :1, :2, :3)."""
13+
"""Load a profile using numeric shortcut (e.g., :p1, :p2, :p3)."""
1414
# Check if this is a numeric shortcut
1515
if not shortcut.isdigit():
16-
return # Not a profile shortcut, let other commands handle it
16+
return # Not a profile shortcut
1717

1818
profile_name = profiles.get_profile_by_shortcut(shortcut)
1919
if profile_name is None:
20+
say(f'Profile {shortcut} not found')
2021
return # No profile mapped to this shortcut
2122

2223
result = profiles.load_profile(profile_name)

gonotego/settings-server/package-lock.json

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gonotego/settings/profiles.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,32 @@ def get_all_settings():
2929

3030

3131
def 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+
6190
def 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

Comments
 (0)