рефакторинг

This commit is contained in:
Arthur 2022-06-29 18:47:58 +05:00
parent 13190c0e73
commit eaa3c99b04
3 changed files with 12 additions and 8 deletions

Binary file not shown.

15
func.py
View File

@ -1,9 +1,7 @@
import os import os
import random import random
from apscheduler.schedulers.background import BlockingScheduler PATH = '/home/arthur/img/Wallpapers/wallpyper/'# path to media (wallpaper)
PATH = '/home/arthur/img/Wallpapers/wallpyper/'# path to media
files = os.listdir(PATH) files = os.listdir(PATH)
def run(command,output=False): def run(command,output=False):
@ -14,14 +12,19 @@ def run(command,output=False):
os.system(command + devNull) os.system(command + devNull)
def kill(): def kill():
with open('/tmp/wallpyper','r') as file: '''
back4.sh will output artifacts if run more 2 processes
It function read PID in /tmp/back4.sh.pid, and kill process.
'''
with open('/tmp/back4.sh.pid','r') as file:
for pid in file: for pid in file:
run(f'kill {pid}') run(f'kill {pid}')
def setWallPeper(): def setWallPaper():
media = random.choices(files)[0] media = random.choices(files)[0]
if media[-4:] != '.gif': if media[-4:] != '.gif':
run(f"feh --bg-scale {PATH}{media}") run(f"feh --bg-scale {PATH}{media}")
else: else:
run(f"back4.sh auto {PATH}{media} & echo $! > /tmp/wallpyper",True) run(f"back4.sh auto {PATH}{media} & echo $! > /tmp/back4.sh.pid",True)
# > tmp/back4.sh.pid write PID for kill()

View File

@ -1,14 +1,15 @@
#!/usr/bin/python3 #!/usr/bin/python3
from apscheduler.schedulers.background import BlockingScheduler
from func import * from func import *
def start(): def start():
try: try:
kill() kill()
except FileNotFoundError: except FileNotFoundError:
setWallPeper() setWallPaper()
setWallPeper() setWallPaper()
if __name__ == '__main__': if __name__ == '__main__':
start() start()