Created
May 19, 2022 13:21
-
-
Save gioxx/ff1a5d9ce8801044a02bbb8cda028cc5 to your computer and use it in GitHub Desktop.
Script di creazione pacchetto "portable" di Firefox Win32 partendo dall'ultima release stabile.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import urllib.request | |
import base64 | |
import json | |
import os | |
import shutil | |
import subprocess | |
import hashlib | |
channel = "LATEST_FIREFOX_VERSION" | |
def fxjson(path,channel): | |
urllib.request.urlretrieve(path,"firefox_versions.json") | |
with open("firefox_versions.json", 'r') as f: | |
response = json.load(f) | |
os.remove("firefox_versions.json") | |
return response[channel] | |
def fxdownload(url,filename): | |
# URL di esempio https://ftp.mozilla.org/pub/firefox/releases/98.0.1/win64/it/Firefox%20Setup%2098.0.1.exe | |
url = url.replace(" ", "%20") # https://stackoverflow.com/a/69811079 | |
urllib.request.urlretrieve(url,filename) | |
hash_md5 = hashlib.md5() # https://stackoverflow.com/a/3431838 | |
with open(filename, "rb") as f: | |
for chunk in iter(lambda: f.read(4096), b""): | |
hash_md5.update(chunk) | |
return hash_md5.hexdigest() | |
def fxTempClean(): | |
shutil.rmtree('./FxTemp', ignore_errors=True) | |
shutil.rmtree('./core', ignore_errors=True) | |
return | |
def fxUnzip(filename): | |
fxTempClean() | |
# https://stackoverflow.com/a/325495 | |
cmd = ['./7zz', 'x', filename, '-oFxTemp'] | |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE) | |
""" | |
for line in p.stdout: | |
print(line) | |
""" | |
p.wait() | |
return p.returncode | |
def fxZip(version): | |
shutil.move('./FxTemp/core','./core') | |
fxZipFile = "firefox-%s-it.win32.zip" %version | |
# https://stackoverflow.com/a/325495 | |
cmd = ['./7zz', 'a', fxZipFile, './core/*'] | |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE) | |
p.wait() | |
return p.returncode | |
fxversion = fxjson("https://product-details.mozilla.org/1.0/firefox_versions.json",channel) | |
pkgpath = "https://ftp.mozilla.org/pub/firefox/releases/%s/win64/it/Firefox Setup %s.exe" % (fxversion,fxversion) | |
pkgname = "Firefox Setup %s.exe" % fxversion | |
download = fxdownload(pkgpath,pkgname) | |
print(channel,download) | |
unzip = fxUnzip(pkgname) | |
zip = fxZip(fxversion) | |
fxTempClean() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment