Diversos canvis de configuració
This commit is contained in:
@@ -40,7 +40,7 @@ monitor-strict = false
|
||||
bottom = false
|
||||
fixed-center = true
|
||||
width = 100%
|
||||
height = 20
|
||||
height = 30
|
||||
;offset-x = 1%
|
||||
;offset-y = 1%
|
||||
|
||||
@@ -68,11 +68,11 @@ module-margin-left = 0
|
||||
module-margin-right = 0
|
||||
|
||||
;https://github.com/jaagr/polybar/wiki/Fonts
|
||||
font-0 = "UbuntuMono Nerd Font Mono:style=Regular:size=10;2"
|
||||
font-1 = "UbuntuMono Nerd Font:size=16;3"
|
||||
font-2 = "Font Awesome 5 Free:style=Regular:pixelsize=8;1"
|
||||
font-3 = "Font Awesome 5 Free:style=Solid:pixelsize=8;1"
|
||||
font-4 = "Font Awesome 5 Brands:pixelsize=8;1"
|
||||
font-0 = "Iosevka:style=Regular:size=15;2"
|
||||
font-1 = "Iosevka:size=16;3"
|
||||
font-2 = "Iosevka:style=Regular:pixelsize=10;1"
|
||||
font-3 = "Iosevka:style=Solid:pixelsize=10;1"
|
||||
font-4 = "Iosevka:pixelsize=10;1"
|
||||
|
||||
modules-left = i3 spotify1
|
||||
modules-center = date
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import re
|
||||
import subprocess
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
APListItem = namedtuple('APListItem', ('active', 'ssid', 'mode', 'channel', 'rate', 'signal', 'bars', 'security'))
|
||||
APListItem = namedtuple('APListItem', ('active', 'bssid', 'ssid', 'mode', 'channel', 'rate', 'signal', 'bars',
|
||||
'security'))
|
||||
ConListItem = namedtuple('ConListItem', ('name', 'uuid', 'type', 'device'))
|
||||
|
||||
def build_ap_items(output):
|
||||
return map(lambda line: APListItem(*map(lambda entry: entry.replace('\\:', ':'), line)),
|
||||
map(lambda line: re.split(r'(?<!\\):', line),
|
||||
filter(None, output.split('\n'))))
|
||||
|
||||
def build_con_items(output):
|
||||
return map(lambda line: ConListItem(*map(lambda entry: entry.replace('\\:', ':'), line)),
|
||||
map(lambda line: re.split(r'(?<!\\):', line),
|
||||
filter(None, output.split('\n'))))
|
||||
|
||||
|
||||
# ---------- ACTIONS ----------
|
||||
Action = namedtuple('Action', ('action', 'item'))
|
||||
|
||||
@@ -32,6 +45,7 @@ def format_action(action):
|
||||
if action.action == ACT_DISCONNECT_WLAN:
|
||||
return '[dis] ' + WLAN_ITEM_FORMAT.format(bars=item.bars, signal=item.signal, ssid=item.ssid, rate=item.rate)
|
||||
|
||||
|
||||
def get_command(action):
|
||||
item = action.item
|
||||
if action.action == ACT_CONNECT_VPN:
|
||||
@@ -43,23 +57,21 @@ def get_command(action):
|
||||
if action.action == ACT_DISCONNECT_WLAN:
|
||||
return ['nmcli', 'connection', 'down', item.ssid], None
|
||||
|
||||
|
||||
# ---------- BEGINNING OF SCRIPT ----------
|
||||
|
||||
|
||||
# Get available wifi APs with nmcli
|
||||
list_aps_command = ['nmcli', '-t', 'device', 'wifi', 'list']
|
||||
list_aps_result = subprocess.run(list_aps_command, stdout=subprocess.PIPE)
|
||||
list_aps_output = list_aps_result.stdout.decode('utf-8')
|
||||
try:
|
||||
nm_items = [APListItem(*line.split(':')) for line in list_aps_output.split('\n') if line]
|
||||
except Exception:
|
||||
print([line.split(':') for line in list_aps_output.split('\n') if line])
|
||||
raise
|
||||
nm_items = list(build_ap_items(list_aps_output))
|
||||
|
||||
# Get VPN status
|
||||
list_con_command = ['nmcli', '-t', 'connection', 'show']
|
||||
list_con_result = subprocess.run(list_con_command, stdout=subprocess.PIPE)
|
||||
list_con_output = list_con_result.stdout.decode('utf-8')
|
||||
con_items = [ConListItem(*line.split(':')) for line in list_con_output.split('\n') if line]
|
||||
con_items = list(build_con_items(list_con_output))
|
||||
|
||||
available_vpns = [item for item in con_items if item.type == 'vpn' and item.device.strip() == '']
|
||||
active_vpns = [item for item in con_items if item.type == 'vpn' and item.device.strip() != '']
|
||||
@@ -115,4 +127,3 @@ if connect_result.returncode == 10:
|
||||
connect_result = subprocess.run(fallback_command)
|
||||
|
||||
exit(connect_result.returncode)
|
||||
|
||||
|
||||
@@ -1,29 +1,40 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import time
|
||||
import re
|
||||
import subprocess
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
APListItem = namedtuple('APListItem', ('active', 'ssid', 'mode', 'channel', 'rate', 'signal', 'bars', 'security'))
|
||||
APListItem = namedtuple('APListItem', ('active', 'bssid', 'ssid', 'mode', 'channel', 'rate', 'signal', 'bars',
|
||||
'security'))
|
||||
ConListItem = namedtuple('ConListItem', ('name', 'uuid', 'type', 'device'))
|
||||
|
||||
|
||||
def build_ap_items(output):
|
||||
return map(lambda line: APListItem(*map(lambda entry: entry.replace('\\:', ':'), line)),
|
||||
map(lambda line: re.split(r'(?<!\\):', line),
|
||||
filter(None, output.split('\n'))))
|
||||
|
||||
def build_con_items(output):
|
||||
return map(lambda line: ConListItem(*map(lambda entry: entry.replace('\\:', ':'), line)),
|
||||
map(lambda line: re.split(r'(?<!\\):', line),
|
||||
filter(None, output.split('\n'))))
|
||||
|
||||
|
||||
if True:
|
||||
# Get available wifi APs with nmcli
|
||||
list_aps_command = ['nmcli', '-t', 'device', 'wifi', 'list']
|
||||
list_aps_result = subprocess.run(list_aps_command, stdout=subprocess.PIPE)
|
||||
list_aps_output = list_aps_result.stdout.decode('utf-8')
|
||||
nm_items = [APListItem(*line.split(':')) for line in list_aps_output.split('\n') if line]
|
||||
nm_items = list(build_ap_items(list_aps_output))
|
||||
|
||||
active_items = [item for item in nm_items if item.active == '*']
|
||||
|
||||
|
||||
# Get VPN status
|
||||
# # Get VPN status
|
||||
list_con_command = ['nmcli', '-t', 'connection', 'show']
|
||||
list_con_result = subprocess.run(list_con_command, stdout=subprocess.PIPE)
|
||||
list_con_output = list_con_result.stdout.decode('utf-8')
|
||||
con_items = [ConListItem(*line.split(':')) for line in list_con_output.split('\n') if line]
|
||||
con_items = list(build_con_items(list_con_output))
|
||||
|
||||
active_vpn = [item for item in con_items if item.type == 'vpn' and item.device.strip() != '']
|
||||
|
||||
@@ -34,6 +45,4 @@ if True:
|
||||
wifi_status = 'disconnected'
|
||||
|
||||
vps_status = '[VPN]' if active_vpn else ''
|
||||
|
||||
print(''.join([wifi_status, vps_status]).strip())
|
||||
# time.sleep(3)
|
||||
|
||||
Reference in New Issue
Block a user