|
|
@@ -1,18 +1,19 @@
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
+import datetime
|
|
|
import os
|
|
|
-from os.path import isdir, isfile, join, getmtime
|
|
|
-from pathlib import Path
|
|
|
import pyexiv2
|
|
|
import random
|
|
|
import re
|
|
|
-import sys
|
|
|
-from string import Template
|
|
|
import subprocess
|
|
|
+import sys
|
|
|
import traceback
|
|
|
+from PIL import Image, ImageOps
|
|
|
from configparser import ConfigParser
|
|
|
from optparse import OptionParser
|
|
|
-from PIL import Image, ImageOps
|
|
|
+from os.path import isdir, isfile, join, getmtime
|
|
|
+from pathlib import Path
|
|
|
+from string import Template
|
|
|
|
|
|
__all__ = []
|
|
|
__version__ = 0.1
|
|
|
@@ -68,6 +69,46 @@ html = Template("""<html>
|
|
|
</html>
|
|
|
""")
|
|
|
|
|
|
+def write_command_to_history(max_entries=20):
|
|
|
+ # Define the history file path
|
|
|
+ history_file = os.path.join(os.getcwd(), '.history')
|
|
|
+ # Get the current timestamp
|
|
|
+ timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+
|
|
|
+ # Function to check if a string contains special characters
|
|
|
+ def contains_special_chars(s):
|
|
|
+ special_chars = r'[^a-zA-Z0-9_\-\.\/]'
|
|
|
+ return bool(re.search(special_chars, s))
|
|
|
+
|
|
|
+ # Quote each argument if it contains special characters
|
|
|
+ quoted_args = []
|
|
|
+ for arg in sys.argv[1:]:
|
|
|
+ if contains_special_chars(arg):
|
|
|
+ quoted_args.append(f'"{arg}"')
|
|
|
+ else:
|
|
|
+ quoted_args.append(arg)
|
|
|
+
|
|
|
+ # Construct the full command with script name and quoted arguments
|
|
|
+ full_command = f"{sys.argv[0]} {' '.join(quoted_args)}"
|
|
|
+
|
|
|
+ # Read existing entries
|
|
|
+ try:
|
|
|
+ with open(history_file, 'r') as f:
|
|
|
+ lines = f.readlines()
|
|
|
+ except FileNotFoundError:
|
|
|
+ lines = []
|
|
|
+
|
|
|
+ # Append the new entry
|
|
|
+ new_entry = f"{full_command} # {timestamp}\n"
|
|
|
+ lines.append(new_entry)
|
|
|
+
|
|
|
+ # Truncate to max_entries
|
|
|
+ lines = lines[-max_entries:]
|
|
|
+
|
|
|
+ # Write the updated entries back to the file
|
|
|
+ with open(history_file, 'w') as f:
|
|
|
+ f.writelines(lines)
|
|
|
+
|
|
|
# Priorität der Auswertung
|
|
|
# 1. Exifdaten
|
|
|
def get_caption(jpg):
|
|
|
@@ -158,9 +199,7 @@ def makethumb(jpg):
|
|
|
else:
|
|
|
if getmtime(jpg) > getmtime(join('_thumbnails', jpg)):
|
|
|
image = Image.open(jpg)
|
|
|
- # thumb = ImageOps.fit(image, thumbsize, Image.ANTIALIAS)
|
|
|
- # thumb.save(join('_thumbnails', jpg))
|
|
|
- image.thumbnail(thumbsize, Image.ANTIALIAS)
|
|
|
+ image.thumbnail(thumbsize, Image.Resampling.LANCZOS)
|
|
|
image.save(join('_thumbnails', jpg))
|
|
|
|
|
|
def read_config(opts):
|
|
|
@@ -193,6 +232,8 @@ def write_config(opts):
|
|
|
def create_index_html(indexdir, opts):
|
|
|
startdir = os.getcwd()
|
|
|
os.chdir(indexdir)
|
|
|
+
|
|
|
+ write_command_to_history()
|
|
|
read_config(opts)
|
|
|
|
|
|
jpegs = []
|
|
|
@@ -237,7 +278,7 @@ def main(argv=None):
|
|
|
program_longdesc = '''create index.html for lightgallery in a directory of jpegs'''
|
|
|
program_license = "Copyright 2021 Markus Spring (markus-spring.info). \
|
|
|
Licensed under the Apache License 2.0\nhttp://www.apache.org/licenses/LICENSE-2.0"
|
|
|
-
|
|
|
+
|
|
|
if argv is None:
|
|
|
argv = sys.argv[1:]
|
|
|
try:
|