Files
Nexus/2023/scripts/animation_tools/dwpicker/updatechecker.py
2025-11-23 23:31:18 +08:00

36 lines
1.1 KiB
Python

import re
import webbrowser
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen # python2
from maya import cmds
from .dialog import UpdateAvailableDialog
from .appinfos import VERSION
from .optionvar import CHECK_FOR_UPDATE
APPINFOS_URL = (
'https://raw.githubusercontent.com/DreamWall-Animation/dwpicker/main/'
'dwpicker/appinfos.py')
LATEST_RELEASE_URL = (
'https://github.com/DreamWall-Animation/dwpicker/releases/latest')
VERSION_PATTERN = r'\d(\.|,).\d(\.|,).\d'
def warn_if_update_available():
if not cmds.optionVar(query=CHECK_FOR_UPDATE):
return
try:
appinfos = urlopen(APPINFOS_URL).read().decode()
latest_version_str = re.search(VERSION_PATTERN, appinfos)[0]
latest_version = tuple(
int(n) for n in latest_version_str.replace(',', '.').split('.'))
if VERSION < latest_version:
if UpdateAvailableDialog(latest_version_str).exec_():
webbrowser.open(LATEST_RELEASE_URL)
except BaseException:
print('DwPicker: could not check for new version')