This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
check_for_updates.py
77 lines (60 loc) · 2.63 KB
/
check_for_updates.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
import locale
import re
import time
import urllib
from urllib.request import urlopen
from bs4 import BeautifulSoup
from PyQt5.QtCore import QThread, pyqtSignal
from _platform import get_platform
class CheckForUpdates(QThread):
new_version_obtained = pyqtSignal('PyQt_PyObject')
def __init__(self, parent):
QThread.__init__(self)
self.parent = parent
self.is_running = True
self.download_url = None
def run(self):
platform = get_platform()
while self.is_running:
try:
self.download_url = self.get_download_url()
commit = self.download_url.split('-',)[2]
new_version = True
if self.parent.layouts:
if (commit in self.parent.layouts[0].git or commit in self.parent.progressBar.text()):
new_version = False
if new_version:
datetime = self.get_commit_datetime(commit)
if platform == 'Windows':
locale.setlocale(locale.LC_ALL, 'eng_usa')
elif platform == 'Linux':
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
self.strptime = time.strptime(
datetime, '%a, %d %b %Y %H:%M:%S %z')
strftime = time.strftime("%d-%b-%H:%M", self.strptime)
info = urlopen(self.download_url).info()
size = str(int(info['content-length']) // 1048576) + " MB"
display_name = "Git-" + commit + " | " + strftime + " | " + size
self.new_version_obtained.emit(display_name)
except urllib.error.URLError as e:
print(e)
QThread.sleep(600)
return
def get_download_url(self):
builder_url = "https://builder.blender.org"
content = urlopen(builder_url + "/download").read()
soup = BeautifulSoup(content, 'html.parser')
platform = get_platform()
if platform == 'Windows':
build_url = soup.find(href=re.compile(
r'blender-.+win.+64'))['href']
elif platform == 'Linux':
build_url = soup.find(href=re.compile(
r'blender-.+linux.+64'))['href']
return builder_url + build_url
def get_commit_datetime(self, commit):
commit_url = "https://git.blender.org/gitweb/gitweb.cgi/blender.git/commit/"
content = urlopen(commit_url + commit).read()
soup = BeautifulSoup(content, 'html.parser')
datetime = soup.find_all("span", {"class": "datetime"})[1].text
return datetime