Skip to content

Commit d0141e5

Browse files
committed
Fix indentation to use 2 spaces to match surrounding code
1 parent 307b22a commit d0141e5

File tree

2 files changed

+361
-361
lines changed

2 files changed

+361
-361
lines changed

gonotego/command_center/wifi_commands.py

Lines changed: 132 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -11,169 +11,169 @@
1111
@register_command('wifi {} {}')
1212
@register_command('wpa {} {}')
1313
def add_wpa_wifi(ssid, psk):
14-
if '"' in ssid or '"' in psk:
15-
say('WiFi not set.')
16-
return
17-
18-
# Load existing networks
19-
networks = wifi.get_networks()
20-
21-
# Check if this network already exists
22-
for network in networks:
23-
if network.get('ssid') == ssid:
24-
network['psk'] = psk
25-
break
26-
else:
27-
# Network doesn't exist, add it
28-
networks.append({'ssid': ssid, 'psk': psk})
29-
30-
# Save updated networks
31-
wifi.save_networks(networks)
32-
33-
# Update NetworkManager connections
34-
if wifi.update_network_connections():
35-
wifi.reconfigure_wifi()
36-
say(f'WiFi network {ssid} added.')
37-
else:
38-
say('Failed to update WiFi configuration.')
14+
if '"' in ssid or '"' in psk:
15+
say('WiFi not set.')
16+
return
17+
18+
# Load existing networks
19+
networks = wifi.get_networks()
20+
21+
# Check if this network already exists
22+
for network in networks:
23+
if network.get('ssid') == ssid:
24+
network['psk'] = psk
25+
break
26+
else:
27+
# Network doesn't exist, add it
28+
networks.append({'ssid': ssid, 'psk': psk})
29+
30+
# Save updated networks
31+
wifi.save_networks(networks)
32+
33+
# Update NetworkManager connections
34+
if wifi.update_network_connections():
35+
wifi.reconfigure_wifi()
36+
say(f'WiFi network {ssid} added.')
37+
else:
38+
say('Failed to update WiFi configuration.')
3939

4040

4141
@register_command('wifi {}')
4242
def add_wifi_no_psk(ssid):
43-
if '"' in ssid:
44-
say('WiFi not set.')
45-
return
46-
47-
# Load existing networks
48-
networks = wifi.get_networks()
49-
50-
# Check if this network already exists
51-
for network in networks:
52-
if network.get('ssid') == ssid:
53-
network.pop('psk', None) # Remove password if it exists
54-
break
55-
else:
56-
# Network doesn't exist, add it
57-
networks.append({'ssid': ssid})
58-
59-
# Save updated networks
60-
wifi.save_networks(networks)
61-
62-
# Update NetworkManager connections
63-
if wifi.update_network_connections():
64-
wifi.reconfigure_wifi()
65-
say(f'Open WiFi network {ssid} added.')
66-
else:
67-
say('Failed to update WiFi configuration.')
43+
if '"' in ssid:
44+
say('WiFi not set.')
45+
return
46+
47+
# Load existing networks
48+
networks = wifi.get_networks()
49+
50+
# Check if this network already exists
51+
for network in networks:
52+
if network.get('ssid') == ssid:
53+
network.pop('psk', None) # Remove password if it exists
54+
break
55+
else:
56+
# Network doesn't exist, add it
57+
networks.append({'ssid': ssid})
58+
59+
# Save updated networks
60+
wifi.save_networks(networks)
61+
62+
# Update NetworkManager connections
63+
if wifi.update_network_connections():
64+
wifi.reconfigure_wifi()
65+
say(f'Open WiFi network {ssid} added.')
66+
else:
67+
say('Failed to update WiFi configuration.')
6868

6969

7070
@register_command('wifi-list')
7171
def list_wifi_networks():
72-
networks = wifi.get_networks()
73-
if not networks:
74-
say('No WiFi networks configured.')
75-
return
76-
77-
network_list = [f"{i+1}. {network['ssid']}" for i, network in enumerate(networks)]
78-
say('Configured WiFi networks: ' + ', '.join(network_list))
72+
networks = wifi.get_networks()
73+
if not networks:
74+
say('No WiFi networks configured.')
75+
return
76+
77+
network_list = [f"{i+1}. {network['ssid']}" for i, network in enumerate(networks)]
78+
say('Configured WiFi networks: ' + ', '.join(network_list))
7979

8080

8181
@register_command('wifi-migrate')
8282
def migrate_wifi_networks():
83-
"""Migrate existing networks from wpa_supplicant.conf to NetworkManager."""
84-
networks = wifi.migrate_networks_from_wpa_supplicant()
83+
"""Migrate existing networks from wpa_supplicant.conf to NetworkManager."""
84+
networks = wifi.migrate_networks_from_wpa_supplicant()
85+
86+
if networks is None:
87+
say('WiFi configuration file not found or error reading it.')
88+
return
8589

86-
if networks is None:
87-
say('WiFi configuration file not found or error reading it.')
88-
return
89-
90-
# Save the extracted networks to Redis
91-
if networks:
92-
wifi.save_networks(networks)
93-
say(f'Migrated {len(networks)} WiFi networks to settings.')
94-
95-
# Update NetworkManager connections
96-
wifi.update_network_connections()
97-
wifi.reconfigure_wifi()
98-
else:
99-
say('No WiFi networks found to migrate.')
90+
# Save the extracted networks to Redis
91+
if networks:
92+
wifi.save_networks(networks)
93+
say(f'Migrated {len(networks)} WiFi networks to settings.')
94+
95+
# Update NetworkManager connections
96+
wifi.update_network_connections()
97+
wifi.reconfigure_wifi()
98+
else:
99+
say('No WiFi networks found to migrate.')
100100

101101

102102
@register_command('wifi-nm-migrate')
103103
def migrate_from_networkmanager():
104-
"""Migrate existing NetworkManager connections to Go Note Go settings."""
105-
networks = wifi.migrate_from_networkmanger()
104+
"""Migrate existing NetworkManager connections to Go Note Go settings."""
105+
networks = wifi.migrate_from_networkmanger()
106+
107+
if networks is None:
108+
say('Error reading NetworkManager connections.')
109+
return
106110

107-
if networks is None:
108-
say('Error reading NetworkManager connections.')
109-
return
110-
111-
# Save the extracted networks to Redis
112-
if networks:
113-
wifi.save_networks(networks)
114-
say(f'Migrated {len(networks)} WiFi networks from NetworkManager to settings.')
115-
else:
116-
say('No WiFi networks found to migrate.')
111+
# Save the extracted networks to Redis
112+
if networks:
113+
wifi.save_networks(networks)
114+
say(f'Migrated {len(networks)} WiFi networks from NetworkManager to settings.')
115+
else:
116+
say('No WiFi networks found to migrate.')
117117

118118

119119
@register_command('wifi-remove {}')
120120
def remove_wifi_network(ssid):
121-
networks = wifi.get_networks()
122-
initial_count = len(networks)
123-
124-
# Remove networks with matching SSID
125-
networks = [network for network in networks if network.get('ssid') != ssid]
121+
networks = wifi.get_networks()
122+
initial_count = len(networks)
123+
124+
# Remove networks with matching SSID
125+
networks = [network for network in networks if network.get('ssid') != ssid]
126+
127+
if len(networks) < initial_count:
128+
# Save updated networks
129+
wifi.save_networks(networks)
126130

127-
if len(networks) < initial_count:
128-
# Save updated networks
129-
wifi.save_networks(networks)
130-
131-
# Update NetworkManager connections
132-
if wifi.update_network_connections():
133-
wifi.reconfigure_wifi()
134-
say(f'WiFi network {ssid} removed.')
135-
else:
136-
say('Failed to update WiFi configuration.')
131+
# Update NetworkManager connections
132+
if wifi.update_network_connections():
133+
wifi.reconfigure_wifi()
134+
say(f'WiFi network {ssid} removed.')
137135
else:
138-
say(f'WiFi network {ssid} not found.')
136+
say('Failed to update WiFi configuration.')
137+
else:
138+
say(f'WiFi network {ssid} not found.')
139139

140140

141141
@register_command('reconnect')
142142
@register_command('wifi-refresh')
143143
@register_command('wifi-reconfigure')
144144
def reconfigure_wifi():
145-
wifi.reconfigure_wifi()
145+
wifi.reconfigure_wifi()
146146

147147

148148
@register_command('wifi-scan')
149149
def scan_wifi_networks():
150-
"""Scan for available WiFi networks."""
151-
try:
152-
# Ensure the WiFi adapter is on
153-
shell('sudo nmcli radio wifi on')
154-
155-
# Scan for networks
156-
result = shell('nmcli -t -f SSID,SIGNAL,SECURITY device wifi list')
157-
158-
networks = []
159-
for line in result.stdout.strip().split('\n'):
160-
if line:
161-
parts = line.split(':', 2)
162-
if len(parts) >= 3 and parts[0]: # Ensure SSID is not empty
163-
ssid, signal, security = parts
164-
networks.append((ssid, int(signal), security))
165-
166-
# Sort by signal strength (descending)
167-
networks.sort(key=lambda x: x[1], reverse=True)
168-
169-
# Take the top 5 networks
170-
top_networks = networks[:5]
171-
172-
if top_networks:
173-
network_list = [f"{i+1}. {ssid} ({signal}%)"
174-
for i, (ssid, signal, _) in enumerate(top_networks)]
175-
say('Available WiFi networks: ' + ', '.join(network_list))
176-
else:
177-
say('No WiFi networks found.')
178-
except Exception as e:
179-
say(f'Error scanning for WiFi networks: {str(e)}')
150+
"""Scan for available WiFi networks."""
151+
try:
152+
# Ensure the WiFi adapter is on
153+
shell('sudo nmcli radio wifi on')
154+
155+
# Scan for networks
156+
result = shell('nmcli -t -f SSID,SIGNAL,SECURITY device wifi list')
157+
158+
networks = []
159+
for line in result.stdout.strip().split('\n'):
160+
if line:
161+
parts = line.split(':', 2)
162+
if len(parts) >= 3 and parts[0]: # Ensure SSID is not empty
163+
ssid, signal, security = parts
164+
networks.append((ssid, int(signal), security))
165+
166+
# Sort by signal strength (descending)
167+
networks.sort(key=lambda x: x[1], reverse=True)
168+
169+
# Take the top 5 networks
170+
top_networks = networks[:5]
171+
172+
if top_networks:
173+
network_list = [f"{i+1}. {ssid} ({signal}%)"
174+
for i, (ssid, signal, _) in enumerate(top_networks)]
175+
say('Available WiFi networks: ' + ', '.join(network_list))
176+
else:
177+
say('No WiFi networks found.')
178+
except Exception as e:
179+
say(f'Error scanning for WiFi networks: {str(e)}')

0 commit comments

Comments
 (0)