Fix load path format from config
This commit is contained in:
parent
cf8b6a9dec
commit
e60dab7f3b
|
@ -15,5 +15,4 @@ day_begins=4
|
||||||
|
|
||||||
# Path format
|
# Path format
|
||||||
dirs_path={%Y}/{%m-%b}-{city}-{folder}
|
dirs_path={%Y}/{%m-%b}-{city}-{folder}
|
||||||
name={%Y%m%d-%H%M%S}-%u{original_name}|%u{basename}.%l{ext}
|
name={%Y%m%d-%H%M%S}-(%u{original_name}|%u{name}).%l{ext}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ _sort_options = [
|
||||||
click.option(
|
click.option(
|
||||||
'--path-format',
|
'--path-format',
|
||||||
'-p',
|
'-p',
|
||||||
default=constants.DEFAULT_PATH_FORMAT,
|
default=None,
|
||||||
help='Custom featured path format',
|
help='Custom featured path format',
|
||||||
),
|
),
|
||||||
click.option(
|
click.option(
|
||||||
|
@ -145,6 +145,7 @@ def _cli_sort(collection, src_paths, import_mode, remove_duplicates):
|
||||||
loc = _cli_get_location(collection)
|
loc = _cli_get_location(collection)
|
||||||
|
|
||||||
path_format = collection.opt['Path']['path_format']
|
path_format = collection.opt['Path']['path_format']
|
||||||
|
LOG.debug(f'path_format: {path_format}')
|
||||||
|
|
||||||
return collection.sort_files(
|
return collection.sort_files(
|
||||||
src_paths, path_format, loc, import_mode, remove_duplicates
|
src_paths, path_format, loc, import_mode, remove_duplicates
|
||||||
|
|
|
@ -209,6 +209,19 @@ class FPath:
|
||||||
)
|
)
|
||||||
this_part = self._set_case(regex, part, this_part)
|
this_part = self._set_case(regex, part, this_part)
|
||||||
|
|
||||||
|
# remove alternate parts inside bracket separated by |
|
||||||
|
regex = r'[-_ .]?\(\|\)'
|
||||||
|
if re.search(regex, this_part):
|
||||||
|
# Delete substitute part and separator if empty
|
||||||
|
this_part = re.sub(regex, '', this_part)
|
||||||
|
elif re.search(r'\(.*\)', this_part):
|
||||||
|
regex = r'\(\|'
|
||||||
|
this_part = re.sub(regex, '', this_part)
|
||||||
|
regex = r'\|.*\)'
|
||||||
|
this_part = re.sub(regex, '', this_part)
|
||||||
|
regex = r'\)'
|
||||||
|
this_part = re.sub(regex, '', this_part)
|
||||||
|
|
||||||
# Delete separator char at the begining of the string if any:
|
# Delete separator char at the begining of the string if any:
|
||||||
if this_part:
|
if this_part:
|
||||||
regex = '[-_ .]'
|
regex = '[-_ .]'
|
||||||
|
@ -229,22 +242,17 @@ class FPath:
|
||||||
path = []
|
path = []
|
||||||
path_parts = path_format.split('/')
|
path_parts = path_format.split('/')
|
||||||
for path_part in path_parts:
|
for path_part in path_parts:
|
||||||
this_parts = path_part.split('|')
|
part = self.get_path_part(path_part, metadata)
|
||||||
for this_part in this_parts:
|
|
||||||
part = self.get_path_part(this_part, metadata)
|
|
||||||
|
|
||||||
if part != '':
|
if part != '':
|
||||||
# Check if all masks are substituted
|
# Check if all masks are substituted
|
||||||
if True in [c in part for c in '{}']:
|
if True in [c in part for c in '{}']:
|
||||||
self.log.error(
|
self.log.error(
|
||||||
f"Format path part invalid: {this_part}"
|
f"Format path part invalid: {this_part}"
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
path.append(part)
|
path.append(part)
|
||||||
# We break as soon as we have a value to append
|
|
||||||
break
|
|
||||||
# Else we continue for fallbacks
|
|
||||||
|
|
||||||
# If last path is empty or start with dot
|
# If last path is empty or start with dot
|
||||||
if part == '' or re.match(r'^\..*', part):
|
if part == '' or re.match(r'^\..*', part):
|
||||||
|
@ -714,8 +722,9 @@ class Collection(SortMedias):
|
||||||
|
|
||||||
# Set client options
|
# Set client options
|
||||||
for option, value in cli_options.items():
|
for option, value in cli_options.items():
|
||||||
for section in self.opt:
|
if value not in (None, ()):
|
||||||
self.opt[section][option] = value
|
for section in self.opt:
|
||||||
|
self.opt[section][option] = value
|
||||||
|
|
||||||
self.exclude = self.opt['Filters']['exclude']
|
self.exclude = self.opt['Filters']['exclude']
|
||||||
if not self.exclude:
|
if not self.exclude:
|
||||||
|
@ -885,7 +894,7 @@ class Collection(SortMedias):
|
||||||
metadata['src_path'] = row['SrcPath']
|
metadata['src_path'] = row['SrcPath']
|
||||||
# Check if row FilePath is a subpath of relpath
|
# Check if row FilePath is a subpath of relpath
|
||||||
if relpath.startswith(row['FilePath']):
|
if relpath.startswith(row['FilePath']):
|
||||||
path = os.path.relpath(rlpath, row['FilePath'])
|
path = os.path.relpath(relpath, row['FilePath'])
|
||||||
metadata['subdirs'] = row['Subdirs'] + path
|
metadata['subdirs'] = row['Subdirs'] + path
|
||||||
metadata['Filename'] = row['Filename']
|
metadata['Filename'] = row['Filename']
|
||||||
break
|
break
|
||||||
|
@ -994,6 +1003,7 @@ class Collection(SortMedias):
|
||||||
subdirs = set()
|
subdirs = set()
|
||||||
for src_path, metadata in self.medias.get_metadatas(src_dirs, imp=imp, loc=loc):
|
for src_path, metadata in self.medias.get_metadatas(src_dirs, imp=imp, loc=loc):
|
||||||
# Get the destination path according to metadata
|
# Get the destination path according to metadata
|
||||||
|
self.log.info(f'src_path: {src_path}')
|
||||||
fpath = FPath(path_format, self.opt['Path']['day_begins'])
|
fpath = FPath(path_format, self.opt['Path']['day_begins'])
|
||||||
metadata['file_path'] = fpath.get_path(metadata)
|
metadata['file_path'] = fpath.get_path(metadata)
|
||||||
subdirs.add(src_path.parent)
|
subdirs.add(src_path.parent)
|
||||||
|
|
|
@ -173,9 +173,10 @@ class Config:
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
if self.is_option('Path', 'name') and self.is_option('dirs_path', option):
|
if option == 'path_format':
|
||||||
# Path format is split in two parts
|
if self.is_option('Path', 'name') and self.is_option('Path', 'dirs_path'):
|
||||||
value = self.conf['Path']['dirs_path'] + '/' + self.conf['Path']['name']
|
# Path format is split in two parts
|
||||||
|
value = self.conf['Path']['dirs_path'] + '/' + self.conf['Path']['name']
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue