From b8657a553d968ed6cf10e4f80926ac7fcd9d3621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Galv=C3=A3o?= Date: Fri, 29 Mar 2019 15:18:39 +0000 Subject: [PATCH] Create update_multilangual_casks.py (#61084) --- developer/bin/update_multilangual_casks.py | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 developer/bin/update_multilangual_casks.py diff --git a/developer/bin/update_multilangual_casks.py b/developer/bin/update_multilangual_casks.py new file mode 100644 index 0000000000..f5ba8ed43a --- /dev/null +++ b/developer/bin/update_multilangual_casks.py @@ -0,0 +1,38 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +import sys +import urllib2 +import hashlib + + +def getsha(url, version, language): + url = url.replace("#{version}", version) + url = url.replace("#{language}", language) + response = urllib2.urlopen(url) + download = response.read() + if len(download) < 100000: + raise Exception('it seems the download failed') + m = hashlib.sha256() + m.update(download) + return m.hexdigest() + + +if (len(sys.argv)) is not 3 or "-h" in sys.argv or "--help" in sys.argv: + print "usage: " + sys.argv[0] + " " + print "for example: " + sys.argv[0] + " /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/firefox.rb 66.0" + sys.exit(1) + +fe = open(sys.argv[1]) +cask = fe.read() + +url = cask.split(" url \"")[1].split("\"")[0] +version = sys.argv[2] + +for line in cask.split("\n"): + if line.startswith(" version '"): + print " version '" + version + "'" + elif line.startswith(" sha256 '"): + language = cask.split(line)[1].split("'")[1].split("'")[0] + print " sha256 '" + getsha(url, version, language) + "'" + else: + print line