show image count

This commit is contained in:
2024-04-21 10:13:58 +03:00
parent e965b8803c
commit c53c57ede2

View File

@@ -9,7 +9,7 @@ from imagelist2.db import DB, sqlite_sqrt, sqlite_square
from imagelist2.image import ImageMeasure, is_image_extension
from tqdm import tqdm
__version__ = "0.0.1"
__version__ = "0.0.2"
SQLFILE = "image-list.sqlite"
# IMGMATCH = re.compile("|".join([".*\." + x + "$" |.*\.jpeg$|.*\.png$|.*\.gif$|.*\.tif$", re.I)
BADDIRS = ["_tn", "_med", ".tn", ".med"]
@@ -26,6 +26,7 @@ class ImageList:
def recursive_add(self):
dir_count = 0
image_count = 0
for path, dirs, files in os.walk(os.path.realpath(self.options.startpath), followlinks=self.options.symlinks):
clean_dirs(dirs)
dir_count += 1
@@ -60,21 +61,25 @@ class ImageList:
if self.db.is_hash_mismatch(image):
has_changed = True
if has_changed:
image_count += 1
self.add_single(image, change=True)
else:
if not self.options.no_add:
image_count += 1
self.add_single(image, change=False)
self.db.conn.commit()
if image_count > 0:
print(f"Added/changed {image_count} images")
return
def add_single(self, image, change=False):
if change:
query = "UPDATE list SET hash=?, date=? ,size=? WHERE file=?"
error_msg = f"error adding file: {image.filename}"
error_msg = f"error adding image: {image.filename}"
else:
query = "INSERT INTO list(hash,date,size,file) VALUES (?,?,?,?)"
error_msg = f"error changing file: {image.filename}"
error_msg = f"error changing image: {image.filename}"
try:
self.db.cursor().execute(
@@ -145,7 +150,7 @@ class ImageList:
cursor.execute("DELETE FROM list where file == ?", (file,))
self.db.conn.commit()
if len(to_delete) > 0:
print(f"Cleaned {len(to_delete)} files")
print(f"Cleaned {len(to_delete)} images")
return
def clean_data(self):