Explorar o código

Minor refactor to use guard and replace instead of split+join

Signed-off-by: Daniel Nephin <[email protected]>
Daniel Nephin %!s(int64=10) %!d(string=hai) anos
pai
achega
5523c3d745
Modificáronse 1 ficheiros con 10 adicións e 12 borrados
  1. 10 12
      compose/service.py

+ 10 - 12
compose/service.py

@@ -943,23 +943,21 @@ def build_volume_binding(volume_spec):
 
 
 def normalize_paths_for_engine(external_path, internal_path):
-    """
-    Windows paths, c:\my\path\shiny, need to be changed to be compatible with
+    """Windows paths, c:\my\path\shiny, need to be changed to be compatible with
     the Engine. Volume paths are expected to be linux style /c/my/path/shiny/
     """
-    if IS_WINDOWS_PLATFORM:
-        if external_path:
-            drive, tail = os.path.splitdrive(external_path)
+    if not IS_WINDOWS_PLATFORM:
+        return external_path, internal_path
 
-            if drive:
-                reformatted_drive = "/{}".format(drive.lower().replace(":", ""))
-                external_path = reformatted_drive + tail
+    if external_path:
+        drive, tail = os.path.splitdrive(external_path)
 
-            external_path = "/".join(external_path.split("\\"))
+        if drive:
+            external_path = '/' + drive.lower().rstrip(':') + tail
 
-        return external_path, "/".join(internal_path.split("\\"))
-    else:
-        return external_path, internal_path
+        external_path = external_path.replace('\\', '/')
+
+    return external_path, internal_path.replace('\\', '/')
 
 
 def parse_volume_spec(volume_config):