diff --git a/.gitignore b/.gitignore index cb1cdda..0c624b4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ config.yaml # dev files .idea venv +.*/ # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/config-example.yaml b/config-example.yaml index 212f15a..99859bd 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -8,6 +8,7 @@ log_level: INFO # Only one consumer can be enabled at a time, you can # delete the section for the consumer which you aren't using +# For Windows file path needs to be absolute. chia_logs: file_log_consumer: enable: true diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..28db1d3 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,24 @@ +$command = "py" +if (Get-Command python -errorAction SilentlyContinue) { + $command = "python" +} +elseif (Get-Command python3 -errorAction SilentlyContinue) { + $command = "python3" +} + +# Create virtual environment +Invoke-expression "$($command) -m venv .venv" + +# Activate the virtual environment +./.venv/Scripts/activate.ps1 + +# Update pip to latest version +Invoke-expression "$($command) -m pip install --upgrade pip" + +# Install dependencies +pip install wheel + +pip install -r requirements.txt + +# Deactivate virtual env +deactivate diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..1db090b --- /dev/null +++ b/install.sh @@ -0,0 +1,14 @@ +# Create virtual environment +python3 -m venv .venv + +# Activate virtual environment +. ./.venv/bin/activate + +# Update pip3 to latest version +python3 -m pip install --upgrade pip + +# Install dependencies +pip3 install wheel && pip3 install -r requirements.txt + +# Deactivate virtual environment +deactivate diff --git a/main.py b/main.py index c28c67a..9c23974 100644 --- a/main.py +++ b/main.py @@ -2,13 +2,14 @@ import argparse import logging import signal +import time from pathlib import Path # project from src.chia_log.handlers.daily_stats.stats_manager import StatsManager from src.chia_log.log_consumer import create_log_consumer_from_config from src.chia_log.log_handler import LogHandler -from src.config import Config +from src.config import Config, is_win_platform from src.notifier.keep_alive_monitor import KeepAliveMonitor from src.notifier.notify_manager import NotifyManager @@ -77,4 +78,12 @@ def interrupt(signal_number, frame): exit(0) signal.signal(signal.SIGINT, interrupt) - signal.pause() + + if is_win_platform: + while True: + try: + time.sleep(5) + except IOError: + pass + else: + signal.pause() diff --git a/src/chia_log/log_consumer.py b/src/chia_log/log_consumer.py index 8ce8a9e..b252afc 100644 --- a/src/chia_log/log_consumer.py +++ b/src/chia_log/log_consumer.py @@ -15,7 +15,7 @@ from typing import List, Optional # project -from src.config import check_keys +from src.config import check_keys, is_win_platform # lib import paramiko @@ -66,7 +66,13 @@ def stop(self): def _consume_loop(self): expanded_user_log_path = self._log_path.expanduser() logging.info(f"Consuming log file from {expanded_user_log_path}") - f = subprocess.Popen(["tail", "-F", expanded_user_log_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + if is_win_platform: + consume_command_args = ["powershell.exe", "get-content", expanded_user_log_path, "-tail", "1", "-wait"] + else: + consume_command_args = ["tail", "-F", expanded_user_log_path] + + f = subprocess.Popen(consume_command_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) while self._is_running: log_line = f.stdout.readline().decode(encoding="utf-8") self._notify_subscribers(log_line) diff --git a/src/config.py b/src/config.py index e40445e..f3ef0af 100644 --- a/src/config.py +++ b/src/config.py @@ -1,5 +1,6 @@ # std import logging +import sys from pathlib import Path from typing import Optional @@ -49,3 +50,6 @@ def check_keys(required_keys, config) -> bool: logging.error(f"Incompatible configuration. Missing {key} in {config}.") return False return True + +def is_win_platform() -> bool: + return sys.platform.startswith("win") diff --git a/start.ps1 b/start.ps1 new file mode 100644 index 0000000..b93a9ba --- /dev/null +++ b/start.ps1 @@ -0,0 +1,13 @@ +$command = "py" +if (Get-Command python -errorAction SilentlyContinue) { + $command = "python" +} +elseif (Get-Command python3 -errorAction SilentlyContinue) { + $command = "python3" +} + +# Activate the virtual environment +./.venv/Scripts/activate.ps1 + +# Start the ChiaDog +Invoke-expression "$($command) main.py --config config.yaml" diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..988a262 --- /dev/null +++ b/start.sh @@ -0,0 +1,5 @@ +# Activate the virtual environment +. ./.venv/bin/activate + +# Start the ChiaDog +python3 main.py --config config.yaml \ No newline at end of file