diff --git a/bumpflatpakversionsha.py b/bumpflatpakversionsha.py index 13b1826..2654378 100644 --- a/bumpflatpakversionsha.py +++ b/bumpflatpakversionsha.py @@ -1,77 +1,80 @@ # # Copyright 2018 Aleix Pol Gonzalez # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License or (at your option) version 3 or any later version # accepted by the membership of KDE e.V. (or its successor approved # by the membership of KDE e.V.), which shall act as a proxy # defined in Section 14 of version 3 of the license. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # import json import hashlib import requests import multiprocessing import sys def calculate_sha256(url): urlsha = url + ".sha256" r = requests.get(urlsha, stream=False) if r.status_code == requests.codes.ok: print("using", urlsha) resp = r.text idxEnd = resp.find(' ') sha = resp[:idxEnd] return sha else: print("no sha256 file", urlsha) print("getting...", url) sha256 = hashlib.sha256() response = requests.get(url, stream=True) for data in response.iter_content(): sha256.update(data) return sha256.hexdigest() def processModule(module): replace = {} - if not 'sources' in module: - return replace - for source in module['sources']: - if source['type'] == 'archive': - sha = calculate_sha256(source['url']) - if sha != source['sha256']: - print("new sha", source, sha) - replace[source['sha256']] = sha - break + if 'sources' in module: + for source in module['sources']: + if source['type'] == 'archive': + sha = calculate_sha256(source['url']) + if sha != source['sha256']: + print("new sha", source, sha) + replace[source['sha256']] = sha + break + + if 'modules' in module: + for submodule in module['modules']: + replace = {**replace, **processModule(submodule)} return replace if __name__ == "__main__": content = "" for x in sys.argv[1:]: with open(x, 'r') as sdkfile: content = sdkfile.read() value = json.loads(content) pool = multiprocessing.Pool(6) replacements = pool.map(processModule, value['modules']) for repl in replacements: for (a, b) in repl.items(): content = content.replace(a, b, 1) with open(x, 'w') as sdkfile: sdkfile.write(content)