Only export used resources

This commit is contained in:
Stavros Korokithakis 2021-01-27 01:14:14 +02:00
parent 9a700a81c2
commit 3fb1050670
No known key found for this signature in database
GPG Key ID: 26EA345ECD4C2A63
4 changed files with 13 additions and 3 deletions

View File

@ -47,6 +47,11 @@ class JoplinExporter:
static_dir = Path("static/resources")
joplin_dir = Path.home() / ".config/joplin-desktop"
def __init__(self):
# A dict of {resource_id: (title, extension)}.
self.resources = {}
self.used_resources = set()
def clean_content_dir(self):
"""Reset the content directory to a known state to begin."""
rmtree(self.content_dir)
@ -82,11 +87,15 @@ class JoplinExporter:
resource = self.resources.get(resource_id)
if not resource:
return None
# Add the resource to the set of used resources, so we can only copy
# the resources that are used.
self.used_resources.add(resource_id)
return "resources/" + resource_id + "." + resource[1]
def copy_resources(self):
"""Copy all the resources to the output directory."""
for resource_id, resource in self.resources.items():
"""Copy all the used resources to the output directory."""
for resource_id in self.used_resources:
resource = self.resources[resource_id]
title, extension = resource
copy(
self.joplin_dir / "resources" / (f"{resource_id}.{extension}"),
@ -144,7 +153,6 @@ class JoplinExporter:
folder_list.sort(key=lambda x: x[1].lower().strip() if x[1] != "Welcome" else "0")
self.clean_content_dir()
self.copy_resources()
for folder_counter, folder in enumerate(folder_list, start=1):
folder_id, folder_title = folder
@ -207,6 +215,8 @@ Click on a link in the list below to go to that page:
"""
)
self.copy_resources()
if __name__ == "__main__":
print("Exporting Joplin database...")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB