From 886e8f9e4818e43670081eeedc0deb265e3cbf29 Mon Sep 17 00:00:00 2001 From: Nate Contino Date: Tue, 25 Jun 2024 13:41:08 -0400 Subject: [PATCH 1/5] Add md5 hash suffix at end of image names to bust the cache when we update one inplace --- documentation/asciidoc/services/connect/use.adoc | 4 ++-- scripts/create_auto_ninjabuild.py | 11 +++++++++-- scripts/create_build_adoc.py | 1 - scripts/create_build_adoc_include.py | 10 ++++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/documentation/asciidoc/services/connect/use.adoc b/documentation/asciidoc/services/connect/use.adoc index 4913484ab..8217fea48 100644 --- a/documentation/asciidoc/services/connect/use.adoc +++ b/documentation/asciidoc/services/connect/use.adoc @@ -103,7 +103,7 @@ image::images/screen-sharing-end.png[width="80%"] To turn off screen sharing, click the Connect system tray icon and unselect **Allow screen sharing**. Your Raspberry Pi remains signed into Connect, but you won't be able to create a screen sharing session from the Connect dashboard. -image:images/screen-sharing-disabled-desktop.png[width="80%"] +image::images/screen-sharing-disabled-desktop.png[width="80%"] Alternatively, you can disable screen sharing with the following command: @@ -168,7 +168,7 @@ image::images/remote-shell-end.png[width="80%"] To turn off remote shell access, click the Connect system tray icon and unselect **Allow remote shell**. Your Raspberry Pi remains signed into Connect, but you won't be able to create a remote shell session from the Connect dashboard. -image:images/remote-shell-disabled-desktop.png[width="80%"] +image::images/remote-shell-disabled-desktop.png[width="80%"] Alternatively, you can disable remote shell access with the following command: diff --git a/scripts/create_auto_ninjabuild.py b/scripts/create_auto_ninjabuild.py index 66dc12235..4dc7503bf 100755 --- a/scripts/create_auto_ninjabuild.py +++ b/scripts/create_auto_ninjabuild.py @@ -5,6 +5,7 @@ import json import re import yaml +import hashlib import ninja_syntax @@ -30,7 +31,10 @@ def scan_adoc(adoc_filename, apparent_filename, includes, src_images, dest_image for image in re.findall(r'image::?(.+?)\[.*\]', contents): if not (image.startswith('http:') or image.startswith('https:')): image_filename = resolve_url(adoc_filename, image) - dest_image = resolve_url(apparent_filename, image) + # append a hash to the end of the image file name to bust the cache when we change the image + image_hash = hashlib.md5(open(os.path.join(input_dir, image_filename),'rb').read()).hexdigest() + image_name, image_extension = os.path.splitext(image_filename) + dest_image = image_name + "-" + image_hash + image_extension if dest_image in dest_images and dest_images[dest_image] != image_filename: raise Exception("{} and {} would both end up as {}".format(dest_images[dest_image], image_filename, dest_image)) src_images[image_filename] = dest_image @@ -44,7 +48,10 @@ def add_entire_directory(tab_dir, dir_path, pages_set, src_images, dest_images): pages_set.add(os.path.join(dir_path, f)) elif f.endswith(".png"): image_filename = os.path.join(dir_path, f) - dest_image = image_filename + # append a hash to the end of the image file name to bust the cache when we change the image + image_hash = hashlib.md5(open(os.path.join(input_dir, image_filename),'rb').read()).hexdigest() + image_name, image_extension = os.path.splitext(image_filename) + dest_image = image_name + "-" + image_hash + image_extension if dest_image in dest_images and dest_images[dest_image] != image_filename: raise Exception("{} and {} would both end up as {}".format(dest_images[dest_image], image_filename, dest_image)) src_images[image_filename] = dest_image diff --git a/scripts/create_build_adoc.py b/scripts/create_build_adoc.py index da5d29314..4ac6f0d3d 100755 --- a/scripts/create_build_adoc.py +++ b/scripts/create_build_adoc.py @@ -21,7 +21,6 @@ def check_no_markdown(filename): if re.search(r'(\[.+?\]\(.+?\))', asciidoc): raise Exception("{} contains a Markdown-style link (i.e. '[title](url)' rather than 'url[title]')".format(filename)) - if __name__ == "__main__": index_json = sys.argv[1] config_yaml = sys.argv[2] diff --git a/scripts/create_build_adoc_include.py b/scripts/create_build_adoc_include.py index ab7c3c0cf..2d6238866 100755 --- a/scripts/create_build_adoc_include.py +++ b/scripts/create_build_adoc_include.py @@ -4,6 +4,7 @@ import os import re import yaml +import hashlib def check_no_markdown(filename): @@ -48,6 +49,15 @@ def check_no_markdown(filename): seen_header = True if github_edit is not None: line += edit_text + "\n\n" + else: + # find all image references, append md5 hash at end to bust the cache if we change the image + m = re.match(r'^(image::)(.+)(\[(.+)]\n?)$', line) + if m: + directory = os.path.dirname(os.path.abspath(src_adoc)) + image_hash = hashlib.md5(open(os.path.join(directory, m.group(2)),'rb').read()).hexdigest() + image_name, image_extension = os.path.splitext(m.group(2)) + line = m.group(1) + image_name + '-' + image_hash + image_extension + m.group(3) + "\n" + #print(m.group(2) + " replaced with " + line) new_contents += line with open(build_adoc, 'w') as out_fh: From f1e1ffb69bb7e3531bc527fa4e7176b35ae90246 Mon Sep 17 00:00:00 2001 From: Nate Contino Date: Tue, 25 Jun 2024 14:03:32 -0400 Subject: [PATCH 2/5] Fix build with apparent image file path --- scripts/create_auto_ninjabuild.py | 4 ++-- scripts/create_build_adoc_include.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/create_auto_ninjabuild.py b/scripts/create_auto_ninjabuild.py index 4dc7503bf..236941c98 100755 --- a/scripts/create_auto_ninjabuild.py +++ b/scripts/create_auto_ninjabuild.py @@ -33,7 +33,7 @@ def scan_adoc(adoc_filename, apparent_filename, includes, src_images, dest_image image_filename = resolve_url(adoc_filename, image) # append a hash to the end of the image file name to bust the cache when we change the image image_hash = hashlib.md5(open(os.path.join(input_dir, image_filename),'rb').read()).hexdigest() - image_name, image_extension = os.path.splitext(image_filename) + image_name, image_extension = os.path.splitext(resolve_url(apparent_filename, image)) dest_image = image_name + "-" + image_hash + image_extension if dest_image in dest_images and dest_images[dest_image] != image_filename: raise Exception("{} and {} would both end up as {}".format(dest_images[dest_image], image_filename, dest_image)) @@ -50,7 +50,7 @@ def add_entire_directory(tab_dir, dir_path, pages_set, src_images, dest_images): image_filename = os.path.join(dir_path, f) # append a hash to the end of the image file name to bust the cache when we change the image image_hash = hashlib.md5(open(os.path.join(input_dir, image_filename),'rb').read()).hexdigest() - image_name, image_extension = os.path.splitext(image_filename) + image_name, image_extension = os.path.splitext(f) dest_image = image_name + "-" + image_hash + image_extension if dest_image in dest_images and dest_images[dest_image] != image_filename: raise Exception("{} and {} would both end up as {}".format(dest_images[dest_image], image_filename, dest_image)) diff --git a/scripts/create_build_adoc_include.py b/scripts/create_build_adoc_include.py index 2d6238866..32fc07d45 100755 --- a/scripts/create_build_adoc_include.py +++ b/scripts/create_build_adoc_include.py @@ -57,7 +57,6 @@ def check_no_markdown(filename): image_hash = hashlib.md5(open(os.path.join(directory, m.group(2)),'rb').read()).hexdigest() image_name, image_extension = os.path.splitext(m.group(2)) line = m.group(1) + image_name + '-' + image_hash + image_extension + m.group(3) + "\n" - #print(m.group(2) + " replaced with " + line) new_contents += line with open(build_adoc, 'w') as out_fh: From 326911b47faac9ac5e2488ddf37024f50a0dd58c Mon Sep 17 00:00:00 2001 From: Nate Contino Date: Tue, 25 Jun 2024 14:11:13 -0400 Subject: [PATCH 3/5] Should have just tried a query param from the beginning --- scripts/create_auto_ninjabuild.py | 10 ++-------- scripts/create_build_adoc_include.py | 3 +-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/scripts/create_auto_ninjabuild.py b/scripts/create_auto_ninjabuild.py index 236941c98..22447ea8e 100755 --- a/scripts/create_auto_ninjabuild.py +++ b/scripts/create_auto_ninjabuild.py @@ -31,10 +31,7 @@ def scan_adoc(adoc_filename, apparent_filename, includes, src_images, dest_image for image in re.findall(r'image::?(.+?)\[.*\]', contents): if not (image.startswith('http:') or image.startswith('https:')): image_filename = resolve_url(adoc_filename, image) - # append a hash to the end of the image file name to bust the cache when we change the image - image_hash = hashlib.md5(open(os.path.join(input_dir, image_filename),'rb').read()).hexdigest() - image_name, image_extension = os.path.splitext(resolve_url(apparent_filename, image)) - dest_image = image_name + "-" + image_hash + image_extension + dest_image = resolve_url(apparent_filename, image) if dest_image in dest_images and dest_images[dest_image] != image_filename: raise Exception("{} and {} would both end up as {}".format(dest_images[dest_image], image_filename, dest_image)) src_images[image_filename] = dest_image @@ -48,10 +45,7 @@ def add_entire_directory(tab_dir, dir_path, pages_set, src_images, dest_images): pages_set.add(os.path.join(dir_path, f)) elif f.endswith(".png"): image_filename = os.path.join(dir_path, f) - # append a hash to the end of the image file name to bust the cache when we change the image - image_hash = hashlib.md5(open(os.path.join(input_dir, image_filename),'rb').read()).hexdigest() - image_name, image_extension = os.path.splitext(f) - dest_image = image_name + "-" + image_hash + image_extension + dest_image = image_filename if dest_image in dest_images and dest_images[dest_image] != image_filename: raise Exception("{} and {} would both end up as {}".format(dest_images[dest_image], image_filename, dest_image)) src_images[image_filename] = dest_image diff --git a/scripts/create_build_adoc_include.py b/scripts/create_build_adoc_include.py index 32fc07d45..52227ebce 100755 --- a/scripts/create_build_adoc_include.py +++ b/scripts/create_build_adoc_include.py @@ -55,8 +55,7 @@ def check_no_markdown(filename): if m: directory = os.path.dirname(os.path.abspath(src_adoc)) image_hash = hashlib.md5(open(os.path.join(directory, m.group(2)),'rb').read()).hexdigest() - image_name, image_extension = os.path.splitext(m.group(2)) - line = m.group(1) + image_name + '-' + image_hash + image_extension + m.group(3) + "\n" + line = m.group(1) + m.group(2) + '?hash=' + image_hash + m.group(3) + "\n" new_contents += line with open(build_adoc, 'w') as out_fh: From 4d4a980f5b1d6e6f9242ad4ec3c3778697c8c64e Mon Sep 17 00:00:00 2001 From: nate contino Date: Tue, 25 Jun 2024 19:31:25 +0100 Subject: [PATCH 4/5] Update scripts/create_auto_ninjabuild.py --- scripts/create_auto_ninjabuild.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/create_auto_ninjabuild.py b/scripts/create_auto_ninjabuild.py index 22447ea8e..66dc12235 100755 --- a/scripts/create_auto_ninjabuild.py +++ b/scripts/create_auto_ninjabuild.py @@ -5,7 +5,6 @@ import json import re import yaml -import hashlib import ninja_syntax From e617a829912004b42af3571d0dcd5f7a3bcba7da Mon Sep 17 00:00:00 2001 From: Nate Contino Date: Tue, 25 Jun 2024 14:40:27 -0400 Subject: [PATCH 5/5] Add to top-level adoc parsing file in case anyone ever dumps an image in there --- scripts/create_build_adoc.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/create_build_adoc.py b/scripts/create_build_adoc.py index 4ac6f0d3d..536446645 100755 --- a/scripts/create_build_adoc.py +++ b/scripts/create_build_adoc.py @@ -71,6 +71,12 @@ def check_no_markdown(filename): m = re.match(r'^(include::)(.+)(\[\]\n?)$', line) if m: line = m.group(1) + os.path.join('{includedir}/{parentdir}', m.group(2)) + m.group(3) + # find all image references, append md5 hash at end to bust the cache if we change the image + m = re.match(r'^(image::)(.+)(\[(.+)]\n?)$', line) + if m: + directory = os.path.dirname(os.path.abspath(src_adoc)) + image_hash = hashlib.md5(open(os.path.join(directory, m.group(2)),'rb').read()).hexdigest() + line = m.group(1) + m.group(2) + '?hash=' + image_hash + m.group(3) + "\n" new_contents += line with open(build_adoc, 'w') as out_fh: