MCPcopy
hub / github.com/ArchiveBox/ArchiveBox / pretty_path

Function pretty_path

archivebox/logging_util.py:546–566  ·  view source on GitHub ↗

convert paths like .../ArchiveBox/archivebox/../output/abc into output/abc

(path: Union[Path, str], pwd: Union[Path, str]=OUTPUT_DIR)

Source from the content-addressed store, hash-verified

544
545@enforce_types
546def pretty_path(path: Union[Path, str], pwd: Union[Path, str]=OUTPUT_DIR) -> str:
547 """convert paths like .../ArchiveBox/archivebox/../output/abc into output/abc"""
548 pwd = str(Path(pwd)) # .resolve()
549 path = str(path)
550
551 if not path:
552 return path
553
554 # replace long absolute paths with ./ relative ones to save on terminal output width
555 if path.startswith(pwd) and (pwd != '/'):
556 path = path.replace(pwd, '.', 1)
557
558 # quote paths containing spaces
559 if ' ' in path:
560 path = f'"{path}"'
561
562 # if path is just a plain dot, replace it back with the absolute path for clarity
563 if path == '.':
564 path = pwd
565
566 return path
567
568
569@enforce_types

Callers 3

printable_folder_statusFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected