-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathversion_check.py
82 lines (69 loc) · 3.55 KB
/
version_check.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from utils import *
from datetime import datetime, timezone, timedelta
from settings import parakit_settings
from version import VERSION_DATE
try:
import requests
except ImportError as e:
if 'OpenSSL' in str(e):
print(bright("Version-checker:"), f"Error while importing requests module (outdated OpenSSL version).")
print(color("You are most likely running ParaKit on an unsupported Python version. We highly recommend updating Python.", 'red'))
print(color("See above warning for more information.", 'red'))
else:
print(bright("Version-checker:"), f"Error while importing requests module ({e}).")
exit()
except KeyboardInterrupt:
exit()
try:
_commits_response = requests.get('https://api.github.com/repos/Guy-L/parakit/commits?sha=master&per_page=100')
except KeyboardInterrupt:
exit()
except Exception as e:
print(bright("Version-checker:"), f"Failed to communicate with GitHub ({type(e).__name__}).")
exit()
try:
_commits_response.raise_for_status()
except requests.exceptions.HTTPError as e:
print(bright("Version-checker:"), f"HTTP error occurred: {e}")
exit()
_commits = _commits_response.json()
_latest_version_date = datetime.strptime(_commits[0]['commit']['committer']['date'], '%Y-%m-%dT%H:%M:%SZ').replace(tzinfo=timezone.utc)
if _latest_version_date > VERSION_DATE:
if parakit_settings['minimize_version_checker']:
new_commits = 0
for commit in _commits:
commit_date = datetime.strptime(commit['commit']['committer']['date'], '%Y-%m-%dT%H:%M:%SZ').replace(tzinfo=timezone.utc)
if commit_date > VERSION_DATE:
new_commits += 1
print(separator)
print(color(bright("A new version is available! ") + f"({new_commits} new change{'s' if new_commits > 1 else ''})", 'green'))
else:
new_commit_list = []
new_commits = 0
max_commits = 6
max_commit_msg_len = 75
for commit in _commits:
commit_date = datetime.strptime(commit['commit']['committer']['date'], '%Y-%m-%dT%H:%M:%SZ').replace(tzinfo=timezone.utc)
if commit_date > VERSION_DATE:
new_commits += 1
if len(new_commit_list) < max_commits:
commit_msg = commit['commit']['message']
if len(commit_msg) > max_commit_msg_len:
commit_msg = commit_msg[:max_commit_msg_len] + '...'
new_commit_list.append(bp + bright(f" [{commit_date.strftime('%Y-%m-%d %H:%M')} UTC] ") + commit_msg)
print(separator)
s = ('s' if new_commits > 1 else '')
print(color(bright("A new version is available! ") + f"({new_commits} new change{s})", 'green'))
print(underline(bright(f'New change{s}:')))
print("\n".join(new_commit_list))
if new_commits >= max_commits:
print(bp, italics(f"... and {'much ' if new_commits > 12 else ''}more!"))
if new_commits >= 3:
print()
print(bright("ParaKit is always improving. We recommend you update now."))
print(f"- If you installed with Git, simply enter \033[30;47mgit pull\033[0m.")
print(f"- If you installed by downloading the project files without")
print(f" Git (i.e. Code -> Download ZIP), you should do so again.")
print(f"- Either way, because of the project's current setup,")
print(f" you may need to resolve conflicts in {italics('analysis.py')} or")
print(f" {italics('settings.py')}. {darker('There are plans to address this soon.')}")