From 87634f1f90ff21e546c0c0b5f6ab6a6ef519f83e Mon Sep 17 00:00:00 2001 From: Rhys Tyers Date: Sat, 16 Nov 2019 14:22:22 +0000 Subject: [PATCH 1/3] Add autorandr extension --- autorandr/__init__.py | 87 ++++++++++++++++++ autorandr/__pycache__/__init__.cpython-37.pyc | Bin 0 -> 2311 bytes autorandr/monitor.svg | 1 + 3 files changed, 88 insertions(+) create mode 100644 autorandr/__init__.py create mode 100644 autorandr/__pycache__/__init__.cpython-37.pyc create mode 100644 autorandr/monitor.svg diff --git a/autorandr/__init__.py b/autorandr/__init__.py new file mode 100644 index 00000000..d2dd4c08 --- /dev/null +++ b/autorandr/__init__.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- + +"""Load and save autorandr configs. + +Load and save configs. Requires autorandr to be installed. + +Synopsis: [load|save] """ + +from albertv0 import * +import os +import subprocess +from time import sleep + + +__iid__ = "PythonInterface/v0.2" +__prettyname__ = "Autorandr" +__version__ = "1.0" +__trigger__ = "ar " +__author__ = "Rhys Tyers" +__dependencies__ = ["autorandr"] + +configurations = [] + +def initialize(): + global configurations + result = subprocess.run(["autorandr", "--detected"], stdout=subprocess.PIPE) + result.stdout.decode('utf-8') + configurations = result.stdout.decode().split() + +def handleQuery(query): + if not query.isTriggered: + return + + queryList = query.string.split() + results = [] + + # Load + if queryList[0] != 'load' and 'load'.startswith(queryList[0]): + item = Item(id=__prettyname__, + icon=os.path.dirname(__file__)+"/monitor.svg", + text="Load", + subtext="Load a saved xrandr configuration", + completion=__trigger__ + 'load ', + urgency=ItemBase.Alert, + actions=[]) + results.append(item) + if queryList[0] == 'load': + for configuration in configurations: + if len(queryList) < 2 or configuration.startswith(queryList[1]): + item = Item(id=__prettyname__, + icon=os.path.dirname(__file__)+"/monitor.svg", + text="Load " + configuration, + subtext="Load the " + configuration + " xrandr configuration", + completion=__trigger__ + 'load ' + configuration, + urgency=ItemBase.Alert, + actions=[ + ProcAction(text="ProcAction", + commandline=["autorandr", "--change", configuration], + ) + ]) + results.append(item) + + # Save + if queryList[0] != 'save' and 'save'.startswith(queryList[0]): + item = Item(id=__prettyname__, + icon=os.path.dirname(__file__)+"/monitor.svg", + text="Save", + subtext="Save the current xrandr configuration", + completion=__trigger__ + 'save ', + urgency=ItemBase.Alert, + actions=[]) + results.append(item) + if queryList[0] == 'save': + item = Item(id=__prettyname__, + icon=os.path.dirname(__file__)+"/monitor.svg", + text="Save " + queryList[1], + subtext="Save the current xrandr configuration as " + queryList[1], + urgency=ItemBase.Alert, + completion=__trigger__ + 'save ', + actions=[ + ProcAction(text="ProcAction", + commandline=["autorandr", "--save", queryList[1]], + ) + ]) + results.append(item) + + return results diff --git a/autorandr/__pycache__/__init__.cpython-37.pyc b/autorandr/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..40fb1b5057845916116518895b40a7c7957e4b24 GIT binary patch literal 2311 zcma)8&2QX96rb_edc7Y>AZ?lokP#}+P?fip^wIPl+ao-3#FCvf6DJ59eLfj55h=FPm%dGmAbcRB%q=XdwdM?Z83 z`3on{9}Aez;8lA-I2jU7xs}pg9PQK^TGeO|Z5W-@nYcrj67CK??hPBfG4#1VZ1UzX z;6Y4>Ez#z!Cv@0}3G4DU@BB!HOT5dMU|i<*L(*GjKT$$<$B7EzkA*6k6sZV{xgO_P zs0GZJ7NI!SB2!78^@E_=d?5(cIG?5*hoexBMYy@M6($*&8s(EhiZSZ#fypB_?}y(g zQEi&!dW(rKJzsKCKM z#?o|N8B_BtFBDYpjc|kD;rZH~@Gj&U$3orP~eOTbUMepN+&|cB_BeG&iRjg3P!q?T`DnN}I{B489)ERk%ABQW^hf z3@OZn9C|F>6H<@RI6iRP#DVv7c-3tnnjBE zgn67m*SOoJ$u1%YHa57>Vx$F!xILwLKGmf=)%zQt_8KNo(>*xbkxB9~zQKi>_;`9usPBs%D)`G}LdrbjQcg)f6*~@GY{&XQ-h1Z2T_z{iH@RvF*gCS2}_ewyo;6bfDmhywy9hJ zZiHpS$AuRzZC$?KKnkTID!{S;M^CLYazbNrVlAMk>x5f}w&dJ8wd?sAm0Ua8)!sql z)Yr{3xYlcgJKWU)_tuDR9kgS@8&4Z2_QE>tEbQtCp4+nI-^a(g`vrMaoH%-EL7!0W z9}@M;!l^to*9mx-UE(2FIN+yM(Kh(0yx|Nz>Sf+RSXel*&6l5AF?~IP$FpzAc}6RT z_Rmz_;VUn4!ucgW-{NnBpVj}!YUR)Z{a-K9zXBd1BZ&LzbFPZEwpqu#RX|R>F;w zz@l+9G?{5Ye^*R^h?fd%UDKG#SY)HQX|Pe%%g+$mpJ5oKTRAJ6)qqe`Ub)nz33lMx zY*zXb`?2&lHb!HX#iD1)tC&#>TuuN65XOvy(HrL>(DDY-3Ytb!DMh9)^-#K~5|(bY zyX^fhrI4wx^foq7wbziV5Qn^i1S67bNY;^DLvkHRZ^g6{wOeDK;D`{2`LYdbfDW2T zt&S2sHqI7&a7;If;JcyqJYy3PMaIgNaS8_O4W3988b6BmlN1+QQFIQfF!53UK2v}v zn<-$P@mNs^07<;C#!f{h@ox8A<5q}kn$_?iQE-Yi(15E1gXp|+_!aonWEoAh;1GB! zzCzgk00e3XgiwzhkCH< znjKj36R-|dY(x=!_%P8L<7T(yhp-}jAkd7-L`WN1*q0^=PV ZM!f^Xv3yA1r)}GTwCbN{`4-5%e*t~Rl;HpX literal 0 HcmV?d00001 diff --git a/autorandr/monitor.svg b/autorandr/monitor.svg new file mode 100644 index 00000000..bc4b4567 --- /dev/null +++ b/autorandr/monitor.svg @@ -0,0 +1 @@ + \ No newline at end of file From 1c1c65e4b02c751b2a906c5d35003ccd77cb8665 Mon Sep 17 00:00:00 2001 From: Rhys Tyers Date: Tue, 29 Sep 2020 10:40:21 +0100 Subject: [PATCH 2/3] Add VPN extension --- __pycache__/vpn.cpython-37.pyc | Bin 0 -> 2106 bytes autorandr/__init__.py | 13 ++++ autorandr/__pycache__/__init__.cpython-37.pyc | Bin 2311 -> 0 bytes vpn.py | 65 ++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 __pycache__/vpn.cpython-37.pyc delete mode 100644 autorandr/__pycache__/__init__.cpython-37.pyc create mode 100644 vpn.py diff --git a/__pycache__/vpn.cpython-37.pyc b/__pycache__/vpn.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..93168186f845295b4d9352d890b8448d8678d677 GIT binary patch literal 2106 zcmZuy&u()Tpu3s;Ur;C=_UmgrZbQQ)wk?Ii88V@p{+H zj1yuxmj zVMSKLs;u^SSW~mIcF4oJs+&zYi{6oSIVb0P;!uQh@{BzDjD_>^oLoSEMxK`!(4UnT z^e(V)X{sVyg|FRg%t7Njo0J3KqWsQQGTA-Tq`@ZQu6OBo(4mu@yhRx*7R$Cch$-7)zyJv8dC3zYMUI021|Lgj%3rcS zMB+=g&<=o<^ngiu%6p{)*8-!dc**2UK95yX$6^=IbEdAWybwJO+`JsE(3R<45{mI? zQoVOfc$)^3`TPGV08LSb6{LA39hZ(-S{3HrWY`qdGNHWMs(%(Ld=8B zhW0Qb%Qf_G$wDDfX;3pO5YIsteG`)Fn^qixIM5w^<5#ww7x*)O z%I~v7et@@Dif62_)>)52cUMn2CX6YyhK}rkhmWu1?$|5-8XI>6^#f0XQ@@KR?s}2t zhLd^5YLszSiqk!%b7VjX(Ok}vqG#~QSn2(Ds2o*R;>cKH!R@c*gQrzxTvn7D&>97V&;%8}Uw z6f&zuWP}kPiS%Lt7H-_ o@|gdZ!2U|{BHqrqNo!rl$8FIZ7cXG(^DqWY)E&R(&-tZ)0a>#NkN^Mx literal 0 HcmV?d00001 diff --git a/autorandr/__init__.py b/autorandr/__init__.py index d2dd4c08..f29eb418 100644 --- a/autorandr/__init__.py +++ b/autorandr/__init__.py @@ -84,4 +84,17 @@ def handleQuery(query): ]) results.append(item) + # refresh + if 'refresh'.startswith(queryList[0]): + item = Item(id=__prettyname__, + icon=os.path.dirname(__file__)+"/monitor.svg", + text="Refresh", + subtext="Refresh xrandr configuration", + completion=__trigger__ + 'refresh ', + urgency=ItemBase.Alert, + actions=[ + FuncAction(initialize) + ]) + results.append(item) + return results diff --git a/autorandr/__pycache__/__init__.cpython-37.pyc b/autorandr/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 40fb1b5057845916116518895b40a7c7957e4b24..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2311 zcma)8&2QX96rb_edc7Y>AZ?lokP#}+P?fip^wIPl+ao-3#FCvf6DJ59eLfj55h=FPm%dGmAbcRB%q=XdwdM?Z83 z`3on{9}Aez;8lA-I2jU7xs}pg9PQK^TGeO|Z5W-@nYcrj67CK??hPBfG4#1VZ1UzX z;6Y4>Ez#z!Cv@0}3G4DU@BB!HOT5dMU|i<*L(*GjKT$$<$B7EzkA*6k6sZV{xgO_P zs0GZJ7NI!SB2!78^@E_=d?5(cIG?5*hoexBMYy@M6($*&8s(EhiZSZ#fypB_?}y(g zQEi&!dW(rKJzsKCKM z#?o|N8B_BtFBDYpjc|kD;rZH~@Gj&U$3orP~eOTbUMepN+&|cB_BeG&iRjg3P!q?T`DnN}I{B489)ERk%ABQW^hf z3@OZn9C|F>6H<@RI6iRP#DVv7c-3tnnjBE zgn67m*SOoJ$u1%YHa57>Vx$F!xILwLKGmf=)%zQt_8KNo(>*xbkxB9~zQKi>_;`9usPBs%D)`G}LdrbjQcg)f6*~@GY{&XQ-h1Z2T_z{iH@RvF*gCS2}_ewyo;6bfDmhywy9hJ zZiHpS$AuRzZC$?KKnkTID!{S;M^CLYazbNrVlAMk>x5f}w&dJ8wd?sAm0Ua8)!sql z)Yr{3xYlcgJKWU)_tuDR9kgS@8&4Z2_QE>tEbQtCp4+nI-^a(g`vrMaoH%-EL7!0W z9}@M;!l^to*9mx-UE(2FIN+yM(Kh(0yx|Nz>Sf+RSXel*&6l5AF?~IP$FpzAc}6RT z_Rmz_;VUn4!ucgW-{NnBpVj}!YUR)Z{a-K9zXBd1BZ&LzbFPZEwpqu#RX|R>F;w zz@l+9G?{5Ye^*R^h?fd%UDKG#SY)HQX|Pe%%g+$mpJ5oKTRAJ6)qqe`Ub)nz33lMx zY*zXb`?2&lHb!HX#iD1)tC&#>TuuN65XOvy(HrL>(DDY-3Ytb!DMh9)^-#K~5|(bY zyX^fhrI4wx^foq7wbziV5Qn^i1S67bNY;^DLvkHRZ^g6{wOeDK;D`{2`LYdbfDW2T zt&S2sHqI7&a7;If;JcyqJYy3PMaIgNaS8_O4W3988b6BmlN1+QQFIQfF!53UK2v}v zn<-$P@mNs^07<;C#!f{h@ox8A<5q}kn$_?iQE-Yi(15E1gXp|+_!aonWEoAh;1GB! zzCzgk00e3XgiwzhkCH< znjKj36R-|dY(x=!_%P8L<7T(yhp-}jAkd7-L`WN1*q0^=PV ZM!f^Xv3yA1r)}GTwCbN{`4-5%e*t~Rl;HpX diff --git a/vpn.py b/vpn.py new file mode 100644 index 00000000..97d6e4ab --- /dev/null +++ b/vpn.py @@ -0,0 +1,65 @@ +"""VPN Extension + +Connect or disconnect from a network manager VPN profile""" + + +import subprocess +from collections import namedtuple +from albertv0 import * +from shutil import which + + +__iid__ = "PythonInterface/v0.2" +__prettyname__ = "VPN" +__version__ = "1.0" +__trigger__ = "vpn " +__author__ = "janeklb" +__dependencies__ = ['nmcli'] + + +iconPath = iconLookup('network-wireless') +if not iconPath: + iconPath = ":python_module" + +VPNConnection = namedtuple('VPNConnection', ['name', 'connected']) + + +def getVPNConnections(): + consStr = subprocess.check_output( + 'nmcli -t connection show', + shell=True, + encoding='UTF-8' + ) + for conStr in consStr.splitlines(): + con = conStr.split(':') + if con[2] == 'vpn': + yield VPNConnection(name=con[0], connected=con[3] != '') + + +def buildItem(con): + name = con.name + command = 'down' if con.connected else 'up' + text = f'Connect to {name}' if command == 'up' else f'Disconnect from {name}' + commandline = ['nmcli', 'connection', command, 'id', name] + return Item( + id=f'vpn-{command}-{name}', + text=name, + subtext=text, + icon=iconPath, + completion=name, + actions=[ ProcAction(text=text, commandline=commandline) ] + ) + + +def initialize(): + if which('nmcli') is None: + raise Exception("'nmcli' is not in $PATH") + + +def handleQuery(query): + if query.isValid and query.isTriggered: + connections = getVPNConnections() + if query.string: + connections = [ con for con in connections if query.string.lower() in con.name.lower() ] + return [ buildItem(con) for con in connections ] + return [] From 4dafb829d3d90e05347340c96022212605a32ad3 Mon Sep 17 00:00:00 2001 From: Rhys Tyers Date: Tue, 29 Sep 2020 10:42:55 +0100 Subject: [PATCH 3/3] Add gitignore --- .gitignore | 1 + __pycache__/vpn.cpython-37.pyc | Bin 2106 -> 0 bytes 2 files changed, 1 insertion(+) create mode 100644 .gitignore delete mode 100644 __pycache__/vpn.cpython-37.pyc diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..bee8a64b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/__pycache__/vpn.cpython-37.pyc b/__pycache__/vpn.cpython-37.pyc deleted file mode 100644 index 93168186f845295b4d9352d890b8448d8678d677..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2106 zcmZuy&u()Tpu3s;Ur;C=_UmgrZbQQ)wk?Ii88V@p{+H zj1yuxmj zVMSKLs;u^SSW~mIcF4oJs+&zYi{6oSIVb0P;!uQh@{BzDjD_>^oLoSEMxK`!(4UnT z^e(V)X{sVyg|FRg%t7Njo0J3KqWsQQGTA-Tq`@ZQu6OBo(4mu@yhRx*7R$Cch$-7)zyJv8dC3zYMUI021|Lgj%3rcS zMB+=g&<=o<^ngiu%6p{)*8-!dc**2UK95yX$6^=IbEdAWybwJO+`JsE(3R<45{mI? zQoVOfc$)^3`TPGV08LSb6{LA39hZ(-S{3HrWY`qdGNHWMs(%(Ld=8B zhW0Qb%Qf_G$wDDfX;3pO5YIsteG`)Fn^qixIM5w^<5#ww7x*)O z%I~v7et@@Dif62_)>)52cUMn2CX6YyhK}rkhmWu1?$|5-8XI>6^#f0XQ@@KR?s}2t zhLd^5YLszSiqk!%b7VjX(Ok}vqG#~QSn2(Ds2o*R;>cKH!R@c*gQrzxTvn7D&>97V&;%8}Uw z6f&zuWP}kPiS%Lt7H-_ o@|gdZ!2U|{BHqrqNo!rl$8FIZ7cXG(^DqWY)E&R(&-tZ)0a>#NkN^Mx