-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcheck.py
More file actions
67 lines (45 loc) · 1.54 KB
/
check.py
File metadata and controls
67 lines (45 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import json
import os
from loguru import logger
from xcoder import run
from xcoder.config import config
from xcoder.features.update.download import download_update
from xcoder.localization import locale
def get_run_output(command: str):
import tempfile
temp_filename = tempfile.mktemp(".temp")
del tempfile
run(command, temp_filename)
with open(temp_filename) as f:
file_data = f.read()
os.remove(temp_filename)
return file_data
def get_pip_info(outdated: bool = False) -> list:
output = get_run_output(
f"pip --disable-pip-version-check list {'-o' if outdated else ''}"
)
output = output.splitlines()
output = output[2:]
packages = [package.split() for package in output]
return packages
def get_tags(owner: str, repo: str):
api_url = "https://api.github.com"
import urllib.request
tags = json.loads(
urllib.request.urlopen(api_url + f"/repos/{owner}/{repo}/tags").read().decode()
)
tags = [
{key: v for key, v in tag.items() if key in ["name", "zipball_url"]}
for tag in tags
]
return tags
def check_update():
tags = get_tags(config.repo_owner, config.repo_name)
if len(tags) > 0:
latest_tag = tags[0]
latest_tag_name = latest_tag["name"][1:] # clear char 'v' at string start
logger.info(locale.check_update)
if config.version != latest_tag_name:
logger.error(locale.not_latest)
logger.info(locale.update_downloading)
download_update(latest_tag["zipball_url"])