From a085dbceac4e911a743c84388b55a0a8f2ba320b Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Wed, 17 Aug 2022 11:04:31 -0700 Subject: Allow config.py to save/load config from zookeeper. No watching yet. --- file_utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'file_utils.py') diff --git a/file_utils.py b/file_utils.py index 7a64f9f..b7cd6bc 100644 --- a/file_utils.py +++ b/file_utils.py @@ -92,6 +92,23 @@ def remove(path: str) -> None: os.remove(path) +def fix_multiple_slashes(path: str) -> str: + """Fixes multi-slashes in paths or path-like strings + + Args: + path: the path in which to remove multiple slashes + + >>> p = '/usr/local//etc/rc.d///file.txt' + >>> fix_multiple_slashes(p) + '/usr/local/etc/rc.d/file.txt' + + >>> p = 'this is a test' + >>> fix_multiple_slashes(p) == p + True + """ + return re.sub(r'/+', '/', path) + + def delete(path: str) -> None: """This is a convenience for my dumb ass who can't remember os.remove sometimes. -- cgit v1.3