From ecbf663b181a457615fd147f94e8454f6dffc392 Mon Sep 17 00:00:00 2001 From: Arksine Date: Sun, 21 Mar 2021 08:31:22 -0400 Subject: [PATCH] file_manager: make the thumbs directory hidden Signed-off-by: Eric Callahan --- moonraker/components/file_manager.py | 7 ++++--- scripts/extract_metadata.py | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/moonraker/components/file_manager.py b/moonraker/components/file_manager.py index e628509..2f1cb9e 100644 --- a/moonraker/components/file_manager.py +++ b/moonraker/components/file_manager.py @@ -441,7 +441,7 @@ class FileManager: def _unzip_ufp(self, ufp_path, dest_path): thumb_name = os.path.splitext( os.path.basename(dest_path))[0] + ".png" - dest_thumb_dir = os.path.join(os.path.dirname(dest_path), "thumbs") + dest_thumb_dir = os.path.join(os.path.dirname(dest_path), ".thumbs") dest_thumb_path = os.path.join(dest_thumb_dir, thumb_name) try: with tempfile.TemporaryDirectory() as tmp_dir_name: @@ -929,6 +929,7 @@ METADATA_VERSION = 3 class MetadataStorage: def __init__(self, server, gc_path, database): self.server = server + self.gc_path = gc_path database.register_local_namespace(METADATA_NAMESPACE) self.mddb = database.wrap_namespace( METADATA_NAMESPACE, parse_keys=False) @@ -936,14 +937,14 @@ class MetadataStorage: "moonraker", "file_manager.metadata_version", 0) if version != METADATA_VERSION: # Clear existing metadata when version is bumped - self.mddb.clear() + for fname in self.mddb.keys(): + self.remove_file_metadata(fname) database.insert_item( "moonraker", "file_manager.metadata_version", METADATA_VERSION) self.pending_requests = {} self.events = {} self.busy = False - self.gc_path = gc_path if self.gc_path: # Check for removed gcode files while moonraker was shutdown for fname in list(self.mddb.keys()): diff --git a/scripts/extract_metadata.py b/scripts/extract_metadata.py index 30721ea..dbd4177 100644 --- a/scripts/extract_metadata.py +++ b/scripts/extract_metadata.py @@ -213,7 +213,7 @@ class PrusaSlicer(BaseSlicer): r"; thumbnail begin[;/\+=\w\s]+?; thumbnail end", self.header_data) if not thumb_matches: return None - thumb_dir = os.path.join(os.path.dirname(self.path), "thumbs") + thumb_dir = os.path.join(os.path.dirname(self.path), ".thumbs") if not os.path.exists(thumb_dir): try: os.mkdir(thumb_dir) @@ -238,7 +238,7 @@ class PrusaSlicer(BaseSlicer): continue thumb_name = f"{thumb_base}-{info[0]}x{info[1]}.png" thumb_path = os.path.join(thumb_dir, thumb_name) - rel_thumb_path = os.path.join("thumbs", thumb_name) + rel_thumb_path = os.path.join(".thumbs", thumb_name) with open(thumb_path, "wb") as f: f.write(base64.b64decode(data.encode())) parsed_matches.append({ @@ -355,11 +355,11 @@ class Cura(PrusaSlicer): if thumbs is not None: return thumbs # Check for thumbnails extracted from the ufp - thumb_dir = os.path.join(os.path.dirname(self.path), "thumbs") + thumb_dir = os.path.join(os.path.dirname(self.path), ".thumbs") thumb_base = os.path.splitext(os.path.basename(self.path))[0] thumb_path = os.path.join(thumb_dir, f"{thumb_base}.png") - rel_path_full = os.path.join("thumbs", f"{thumb_base}.png") - rel_path_small = os.path.join("thumbs", f"{thumb_base}-32x32.png") + rel_path_full = os.path.join(".thumbs", f"{thumb_base}.png") + rel_path_small = os.path.join(".thumbs", f"{thumb_base}-32x32.png") thumb_path_small = os.path.join(thumb_dir, f"{thumb_base}-32x32.png") if not os.path.isfile(thumb_path): return None