Skip to content

Commit ee17b53

Browse files
committed
fix(updater): import package
Signed-off-by: Me0wo <152751263+Sn0wo2@users.noreply.github.com>
1 parent 4bc2b36 commit ee17b53

File tree

9 files changed

+33
-17
lines changed

9 files changed

+33
-17
lines changed

Updater/__init__.py

Whitespace-only changes.

Updater/config/yml_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import yaml
55

6-
from Updater.config.model import Config
6+
from .model import Config
77

88

99
@lru_cache()

Updater/fetch/github_release_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import Optional, MutableMapping
22

33
import requests
4+
from proxy.http import get_proxies
45

56

67
def fetch_latest_release(owner: str, repo: str, proxies: Optional[MutableMapping[str, str]] = None) -> dict:
7-
from Updater.proxy.http import get_proxies
88
proxies = proxies or get_proxies()
99

1010
resp = requests.get(

Updater/main.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1+
import os
2+
import sys
3+
4+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
5+
if BASE_DIR not in sys.path:
6+
sys.path.insert(0, BASE_DIR)
7+
18
import json
29
import time
310
from pathlib import Path
411

5-
from Updater.config.yml_loader import get_config
6-
from Updater.updater.assets.name import get_package_name_from_current_machine
7-
from Updater.updater.downloader.temp import download_to_temp
8-
from Updater.updater.extract.extract import extract_and_replace
9-
from Updater.updater.runner.process import find_processes_by_path, try_terminate
10-
from Updater.updater.tag.reader import read
12+
from psutil import NoSuchProcess
13+
14+
from config.yml_loader import get_config
1115
from fetch.github_release_api import fetch_latest_release
1216
from proxy.http import get_proxies
17+
from updater.assets.name import get_package_name_from_current_machine
18+
from updater.downloader.temp import download_to_temp
19+
from updater.extract.extract import extract_and_replace
20+
from updater.runner.process import find_processes_by_path, try_terminate
21+
from updater.tag.reader import read
1322

1423
OWNER = "Sn0wo2"
1524
REPO = "QuickNote"
@@ -32,7 +41,12 @@ def main():
3241
if not procs:
3342
print("No matching processes found.")
3443
for proc in procs:
35-
try_terminate(proc)
44+
try:
45+
if proc.is_running():
46+
try_terminate(proc)
47+
# fiber prefork child process
48+
except (NoSuchProcess, PermissionError):
49+
pass
3650

3751
download_url = None
3852

Updater/proxy/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from functools import lru_cache
22

3-
from Updater.config.yml_loader import get_config
3+
from config.yml_loader import get_config
44

55

66
@lru_cache()

Updater/updater/extract/extract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pathlib import Path
22

3-
from Updater.updater.extract.tar_gz import _extract_tar
4-
from Updater.updater.extract.zip import _extract_zip
3+
from .tar_gz import _extract_tar
4+
from .zip import _extract_zip
55

66

77
def extract_and_replace(archive_path: Path, extract_to: Path):

Updater/updater/runner/process.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import os
22
import signal
3+
from pathlib import Path
4+
from typing import List
35

46
import psutil
57

68

7-
def find_processes_by_path(target_path):
8-
matches = []
9+
def find_processes_by_path(target_path: Path) -> list[psutil.Process]:
10+
matches: List[psutil.Process] = []
911
for proc in psutil.process_iter(['pid', 'exe', 'cmdline']):
1012
try:
1113
exe = proc.info['exe']
@@ -22,7 +24,7 @@ def try_terminate(proc):
2224
print(f"Trying to gracefully terminate PID {proc.pid} ({proc.name()})...")
2325
try:
2426
if os.name == 'nt':
25-
os.kill(proc.pid, signal.CTRL_BREAK_EVENT)
27+
proc.terminate()
2628
else:
2729
proc.send_signal(signal.SIGINT)
2830
proc.wait(timeout=5)

Updater/updater/tag/reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from Updater.config.yml_loader import get_config
1+
from config.yml_loader import get_config
22

33

44
def read():

Updater/updater/tag/writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from Updater.config.yml_loader import get_config
1+
from config.yml_loader import get_config
22

33

44
def write(tag: str):

0 commit comments

Comments
 (0)