eve-watcher/update.py
2026-06-14 07:17:53 +00:00

95 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""One command to set up AND update the Eve watchers — `python update.py`.
This folder is a clone of the public repo
https://git.armoredarmadillo.com/brockdarnold/eve-watcher.git
so updates are just a `git pull`. Run this any time to:
1. create config.ini from the example on first run (your webhook is prefilled;
config.ini is gitignored so your edits + OCR snip survive every update),
2. pull the latest watcher code,
3. install/upgrade python deps,
4. (re)start the headless watchers.
First time on a new PC:
git clone https://git.armoredarmadillo.com/brockdarnold/eve-watcher.git
cd eve-watcher
python update.py
python eve_orehold_watcher.py --snip # one-time: aim OCR at the ore-hold bar
After that, to get my latest changes, just: python update.py
"""
import configparser
import os
import shutil
import subprocess
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
WIN = os.name == "nt"
def run(cmd, **kw):
print(f" $ {' '.join(cmd)}")
return subprocess.run(cmd, cwd=HERE, **kw)
def ensure_config():
cfg = os.path.join(HERE, "config.ini")
ex = os.path.join(HERE, "config.ini.example")
if not os.path.exists(cfg):
shutil.copyfile(ex, cfg)
print("• created config.ini from config.ini.example (webhook prefilled).")
else:
print("• config.ini already exists — leaving your settings + snip untouched.")
return cfg
def git_pull():
if not os.path.isdir(os.path.join(HERE, ".git")):
print("• not a git clone — skipping pull. To get updates in future, install "
"via:\n git clone https://git.armoredarmadillo.com/brockdarnold/"
"eve-watcher.git")
return
if run(["git", "pull", "--ff-only"]).returncode != 0:
print("! git pull failed (local edits to tracked files?). Stash or commit "
"them, then re-run. Your config.ini is safe (gitignored).")
def deps():
req = os.path.join(HERE, "requirements.txt")
if os.path.exists(req):
run([sys.executable, "-m", "pip", "install", "--quiet", "-r", req])
def restart_watchers(cfg_path):
if not WIN:
print("• non-Windows — start watchers manually (this is a Goliath/Windows tool).")
return
# stop any running watchers, then relaunch via start-all.ps1
subprocess.run(["powershell", "-NoProfile", "-Command",
"Get-Process pythonw -ErrorAction SilentlyContinue | Stop-Process -Force"],
cwd=HERE)
run(["powershell", "-ExecutionPolicy", "Bypass", "-File",
os.path.join(HERE, "start-all.ps1")])
# nudge if OCR region not snipped yet
cp = configparser.ConfigParser()
cp.read(cfg_path)
if cp.get("watcher", "mode", fallback="ocr") == "ocr" and \
not cp.get("ocr", "region", fallback="").strip():
print("\n >> ONE-TIME STEP: the OCR hold/compress/stall watcher needs its "
"region.\n Run: python eve_orehold_watcher.py --snip\n"
" (drag a box around the Ore Hold fill bar; it persists after that.)")
def main():
print("=== Eve watcher setup / update ===")
cfg = ensure_config()
git_pull()
deps()
restart_watchers(cfg)
print("\nDone. Watchers running. Stop them with: Get-Process pythonw | Stop-Process")
if __name__ == "__main__":
main()