add updater

This commit is contained in:
Stefan Regnery 2018-10-31 20:23:12 +01:00
commit 887b12bb0c

61
arc-dps-updater/update.py Normal file
View File

@ -0,0 +1,61 @@
import shutil
import json
import os
import requests
import urllib3
import urllib2
import ssl
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
with open("config.json", mode="r") as config_file:
config = json.load(config_file)
def get_md5sum(md5_url):
r = requests.get(md5_url, verify=False, stream=True)
return str(r.text.split(" ")[0])
def download_file(url):
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
file_name = url.split('/')[-1]
u = urllib2.urlopen(url, context=ctx)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192
while True:
file_buffer = u.read(block_sz)
if not file_buffer:
break
file_size_dl += len(file_buffer)
f.write(file_buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
status += chr(8) * (len(status) + 1)
print status,
f.close()
online_version = get_md5sum(config["arc_dps"]["md5path"])
arc_dps_url = config["arc_dps"]["download_path"]
buildtemplates_url = config["arc_dps_buildtemplates"]["download_path"]
if config["arc_dps"]["current_version"] != online_version:
arc_dps_file_name = arc_dps_url.rsplit('/', 1)[-1]
buildtemplates_file_name = buildtemplates_url.rsplit('/', 1)[-1]
download_file(arc_dps_url)
download_file(buildtemplates_url)
shutil.move(arc_dps_file_name, os.path.join(config["guildwars2_path"], "bin64", arc_dps_file_name))
shutil.move(buildtemplates_file_name, os.path.join(config["guildwars2_path"], "bin64", buildtemplates_file_name))
config["arc_dps"]["current_version"] = online_version
with open("config.json", mode="w") as config_file:
config_file = (json.dump(config, config_file, indent=2))