From 4cff2d65a789510e00fe4536dbd93acf29318281 Mon Sep 17 00:00:00 2001 From: citrullux <565963@gmail.com> Date: Fri, 11 Oct 2024 00:21:08 +0300 Subject: [PATCH] unstable: environment variable for systemctl required --- README.md | 2 +- services/wthrc.service | 5 +++-- src/installer.py | 38 +++++++++++++++++--------------------- src/main.py | 6 +++++- src/server.py | 2 +- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 2c18db8..2959f5f 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,4 @@ > $ sh install.sh -После этого в браузере на localhost:8000 должны появиться данные о погоде. \ No newline at end of file +После этого в браузере на localhost:7841 должны появиться данные о погоде. \ No newline at end of file diff --git a/services/wthrc.service b/services/wthrc.service index 826b857..30956e6 100644 --- a/services/wthrc.service +++ b/services/wthrc.service @@ -2,9 +2,10 @@ Description=Weather collection service [Service] +$DIR=/home/citrullux/ModernOSWeather Type=simple -WorkingDirectory=/home/citrullux/ModernOSLabs/src -ExecStart=/usr/bin/python3 /home/citrullux/ModernOSLabs/src/main.py +WorkingDirectory=/home/citrullux/ModernOSWeather/src +ExecStart=/usr/bin/python3 /home/citrullux/ModernOSWeather/src/main.py Restart=always [Install] diff --git a/src/installer.py b/src/installer.py index 2f2b231..19ddeea 100644 --- a/src/installer.py +++ b/src/installer.py @@ -2,30 +2,26 @@ import filecmp import subprocess import os from time import sleep -from server import weather_run + from pathlib import Path -def install(parsed) -> None: - args = parsed.parse_args() - if args.install: - projectDir = Path(__file__).resolve().parent.parent - homeDir = Path(os.getenv("HOME")) - serviceDirExist = os.path.isdir(os.path.join(homeDir, ".config/systemd/user/")) - delivered = False +def install() -> None: + projectDir = Path(__file__).resolve().parent.parent + homeDir = Path(os.getenv("HOME")) + serviceDirExist = os.path.isdir(os.path.join(homeDir, ".config/systemd/user/")) + delivered = False - if serviceDirExist: - delivered = filecmp.cmp( - os.path.join(projectDir, "services/wthrc.service"), - os.path.join(homeDir, ".config/systemd/user/wthrc.service"), - shallow=True, - ) + if serviceDirExist: + delivered = filecmp.cmp( + os.path.join(projectDir, "services/wthrc.service"), + os.path.join(homeDir, ".config/systemd/user/wthrc.service"), + shallow=True, + ) - if not delivered or not serviceDirExist: - os.environ["DIR"] = str(projectDir) - subprocess.call(["sh", os.path.join(projectDir, "scripts/install.sh")]) - subprocess.call(["sh", os.path.join(projectDir, "scripts/runner.sh")]) + if not delivered or not serviceDirExist: + os.environ["DIR"] = str(projectDir) + subprocess.call(["sh", os.path.join(projectDir, "scripts/install.sh")]) + subprocess.call(["sh", os.path.join(projectDir, "scripts/runner.sh")]) - sleep(5) - else: - weather_run() + sleep(5) diff --git a/src/main.py b/src/main.py index 4bdeca3..1811eb2 100644 --- a/src/main.py +++ b/src/main.py @@ -1,7 +1,11 @@ from installer import install +from server import weather_run import argparse flags = argparse.ArgumentParser() flags.add_argument("--install", "-i", action="store_true") +args = flags.parse_args() -install(flags) +if args.install: + install() +weather_run() \ No newline at end of file diff --git a/src/server.py b/src/server.py index 2c9e01b..296f7ec 100644 --- a/src/server.py +++ b/src/server.py @@ -5,7 +5,7 @@ from weather import weather_handler def weather_run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler): - server_address = ("", int(os.getenv("PORT", "8000"))) + server_address = ("", int(os.getenv("PORT", "7841"))) httpd = server_class(server_address, WeatherHandler) httpd.serve_forever()