Added {album_seq} and {folder_album_seq}, #496

This commit is contained in:
Rhet Turnbull
2021-07-24 20:41:31 -07:00
parent 6e9f709279
commit 12f39dbaf5
5 changed files with 242 additions and 28 deletions

View File

@@ -778,6 +778,21 @@ UUID_DICT_MISSING = {
"D79B8D77-BFFC-460B-9312-034F2877D35B": "Pumkins2.jpg", # not missing
}
UUID_DICT_FOLDER_ALBUM_SEQ = {
"7783E8E6-9CAC-40F3-BE22-81FB7051C266": {
"directory": "{folder_album}",
"album": "Sorted Oldest First",
"filename": "{album?{folder_album_seq.1}_,}{original_name}",
"result": "3_IMG_3092.heic",
},
"3DD2C897-F19E-4CA6-8C22-B027D5A71907": {
"directory": "{album}",
"album": "Sorted Oldest First",
"filename": "{album?{album_seq}_,}{original_name}",
"result": "0_IMG_4547.jpg",
},
}
def modify_file(filename):
"""appends data to a file to modify it"""
@@ -7070,3 +7085,39 @@ def test_export_query_function():
)
assert result.exit_code == 0
assert "exported: 1" in result.output
def test_export_album_seq():
"""Test {album_seq} template"""
import glob
from osxphotos.cli import cli
runner = CliRunner()
cwd = os.getcwd()
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
for uuid in UUID_DICT_FOLDER_ALBUM_SEQ:
result = runner.invoke(
cli,
[
"export",
"--db",
os.path.join(cwd, PHOTOS_DB_15_7),
".",
"-V",
"--album",
UUID_DICT_FOLDER_ALBUM_SEQ[uuid]["album"],
"--directory",
UUID_DICT_FOLDER_ALBUM_SEQ[uuid]["directory"],
"--filename",
UUID_DICT_FOLDER_ALBUM_SEQ[uuid]["filename"],
"--uuid",
uuid,
],
)
assert result.exit_code == 0
files = glob.glob(f"{UUID_DICT_FOLDER_ALBUM_SEQ[uuid]['album']}/*")
assert (
f"{UUID_DICT_FOLDER_ALBUM_SEQ[uuid]['album']}/{UUID_DICT_FOLDER_ALBUM_SEQ[uuid]['result']}"
in files
)

View File

@@ -343,6 +343,49 @@ UUID_CONDITIONAL = {
},
}
UUID_ALBUM_SEQ = {
"7783E8E6-9CAC-40F3-BE22-81FB7051C266": {
"album": "/Sorted Manual",
"templates": {
"{album_seq}": "0",
"{album_seq:02d}": "00",
"{album_seq.1}": "1",
"{album_seq.1:03d}": "001",
"{folder_album_seq}": "0",
"{folder_album_seq:02d}": "00",
"{folder_album_seq.1}": "1",
"{folder_album_seq.1:03d}": "001",
},
},
"F12384F6-CD17-4151-ACBA-AE0E3688539E": {
"album": "/Sorted Manual",
"templates": {
"{album_seq}": "2",
"{album_seq:02d}": "02",
"{album_seq.1}": "3",
"{album_seq.1:03d}": "003",
"{folder_album_seq}": "2",
"{folder_album_seq:02d}": "02",
"{folder_album_seq.1}": "3",
"{folder_album_seq.1:03d}": "003",
},
},
"E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51": {
"album": "/Folder1/SubFolder2/AlbumInFolder",
"templates": {
"{album_seq}": "1",
"{album_seq:02d}": "01",
"{album_seq.1}": "2",
"{album_seq.1:03d}": "002",
"{folder_album_seq}": "1",
"{folder_album_seq:02d}": "01",
"{folder_album_seq.1}": "2",
"{folder_album_seq.0}": "1",
"{folder_album_seq.1:03d}": "002",
},
},
}
@pytest.fixture(scope="module")
def photosdb_places():
@@ -1105,3 +1148,16 @@ def test_id(photosdb):
rendered, _ = photo.render_template("{id:03d}")
assert rendered[0] == "007"
def test_album_seq(photosdb):
"""Test {album_seq} and {folder_album_seq} templates"""
from osxphotos.phototemplate import RenderOptions
for uuid in UUID_ALBUM_SEQ:
photo = photosdb.get_photo(uuid)
album = UUID_ALBUM_SEQ[uuid]["album"]
options = RenderOptions(dest_path=album)
for template, value in UUID_ALBUM_SEQ[uuid]["templates"].items():
rendered, _ = photo.render_template(template, options=options)
assert rendered[0] == value