Bulk operations¶
Bulk operations are defined in dantalian.bulk
. These functions operate
on multiple file or entire directory trees.
-
dantalian.bulk.
clean_symlinks
(dirpath)¶ Remove all broken symlinks in the given directory tree.
-
dantalian.bulk.
rename_all
(rootpath, top, path, name)¶ Rename all links to the given file or directory.
Attempt to rename all links to the target under the rootpath to the given name, finding a name as necessary. If there are multiple links in a directory, the first will be renamed and the rest unlinked.
Parameters: - rootpath (str) – Base path for tagname conversions.
- top (str) – Path of search directory.
- path (str) – Path of target to rename.
- name (str) – New filename.
-
dantalian.bulk.
unlink_all
(rootpath, top, path)¶ Unlink all links to the target file or directory. This can be used to completely remove a file instead of needing to manually unlink each of its links.
Parameters: - rootpath (str) – Base path for tagname conversions.
- top (str) – Path of search directory.
- path (str) – Path of target.
Import and export¶
Import a path tag map, such as one returned from
export_tags()
.Tags each path with the given tagnames, thus “importing” tag data.
Parameters: - rootpath (str) – Base path for tag conversions.
- path_tag_map (dict) – Mapping of paths to lists of tagnames.
Export a path tag map.
Each file will only have one key path mapping to a list of tags. If full is
True
, each file will have one key path for each one of that file’s links, all mapping to the same list of tags.Example without full:
{'foo/file': ['//foo', '//bar']}
With
full
:{'foo/file': ['//foo', '//bar'], 'bar/file': ['//foo', '//bar']}
Parameters: - rootpath (str) – Base path for tag conversions.
- top (str) – Top of directory tree to export.
- full (bool) – Whether to include all paths to a file. Defaults to False.
Returns: Mapping of paths to lists of tagnames.
Return type: dict