Version 0.50.1 with --delete-file, --delete-uuid exportdb commands
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
""" version info """
|
||||
|
||||
__version__ = "0.50.0"
|
||||
__version__ = "0.50.1"
|
||||
|
||||
@@ -1920,7 +1920,7 @@ def export_photo(
|
||||
original_filename = str(original_filename)
|
||||
|
||||
verbose_(
|
||||
f"Exporting [filename]{photo.original_filename}[/] ([filename]{photo.filename}[/]) as [filepath]{original_filename}[/] ([count]{photo_num}/{num_photos}[/])"
|
||||
f"Exporting [filename]{photo.original_filename}[/] ([filename]{photo.filename}[/]) ([count]{photo_num}/{num_photos}[/])"
|
||||
)
|
||||
|
||||
results += export_photo_to_directory(
|
||||
@@ -2034,7 +2034,7 @@ def export_photo(
|
||||
)
|
||||
|
||||
verbose_(
|
||||
f"Exporting edited version of [filename]{photo.original_filename}[/filename] ([filename]{photo.filename}[/filename]) as [filepath]{edited_filename}[/filepath]"
|
||||
f"Exporting edited version of [filename]{photo.original_filename}[/filename] ([filename]{photo.filename}[/filename])"
|
||||
)
|
||||
|
||||
results += export_photo_to_directory(
|
||||
@@ -2728,4 +2728,3 @@ def render_and_validate_report(report: str, exiftool_path: str, export_dir: str)
|
||||
sys.exit(1)
|
||||
|
||||
return report
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ from osxphotos.export_db_utils import (
|
||||
export_db_update_signatures,
|
||||
export_db_vacuum,
|
||||
)
|
||||
from osxphotos.utils import pluralize
|
||||
|
||||
from .export import render_and_validate_report
|
||||
from .param_types import TemplateString
|
||||
@@ -76,6 +77,21 @@ from .verbose import verbose_print
|
||||
nargs=1,
|
||||
help="Print information about UUID contained in the database.",
|
||||
)
|
||||
@click.option(
|
||||
"--delete-uuid",
|
||||
metavar="UUID",
|
||||
nargs=1,
|
||||
multiple=True,
|
||||
help="Delete all data associated with UUID from the database.",
|
||||
)
|
||||
@click.option(
|
||||
"--delete-file",
|
||||
metavar="FILE_PATH",
|
||||
nargs=1,
|
||||
multiple=True,
|
||||
help="Delete all data associated with FILE_PATH from the database; "
|
||||
"does not delete the actual exported file if it exists, only the data in the database.",
|
||||
)
|
||||
@click.option(
|
||||
"--report",
|
||||
metavar="REPORT_FILE RUN_ID",
|
||||
@@ -138,6 +154,8 @@ def exportdb(
|
||||
update_signatures,
|
||||
uuid_files,
|
||||
uuid_info,
|
||||
delete_uuid,
|
||||
delete_file,
|
||||
vacuum,
|
||||
verbose,
|
||||
version,
|
||||
@@ -321,6 +339,24 @@ def exportdb(
|
||||
print(f"[red]UUID '{uuid_files}' not found in export database[/red]")
|
||||
sys.exit(0)
|
||||
|
||||
if delete_uuid:
|
||||
# delete a uuid from the export database
|
||||
exportdb = ExportDB(export_db, export_dir)
|
||||
for uuid in delete_uuid:
|
||||
print(f"Deleting uuid {uuid} from database.")
|
||||
count = exportdb.delete_data_for_uuid(uuid)
|
||||
print(f"Deleted {count} {pluralize(count, 'record', 'records')}.")
|
||||
sys.exit(0)
|
||||
|
||||
if delete_file:
|
||||
# delete information associated with a file from the export database
|
||||
exportdb = ExportDB(export_db, export_dir)
|
||||
for filepath in delete_file:
|
||||
print(f"Deleting file {filepath} from database.")
|
||||
count = exportdb.delete_data_for_filepath(filepath)
|
||||
print(f"Deleted {count} {pluralize(count, 'record', 'records')}.")
|
||||
sys.exit(0)
|
||||
|
||||
if report:
|
||||
exportdb = ExportDB(export_db, export_dir)
|
||||
report_template, run_id = report
|
||||
|
||||
Binary file not shown.
@@ -336,6 +336,34 @@ class ExportDB:
|
||||
yield row[0], os.path.join(self.export_dir, row[1])
|
||||
return
|
||||
|
||||
@retry(stop=stop_after_attempt(MAX_RETRY_ATTEMPTS))
|
||||
def delete_data_for_uuid(self, uuid):
|
||||
"""Delete all exportdb data for given UUID"""
|
||||
conn = self._conn
|
||||
c = conn.cursor()
|
||||
count = 0
|
||||
c.execute("DELETE FROM export_data WHERE uuid = ?;", (uuid,))
|
||||
count += c.execute("SELECT CHANGES();").fetchone()[0]
|
||||
c.execute("DELETE FROM photoinfo WHERE uuid = ?;", (uuid,))
|
||||
count += c.execute("SELECT CHANGES();").fetchone()[0]
|
||||
conn.commit()
|
||||
return count
|
||||
|
||||
@retry(stop=stop_after_attempt(MAX_RETRY_ATTEMPTS))
|
||||
def delete_data_for_filepath(self, filepath):
|
||||
"""Delete all exportdb data for given filepath"""
|
||||
conn = self._conn
|
||||
c = conn.cursor()
|
||||
filepath_normalized = self._normalize_filepath_relative(filepath)
|
||||
results = c.execute(
|
||||
"SELECT uuid FROM export_data WHERE filepath_normalized = ?;",
|
||||
(filepath_normalized,),
|
||||
).fetchall()
|
||||
count = 0
|
||||
for row in results:
|
||||
count += self.delete_data_for_uuid(row[0])
|
||||
return count
|
||||
|
||||
@retry(stop=stop_after_attempt(MAX_RETRY_ATTEMPTS))
|
||||
def close(self):
|
||||
"""close the database connection"""
|
||||
|
||||
@@ -1076,6 +1076,7 @@ class PhotoExporter:
|
||||
ValueError if export_as_hardlink and convert_to_jpeg both True
|
||||
"""
|
||||
|
||||
verbose = options.verbose or self._verbose
|
||||
if options.export_as_hardlink and options.convert_to_jpeg:
|
||||
raise ValueError(
|
||||
"export_as_hardlink and convert_to_jpeg cannot both be True"
|
||||
@@ -1165,6 +1166,9 @@ class PhotoExporter:
|
||||
|
||||
try:
|
||||
fileutil.copy(src, dest_str)
|
||||
verbose(
|
||||
f"Exported {self._filename(self.photo.original_filename)} to {self._filepath(dest_str)}"
|
||||
)
|
||||
except Exception as e:
|
||||
raise ExportError(
|
||||
f"Error copying file {src} to {dest_str}: {e} ({lineno(__file__)})"
|
||||
|
||||
Reference in New Issue
Block a user