Skip to content

Commit

Permalink
Save path prefix changes in config file.
Browse files Browse the repository at this point in the history
When user changes a path prefix for missing videos and chooses
to apply this to other video paths for the file being opened,
this change will be saved in ~/.sleap/path_prefixes.yaml and
applied when opening files in the future to find missing videos.

Resolves issue #268.
  • Loading branch information
ntabris committed Jan 23, 2020
1 parent 196986d commit ee84530
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions sleap/io/pathutils.py
Expand Up @@ -66,6 +66,10 @@ def filenames_prefix_change(
filenames[i] = try_filename
check[i] = False

# Save prefix change in config file so that it can be used
# automatically in the future
save_path_prefix_replacement(old_prefix, new_prefix)


def fix_path_separator(path: str):
return path.replace("\\", "/")
Expand Down Expand Up @@ -106,6 +110,9 @@ def find_changed_subpath(old_path: str, new_path: str) -> Tuple[str, str]:
def fix_paths_with_saved_prefix(filenames, missing: Optional[List[bool]] = None):
path_prefix_conversions = util.get_config_yaml("path_prefixes.yaml")

if path_prefix_conversions is None:
return

for i, filename in enumerate(filenames):
if missing is not None:
if not missing[i]:
Expand All @@ -123,3 +130,9 @@ def fix_paths_with_saved_prefix(filenames, missing: Optional[List[bool]] = None)
if missing is not None:
missing[i] = False
continue


def save_path_prefix_replacement(old_prefix: str, new_prefix: str):
data = util.get_config_yaml("path_prefixes.yaml") or dict()
data[old_prefix] = new_prefix
util.save_config_yaml("path_prefixes.yaml", data)

0 comments on commit ee84530

Please sign in to comment.