mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
6a708e55e6
- moved config to documents - reduced readme - updated requirements - action key implemented - when non saved config is get for the first time, default is saved - added icon - added unhandled exception logging - added debug mode - made dark mode and debug mode check buttons instead of command - created manifest - moved addon to a zip
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
import re
|
|
import subprocess
|
|
import sys
|
|
import urllib.request
|
|
from os import execl
|
|
|
|
import pkg_resources
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
def _normalize_version(v):
|
|
rv = []
|
|
for x in v.split("."):
|
|
try:
|
|
rv.append(int(x))
|
|
except ValueError:
|
|
for y in re.split("([0-9]+)", x):
|
|
try:
|
|
if y != '':
|
|
rv.append(int(y))
|
|
except ValueError:
|
|
rv.append(y)
|
|
return rv
|
|
|
|
|
|
def _get_highest_version(index, pkg):
|
|
url = "{}/{}/".format(index, pkg)
|
|
html = urllib.request.urlopen(url)
|
|
if html.getcode() != 200:
|
|
raise Exception # not found
|
|
soup = BeautifulSoup(html.read(), "html5lib")
|
|
versions = []
|
|
for link in soup.find_all('a'):
|
|
text = link.get_text()
|
|
try:
|
|
version = re.search(pkg + '-(.*)\.tar\.gz', text).group(1)
|
|
versions.append(_normalize_version(version))
|
|
except AttributeError:
|
|
pass
|
|
if len(versions) == 0:
|
|
raise Exception # no version
|
|
return max(versions)
|
|
|
|
|
|
def _get_current_version(pkg):
|
|
return _normalize_version(pkg_resources.get_distribution(pkg).version)
|
|
|
|
|
|
def auto_upgrade():
|
|
index = "https://pypi.python.org/simple"
|
|
pkg = "fishy"
|
|
if _get_highest_version(index, pkg) > _get_current_version(pkg):
|
|
subprocess.call(["python", '-m', 'pip', 'install', '--upgrade', 'fishy', '--user'])
|
|
execl(sys.executable, *([sys.executable] + sys.argv))
|