WIP: logging, async processes, bluetooth keyboard & volume
This commit is contained in:
parent
9aab88f4f8
commit
9f4f3b9293
36
modeset2.py
36
modeset2.py
@ -3,13 +3,42 @@
|
|||||||
# Ferit Yiğit BALABAN <f@fybx.dev>, 2022
|
# Ferit Yiğit BALABAN <f@fybx.dev>, 2022
|
||||||
#
|
#
|
||||||
from datetime import datetime as dt
|
from datetime import datetime as dt
|
||||||
|
from subprocess import run
|
||||||
|
import asyncio
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
START_NIGHT = "22.30"
|
START_NIGHT = "22.30"
|
||||||
START_DAY = "8.20"
|
START_DAY = "8.20"
|
||||||
|
|
||||||
|
|
||||||
|
async def connect_keyboard():
|
||||||
|
command = 'bash ' + os.path.expandvars("$HOME/scripts/keyboard")
|
||||||
|
await open_subprocess(command)
|
||||||
|
|
||||||
|
|
||||||
|
async def set_volume(value: int, save_state = False):
|
||||||
|
value = 100 if value > 100 else 0 if value < 0 else value
|
||||||
|
command = f'pactl set-sink-volume @DEFAULT_SINK@ {value}'
|
||||||
|
await open_subprocess(command)
|
||||||
|
|
||||||
|
|
||||||
|
async def open_subprocess(cmd: str):
|
||||||
|
p = await asyncio.create_subprocess_shell(
|
||||||
|
cmd,
|
||||||
|
stdout=asyncio.subprocess.PIPE,
|
||||||
|
stderr=asyncio.subprocess.PIPE)
|
||||||
|
stdout, stderr = await p.communicate()
|
||||||
|
return p.returncode, stdout, stderr
|
||||||
|
|
||||||
|
|
||||||
|
def log(message: str):
|
||||||
|
with open(os.path.expandvars("$HOME/navi.log"), 'a') as f:
|
||||||
|
f.write(f"[{dt.now().strftime('%m/%d/%y-%H.%M.%S')}] {message}\n")
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def get_hour():
|
def get_hour():
|
||||||
if 0 <= dt.now().minute and dt.now().minute <= 9:
|
if 0 <= dt.now().minute and dt.now().minute <= 9:
|
||||||
return f"{dt.now().hour}.0{dt.now().minute}"
|
return f"{dt.now().hour}.0{dt.now().minute}"
|
||||||
@ -35,12 +64,17 @@ def main():
|
|||||||
sys.argv.reverse()
|
sys.argv.reverse()
|
||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
if sys.argv[0] == "--login":
|
if sys.argv[0] == "--login":
|
||||||
print("Login")
|
log("modeset2 started with \"--login\"")
|
||||||
|
asyncio.run(connect_keyboard())
|
||||||
|
asyncio.run(set_volume(0))
|
||||||
elif sys.argv[0] == "--lock":
|
elif sys.argv[0] == "--lock":
|
||||||
|
log("modeset2 started with \"--lock\"")
|
||||||
print("Lock")
|
print("Lock")
|
||||||
elif sys.argv[0] == "--unlock":
|
elif sys.argv[0] == "--unlock":
|
||||||
|
log("modeset2 started with \"--unlock\"")
|
||||||
print("Unlock")
|
print("Unlock")
|
||||||
elif sys.argv[0] == "--shutdown":
|
elif sys.argv[0] == "--shutdown":
|
||||||
|
log("modeset2 started with \"--shutdown\"")
|
||||||
print("Shutdown")
|
print("Shutdown")
|
||||||
elif len(sys.argv) == 0:
|
elif len(sys.argv) == 0:
|
||||||
print("modeset2 by fyb")
|
print("modeset2 by fyb")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user