Allow config.py to save/load config from zookeeper. No watching yet.
[python_utils.git] / file_utils.py
index 7a64f9f3eef7f8073736863bc87d408db8f49695..b7cd6bc158fd6e4c9b490cf075f96d1d3f5278c8 100644 (file)
@@ -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.