-
Notifications
You must be signed in to change notification settings - Fork 67
/
update_version_check.py
55 lines (51 loc) · 2.08 KB
/
update_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
######################### UpDateNotifi ################
import urllib.request
import requests
import re
from PyQt5.QtWidgets import QMessageBox,QMainWindow
import sys
class Update():
def __init__(self):
super().__init__()
self.old_version=self.get_current_version()
# msg = self.notifi()
def notifi(self):
try:
url = "https://raw.githubusercontent.com/osdag-admin/Osdag/master/README.md"
file = urllib.request.urlopen(url)
version = 'not found'
for line in file:
decoded_line = line.decode("utf-8")
match = re.search(r'Download the latest release version (\S+)', decoded_line)
if match:
version = match.group(1)
version = version.split("<")[0]
break
# decoded_line = line.decode("utf-8")
# new_version = decoded_line.split("=")[1]
if version != self.old_version:
msg = 'Current version: '+ self.old_version+'<br>'+'Latest version '+ str(version)+'<br>'+\
'Update will be available <a href=\"https://osdag.fossee.in/resources/downloads\"> here <a/>'
else:
msg = 'Already up to date'
return msg
except:
return "No internet connection"
def get_current_version(self):
version_file = "_version.py"
rel_path = str(sys.path[0])
rel_path = rel_path.replace("\\", "/")
VERSIONFILE = rel_path +'/'+ version_file
try:
verstrline = open(VERSIONFILE, "rt").read()
except EnvironmentError:
pass # Okay, there is no version file.
else:
VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
mo = re.search(VSRE, verstrline, re.M)
if mo:
verstr = mo.group(1)
return verstr
else:
print("unable to find version in %s" % (VERSIONFILE,))
raise RuntimeError("if %s.py exists, it is required to be well-formed" % (VERSIONFILE,))