make_download (2299B)
1 #!/usr/bin/python3 2 import re 3 import os 4 import sys 5 import importlib 6 7 # load version.py; needlessly complicated alternative to "imp.load_source": 8 version_spec = importlib.util.spec_from_file_location('version', 'electrum/version.py') 9 version_module = importlib.util.module_from_spec(version_spec) 10 version_spec.loader.exec_module(version_module) 11 12 ELECTRUM_VERSION = version_module.ELECTRUM_VERSION 13 APK_VERSION = version_module.APK_VERSION 14 print("version", ELECTRUM_VERSION) 15 16 dirname = sys.argv[1] 17 print("directory", dirname) 18 19 download_page = os.path.join(dirname, "panel-download.html") 20 download_template = download_page + ".template" 21 22 with open(download_template) as f: 23 string = f.read() 24 25 version = version_win = version_mac = version_android = ELECTRUM_VERSION 26 string = string.replace("##VERSION##", version) 27 string = string.replace("##VERSION_WIN##", version_win) 28 string = string.replace("##VERSION_MAC##", version_mac) 29 string = string.replace("##VERSION_ANDROID##", version_android) 30 string = string.replace("##VERSION_APK##", APK_VERSION) 31 32 files = { 33 'tgz': "Electrum-%s.tar.gz" % version, 34 'appimage': "electrum-%s-x86_64.AppImage" % version, 35 'zip': "Electrum-%s.zip" % version, 36 'mac': "electrum-%s.dmg" % version_mac, 37 'win': "electrum-%s.exe" % version_win, 38 'win_setup': "electrum-%s-setup.exe" % version_win, 39 'win_portable': "electrum-%s-portable.exe" % version_win, 40 } 41 42 for k, n in files.items(): 43 path = "dist/%s"%n 44 link = "https://download.electrum.org/%s/%s"%(version,n) 45 if not os.path.exists(path): 46 os.system("wget -q %s -O %s" % (link, path)) 47 if not os.path.getsize(path): 48 os.unlink(path) 49 string = re.sub("<div id=\"%s\">(.*?)</div>"%k, '', string, flags=re.DOTALL + re.MULTILINE) 50 continue 51 sigpath = path + '.asc' 52 siglink = link + '.asc' 53 if not os.path.exists(sigpath): 54 os.system("wget -q %s -O %s" % (siglink, sigpath)) 55 if not os.path.getsize(sigpath): 56 os.unlink(sigpath) 57 string = re.sub("<div id=\"%s\">(.*?)</div>"%k, '', string, flags=re.DOTALL + re.MULTILINE) 58 continue 59 if os.system("gpg --verify %s"%sigpath) != 0: 60 raise Exception(sigpath) 61 string = string.replace("##link_%s##"%k, link) 62 63 64 with open(download_page,'w') as f: 65 f.write(string)