Skip to content

Commit 52491ed

Browse files
committed
feat(updater): test
Signed-off-by: Me0wo <[email protected]>
1 parent 56e46ec commit 52491ed

File tree

18 files changed

+182
-59
lines changed

18 files changed

+182
-59
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
version: 2
22
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
37
- package-ecosystem: "npm"
48
directory: "/Frontend"
59
schedule:
610
interval: "daily"
7-
- package-ecosystem: "gomod"
8-
directory: "/"
11+
- package-ecosystem: "pip"
12+
directory: "/Updater"
913
schedule:
1014
interval: "daily"

.github/workflows/codeql.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,7 @@ static/
175175
*.pem
176176

177177
# QuickNote test config
178-
config_test.yml
178+
config_test.yml
179+
180+
# QuickNote updater tags data
181+
/Updater/data/tags

Updater/config/__init__.py

Whitespace-only changes.

Updater/config/yml_loader.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from functools import lru_cache
2+
from pathlib import Path
3+
4+
import yaml
5+
from pydantic import BaseModel
6+
7+
8+
class PathConfig(BaseModel):
9+
processPath: str = "../QuickNote"
10+
tagPath: str = "./tags"
11+
12+
class ProxyConfig(BaseModel):
13+
url: str = ""
14+
15+
class Config(BaseModel):
16+
path: PathConfig = PathConfig()
17+
proxy: ProxyConfig = ProxyConfig()
18+
19+
@lru_cache()
20+
def get_config() -> Config:
21+
with open(Path(__file__).parent.parent / "./data/config.yml", "r") as f:
22+
return Config(**yaml.safe_load(f) or {})

Updater/data/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
path:
2+
processPath: ../QuickNote.exe
3+
tagPath: ./data/tags
4+
5+
proxy:
6+
url: env

Updater/fetch/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import Optional, MutableMapping
2+
3+
import requests
4+
5+
6+
def fetch_latest_release(owner: str, repo: str, proxies: Optional[MutableMapping[str, str]] = None) -> dict:
7+
from Updater.proxy.http import get_proxies
8+
proxies = proxies or get_proxies()
9+
10+
resp = requests.get(
11+
f"https://api.github.com/repos/{owner}/{repo}/releases/latest",
12+
headers={"Accept": "application/vnd.github.v3+json"},
13+
proxies=proxies
14+
)
15+
resp.raise_for_status()
16+
return resp.json()

Updater/main.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import json
2+
import time
3+
4+
from Updater.config.yml_loader import get_config
5+
from Updater.updater.runner.process import find_processes_by_path, try_terminate
6+
from Updater.updater.tag.reader import read
7+
from Updater.updater.tag.writer import write
8+
from fetch.github_release_api import fetch_latest_release
9+
from proxy.http import get_proxies
10+
11+
OWNER = "Sn0wo2"
12+
REPO = "QuickNote"
13+
INTERVAL = 5.0
14+
15+
def main():
16+
result = fetch_latest_release(OWNER, REPO, get_proxies())
17+
print(json.dumps(
18+
result,
19+
indent=2,
20+
ensure_ascii=False
21+
))
22+
tag = result.get("tag_name")
23+
if read() != tag:
24+
print("=" * 80)
25+
print(f"New tag: {tag}")
26+
27+
procs = find_processes_by_path(get_config().path.processPath)
28+
if not procs:
29+
print("No matching processes found.")
30+
for proc in procs:
31+
try_terminate(proc)
32+
33+
write(tag)
34+
35+
print("=" * 80)
36+
time.sleep(INTERVAL)
37+
38+
if __name__ == "__main__":
39+
main()

Updater/proxy/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)