Fix load path format from config
This commit is contained in:
parent
cf8b6a9dec
commit
e60dab7f3b
|
@ -15,5 +15,4 @@ day_begins=4
|
|||
|
||||
# Path format
|
||||
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(
|
||||
'--path-format',
|
||||
'-p',
|
||||
default=constants.DEFAULT_PATH_FORMAT,
|
||||
default=None,
|
||||
help='Custom featured path format',
|
||||
),
|
||||
click.option(
|
||||
|
@ -145,6 +145,7 @@ def _cli_sort(collection, src_paths, import_mode, remove_duplicates):
|
|||
loc = _cli_get_location(collection)
|
||||
|
||||
path_format = collection.opt['Path']['path_format']
|
||||
LOG.debug(f'path_format: {path_format}')
|
||||
|
||||
return collection.sort_files(
|
||||
src_paths, path_format, loc, import_mode, remove_duplicates
|
||||
|
|
|
@ -209,6 +209,19 @@ class FPath:
|
|||
)
|
||||
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:
|
||||
if this_part:
|
||||
regex = '[-_ .]'
|
||||
|
@ -229,9 +242,7 @@ class FPath:
|
|||
path = []
|
||||
path_parts = path_format.split('/')
|
||||
for path_part in path_parts:
|
||||
this_parts = path_part.split('|')
|
||||
for this_part in this_parts:
|
||||
part = self.get_path_part(this_part, metadata)
|
||||
part = self.get_path_part(path_part, metadata)
|
||||
|
||||
if part != '':
|
||||
# Check if all masks are substituted
|
||||
|
@ -242,9 +253,6 @@ class FPath:
|
|||
sys.exit(1)
|
||||
|
||||
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 part == '' or re.match(r'^\..*', part):
|
||||
|
@ -714,6 +722,7 @@ class Collection(SortMedias):
|
|||
|
||||
# Set client options
|
||||
for option, value in cli_options.items():
|
||||
if value not in (None, ()):
|
||||
for section in self.opt:
|
||||
self.opt[section][option] = value
|
||||
|
||||
|
@ -885,7 +894,7 @@ class Collection(SortMedias):
|
|||
metadata['src_path'] = row['SrcPath']
|
||||
# Check if row FilePath is a subpath of relpath
|
||||
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['Filename'] = row['Filename']
|
||||
break
|
||||
|
@ -994,6 +1003,7 @@ class Collection(SortMedias):
|
|||
subdirs = set()
|
||||
for src_path, metadata in self.medias.get_metadatas(src_dirs, imp=imp, loc=loc):
|
||||
# Get the destination path according to metadata
|
||||
self.log.info(f'src_path: {src_path}')
|
||||
fpath = FPath(path_format, self.opt['Path']['day_begins'])
|
||||
metadata['file_path'] = fpath.get_path(metadata)
|
||||
subdirs.add(src_path.parent)
|
||||
|
|
|
@ -173,7 +173,8 @@ class Config:
|
|||
|
||||
return value
|
||||
|
||||
if self.is_option('Path', 'name') and self.is_option('dirs_path', option):
|
||||
if option == 'path_format':
|
||||
if self.is_option('Path', 'name') and self.is_option('Path', 'dirs_path'):
|
||||
# Path format is split in two parts
|
||||
value = self.conf['Path']['dirs_path'] + '/' + self.conf['Path']['name']
|
||||
|
||||
|
|
Loading…
Reference in New Issue