63 lines
1.4 KiB
Python
63 lines
1.4 KiB
Python
"""
|
|
This module brings a way to build the path specifiers internally used
|
|
(lists of strings) from the input path specifier (a string).
|
|
|
|
The input string will contain literal path specifiers and placeholders.
|
|
The placeholders are marked by chevrons: ``<placeholder>``
|
|
|
|
|
|
An example path specifier might look like this::
|
|
|
|
<DateTime-year>/<DateTime-month>/<DateTime-day>/images/<Make>/<Model>
|
|
|
|
The resulting internal specifier will be::
|
|
|
|
[
|
|
"<DateTime-year>"
|
|
, "<DateTime-month>"
|
|
, "<DateTime-day>"
|
|
, "images"
|
|
, "<Make>"
|
|
, "<Model>"
|
|
]
|
|
|
|
It will also check whether the placeholders are actually valid.
|
|
"""
|
|
|
|
import os
|
|
|
|
|
|
placeholders = {
|
|
"<name>",
|
|
"<DateTime.day>",
|
|
"<DateTime.month>",
|
|
"<DateTime.year>",
|
|
"<DateTime.hour>",
|
|
"<DateTime.minute>",
|
|
"<DateTime.second>",
|
|
"<DateTimeDigitized.day>",
|
|
"<DateTimeDigitized.month>",
|
|
"<DateTimeDigitized.year>",
|
|
"<DateTimeDigitized.hour>",
|
|
"<DateTimeDigitized.minute>",
|
|
"<DateTimeDigitized.second>",
|
|
"<DateTimeOriginal.day>",
|
|
"<DateTimeOriginal.month>",
|
|
"<DateTimeOriginal.year>",
|
|
"<DateTimeOriginal.hour>",
|
|
"<DateTimeOriginal.minute>",
|
|
"<DateTimeOriginal.second>",
|
|
"<Model>",
|
|
"<Make>",
|
|
"<Software>"
|
|
}
|
|
|
|
def get_path_specifier(string_path_specifer):
|
|
data = string_path_specifer.split(os.path.sep)
|
|
for d in data:
|
|
if((d.startswith("<")
|
|
and d.endswith(">"))
|
|
and d not in placeholders):
|
|
raise ValueError("unknown placeholder: {}".format(d))
|
|
return data
|