summaryrefslogtreecommitdiff
path: root/file_utils.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2022-08-17 11:04:31 -0700
committerScott Gasch <[email protected]>2022-08-17 11:04:31 -0700
commita085dbceac4e911a743c84388b55a0a8f2ba320b (patch)
tree7444b742bb51dac862bec102b15abba7d2bafd26 /file_utils.py
parent581d759e55faf532fcf3c89d59eae929ede24dd7 (diff)
Allow config.py to save/load config from zookeeper. No watching yet.
Diffstat (limited to 'file_utils.py')
-rw-r--r--file_utils.py17
1 files changed, 17 insertions, 0 deletions
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.