Added --uuid-info, --uuid-files to exportdb
This commit is contained in:
parent
3b789242aa
commit
c776f3070d
@ -1,3 +1,3 @@
|
||||
""" version info """
|
||||
|
||||
__version__ = "0.49.2"
|
||||
__version__ = "0.49.3"
|
||||
|
||||
@ -350,7 +350,7 @@ def process_files(
|
||||
verbose(f"Skipping missing file [filepath]{file}[/]")
|
||||
report_writer.write(ExportResults(missing=[file]))
|
||||
continue
|
||||
# zzz put in check for hardlink
|
||||
# TODO: zzz put in check for hardlink
|
||||
verbose(f"Processing file [filepath]{file}[/] ([num]{count}/{total}[/num])")
|
||||
photo = photosdb.get_photo(uuid)
|
||||
export_options = ExportOptions(
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
"""exportdb command for osxphotos CLI"""
|
||||
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
@ -63,6 +64,18 @@ from .verbose import verbose_print
|
||||
nargs=1,
|
||||
help="Print information about FILE_PATH contained in the database.",
|
||||
)
|
||||
@click.option(
|
||||
"--uuid-files",
|
||||
metavar="UUID",
|
||||
nargs=1,
|
||||
help="List exported files associated with UUID.",
|
||||
)
|
||||
@click.option(
|
||||
"--uuid-info",
|
||||
metavar="UUID",
|
||||
nargs=1,
|
||||
help="Print information about UUID contained in the database.",
|
||||
)
|
||||
@click.option(
|
||||
"--report",
|
||||
metavar="REPORT_FILE RUN_ID",
|
||||
@ -110,22 +123,24 @@ from .verbose import verbose_print
|
||||
)
|
||||
@click.argument("export_db", metavar="EXPORT_DATABASE", type=click.Path(exists=True))
|
||||
def exportdb(
|
||||
version,
|
||||
vacuum,
|
||||
check_signatures,
|
||||
update_signatures,
|
||||
touch_file,
|
||||
last_run,
|
||||
save_config,
|
||||
info,
|
||||
report,
|
||||
migrate,
|
||||
sql,
|
||||
export_dir,
|
||||
append,
|
||||
verbose,
|
||||
check_signatures,
|
||||
dry_run,
|
||||
export_db,
|
||||
export_dir,
|
||||
info,
|
||||
last_run,
|
||||
migrate,
|
||||
report,
|
||||
save_config,
|
||||
sql,
|
||||
touch_file,
|
||||
update_signatures,
|
||||
uuid_files,
|
||||
uuid_info,
|
||||
vacuum,
|
||||
verbose,
|
||||
version,
|
||||
):
|
||||
"""Utilities for working with the osxphotos export database"""
|
||||
|
||||
@ -163,6 +178,8 @@ def exportdb(
|
||||
sql,
|
||||
touch_file,
|
||||
update_signatures,
|
||||
uuid_files,
|
||||
uuid_info,
|
||||
vacuum,
|
||||
version,
|
||||
]
|
||||
@ -273,6 +290,37 @@ def exportdb(
|
||||
print(f"[red]File '{info}' not found in export database[/red]")
|
||||
sys.exit(0)
|
||||
|
||||
if uuid_info:
|
||||
# get photoinfo record for a uuid
|
||||
exportdb = ExportDB(export_db, export_dir)
|
||||
try:
|
||||
info_rec = exportdb.get_photoinfo_for_uuid(uuid_info)
|
||||
except Exception as e:
|
||||
print(f"[red]Error: {e}[/red]")
|
||||
sys.exit(1)
|
||||
else:
|
||||
if info_rec:
|
||||
print(json.dumps(json.loads(info_rec), sort_keys=True, indent=2))
|
||||
else:
|
||||
print(f"[red]UUID '{uuid_info}' not found in export database[/red]")
|
||||
sys.exit(0)
|
||||
|
||||
if uuid_files:
|
||||
# list files associated with a uuid
|
||||
exportdb = ExportDB(export_db, export_dir)
|
||||
try:
|
||||
file_list = exportdb.get_files_for_uuid(uuid_files)
|
||||
except Exception as e:
|
||||
print(f"[red]Error: {e}[/red]")
|
||||
sys.exit(1)
|
||||
else:
|
||||
if file_list:
|
||||
for f in file_list:
|
||||
print(f)
|
||||
else:
|
||||
print(f"[red]UUID '{uuid_files}' not found in export database[/red]")
|
||||
sys.exit(0)
|
||||
|
||||
if report:
|
||||
exportdb = ExportDB(export_db, export_dir)
|
||||
report_template, run_id = report
|
||||
|
||||
@ -15,7 +15,7 @@ from contextlib import suppress
|
||||
from io import StringIO
|
||||
from sqlite3 import Error
|
||||
from tempfile import TemporaryDirectory
|
||||
from typing import Any, Optional, Tuple, Union
|
||||
from typing import Any, Optional, Tuple, Union, List
|
||||
|
||||
from tenacity import retry, stop_after_attempt
|
||||
|
||||
@ -171,6 +171,17 @@ class ExportDB:
|
||||
uuid = None
|
||||
return uuid
|
||||
|
||||
def get_files_for_uuid(self, uuid: str) -> List:
|
||||
"""query database for UUID and return list of files associated with UUID or empty list"""
|
||||
conn = self._conn
|
||||
c = conn.cursor()
|
||||
c.execute(
|
||||
"SELECT filepath FROM export_data WHERE uuid = ?",
|
||||
(uuid,),
|
||||
)
|
||||
results = c.fetchall()
|
||||
return [os.path.join(self.export_dir, r[0]) for r in results]
|
||||
|
||||
def get_photoinfo_for_uuid(self, uuid):
|
||||
"""returns the photoinfo JSON struct for a UUID"""
|
||||
conn = self._conn
|
||||
|
||||
@ -50,6 +50,7 @@ def test_export_db():
|
||||
assert db.get_uuid_for_file(filepath) is None
|
||||
db.create_file_record(filepath, uuid)
|
||||
assert db.get_uuid_for_file(filepath) == uuid
|
||||
assert db.get_files_for_uuid(uuid) == [filepath]
|
||||
|
||||
record = db.get_file_record(filepath)
|
||||
assert record.uuid == uuid
|
||||
@ -142,6 +143,7 @@ def test_export_db_in_memory():
|
||||
assert record2.digest == DIGEST_DATA
|
||||
assert record2.src_sig == (7, 8, 9)
|
||||
assert record2.dest_sig == (10, 11, 12)
|
||||
assert dbram.get_files_for_uuid(uuid) == [filepath]
|
||||
|
||||
# change some values
|
||||
record2.photoinfo = INFO_DATA2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user