From 96854be84a9374ceed4d9c74870d068f8516de56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20Br=C3=BCckmann?= <64bit@posteo.de> Date: Tue, 26 Jan 2021 13:06:06 +0100 Subject: [PATCH] Only overwrite index.html/css files which were created by fdroid update Further changes: * use real value for icon instead of hard coded value * Move qrcode.make() to top * fix identation of css file generation --- fdroidserver/index.py | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/fdroidserver/index.py b/fdroidserver/index.py index ff391abd..8ba53b88 100644 --- a/fdroidserver/index.py +++ b/fdroidserver/index.py @@ -133,21 +133,36 @@ def make(apps, apks, repodir, archive): make_website(sortedapps, repodir, repodict) +def _should_file_be_generated(path, magic_string): + if os.path.exists(path): + with open(path) as f: + if not magic_string in f.readline(): # if the magic_string is not in the first line the file should be overwritten + return False + return True + + def make_website(apps, repodir, repodict): _, repo_pubkey_fingerprint = extract_pubkey() repo_pubkey_fingerprint_stripped = repo_pubkey_fingerprint.replace(" ", "") link = repodict["address"] link_fingerprinted = "{link}?fingerprint={fingerprint}".format(link=link, fingerprint=repo_pubkey_fingerprint_stripped) + autogenerate_comment = "auto-generated - fdroid index updates will overwrite this file" # do not change this string, as it will break the updates for existing files with older versions of this string if not os.path.exists(repodir): os.makedirs(repodir) - html_name = 'index.html' + + qrcode.make(link_fingerprinted).save(os.path.join(repodir, "index.png")) + html_name = 'index.html' html_file = os.path.join(repodir, html_name) - with open(html_file, 'w') as f: - name = repodict["name"] - description = repodict["description"] - f.write(""" + + if _should_file_be_generated(html_file, autogenerate_comment): + with open(html_file, 'w') as f: + name = repodict["name"] + description = repodict["description"] + icon = repodict["icon"] + f.write(""" + @@ -155,8 +170,8 @@ def make_website(apps, repodir, repodict): {name} - - + + @@ -188,16 +203,20 @@ def make_website(apps, repodir, repodict):

- """.format(name=name, + """.format(autogenerate_comment=autogenerate_comment, description=description, details="Currently it serves {} apps. To add it to your F-Droid client, scan the QR code (click it to enlarge) or use this URL:".format(len(apps)), fingerprint=repo_pubkey_fingerprint, + icon=icon, link=link, - link_fingerprinted=link_fingerprinted)) + link_fingerprinted=link_fingerprinted, + name=name)) - css_file = os.path.join(repodir, "index.css") + css_file = os.path.join(repodir, "index.css") + if _should_file_be_generated(css_file, autogenerate_comment): with open(css_file, "w") as f: - f.write(""" + # this auto generated comment was not included via .format(), as python seems to have problems with css files in combination with .format() + f.write("""/* auto-generated - fdroid index updates will overwrite this file */ BODY { font-family: Arial, Helvetica, Sans-Serif; color: #0000ee; @@ -308,8 +327,6 @@ fieldset select, fieldset input, #reposelect select, #reposelect input { font-si .appdetailcell { display:block; float:left; line-height:1.5em; } }""") - qrcode.make(link_fingerprinted).save(os.path.join(repodir, "index.png")) - def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_fingerprints):