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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#!/c/Python27/python.exe
"""
Update Chocolatey package from GitHub releases information.
Requirements:
- Being on Windows
- Having Chocolatey installed (https://chocolatey.org/)
- Having warmup and nuget.commandline installed ("cinst warmup nuget.commandline")
- Having the API key configured ("nuget SetApiKey [API_KEY_HERE] -source http://chocolatey.org/" "https://chocolatey.org/account")
- Being a maintainer of the syncthing-gtk package on Chocolatey
"""
from __future__ import unicode_literals, print_function
import re, os, json
try:
from urllib import request # Py3
except ImportError:
import urllib2 as request # Py2
from io import open
print("Retrieving last version...")
releasesString = request.urlopen("https://api.github.com/repos/syncthing/syncthing-gtk/releases").read().decode('utf-8')
releases = json.loads(releasesString)
lastRelease = releases[0] # Improve if needed
version = ''
url = ''
releaseNotes = ''
version = lastRelease['name'].replace('v', '', )
releaseNotes = lastRelease['body'].replace('\r', '').replace(':\n-', ':\n\n-')
for asset in lastRelease['assets']:
if re.match(r'.+win32-full-installer.exe', asset['name']):
# url = "https://cdn.rawgit.com/syncthing/syncthing-gtk/releases/download/"+lastRelease['name']+"/"+asset['name']
url = asset['browser_download_url']
assert(url != ''), "ERR No fitting script found"
print("Found version", version)
print("Updating files...")
nuspecFile = open("syncthing-gtk.nuspec", "r", encoding="utf8")
nuspecString = nuspecFile.read()
nuspecFile.close()
nuspecString = re.sub(r'<version>.*</version>', '<version>'+version+'</version>', nuspecString)
nuspecString = re.sub(r'<releaseNotes>[\w\W]*</releaseNotes>', '<releaseNotes>'+releaseNotes+'</releaseNotes>', nuspecString)
nuspecFile = open("syncthing-gtk.nuspec", "w", encoding="utf8")
print(nuspecString, file=nuspecFile, end="")
nuspecFile.close()
chocolateyInstallFile = open("tools/chocolateyInstall.ps1", "r", encoding="utf8")
chocolateyInstallString = chocolateyInstallFile.read()
chocolateyInstallFile.close()
chocolateyInstallString = re.sub(r'\$url ?= ?\'.*\'\n', '$url = \''+url+'\'\n', chocolateyInstallString)
chocolateyInstallFile = open("tools/chocolateyInstall.ps1", "w", encoding="utf8")
print(chocolateyInstallString, file=chocolateyInstallFile, end="")
chocolateyInstallFile.close()
print("Packaging...")
os.system("cpack")
input("Done! Press [Enter] to push or ^C to cancel pushing")
print("Pushing...")
os.system("cpush syncthing-gtk."+version+".nupkg")
print("Done!")
|