added lockfile function

This commit is contained in:
2024-06-27 14:46:15 +02:00
committed by Flo Greistorfer
parent a4174a2b9e
commit 9f9a255d53

View File

@@ -5,6 +5,7 @@ import urllib.parse
import shutil
from multiprocessing import Pool
from string import Template
from pathlib import Path
import numpy as np
from tqdm.auto import tqdm
@@ -18,7 +19,7 @@ _FOLDERICON = "https://www.svgrepo.com/show/400249/folder.svg"
_ROOTTITLE = "Pictures"
imgext = [".jpg", ".jpeg"]
rawext = [".3fr", ".ari", ".arw", ".bay", ".braw", ".crw", ".cr2", ".cr3", ".cap", ".data", ".dcs", ".dcr", ".dng", ".drf", ".eip", ".erf", ".fff", ".gpr", ".iiq", ".k25", ".kdc", ".mdc", ".mef", ".mos", ".mrw", ".nef", ".nrw", ".obm", ".orf", ".pef", ".ptx", ".pxn", ".r3d", ".raf", ".raw", ".rwl", ".rw2", ".rwz", ".sr2", ".srf", ".srw", ".tif", ".tiff", ".x3f"]
excludes = ["index.html", "Galleries", ".previews", "Archives", "Wallpaper"]
excludes = [".lock", "index.html", "Galleries", ".previews", "Archives", "Wallpaper"]
thumbnails: list[tuple[str, str]] = []
@@ -46,6 +47,7 @@ HTMLHEADER = """
-ms-flex-wrap: wrap; /* IE10 */
flex-wrap: wrap;
justify-content: space-evenly;
overflow: hidden;
}
.folders figure {
@@ -65,6 +67,7 @@ HTMLHEADER = """
.folders figcaption {
width: 120px;
text-align: center;
}
.row {
@@ -269,6 +272,12 @@ def main():
if not os.path.exists(os.path.join(args.root, ".previews")):
os.mkdir(os.path.join(args.root, ".previews"))
if os.path.exists(os.path.join(args.root, ".lock")):
print("Another instance of this program is running.")
exit()
try:
Path(os.path.join(args.root, ".lock")).touch()
if args.non_interactive:
print("Generating html files...")
listfolder(args.root, _ROOTTITLE)
@@ -287,7 +296,9 @@ def main():
with Pool(os.cpu_count()) as p:
for r in tqdm(p.imap_unordered(thumbnail_convert, thumbnails), total=len(thumbnails), desc="Generating thumbnails", unit=" files", ascii=True, dynamic_ncols=True):
...
pass
finally:
os.remove(os.path.join(args.root, ".lock"))
if __name__ == "__main__":