From 5356257c1db0bafbd09b96082bf95be4bf1f89a2 Mon Sep 17 00:00:00 2001
From: madsmpedersen <m@madsp.dk>
Date: Mon, 11 Jul 2016 14:19:43 +0200
Subject: [PATCH] unix_filename function

---
 wetb/utils/process_exec.py | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/wetb/utils/process_exec.py b/wetb/utils/process_exec.py
index 6626cee..adde550 100644
--- a/wetb/utils/process_exec.py
+++ b/wetb/utils/process_exec.py
@@ -36,7 +36,7 @@ def pexec(args, cwd=None):
     stdout, stderr = proc.communicate()
     errorcode = proc.returncode
 
-    return errorcode, stdout.decode(), stderr.decode(), cmd
+    return errorcode, stdout.decode('cp1252'), stderr.decode('cp1252'), cmd
 
 
 def process(args, cwd=None):
@@ -59,4 +59,31 @@ def exec_process(process):
 
     return errorcode, stdout.decode(), stderr.decode()
 
+def unix_filename(filename):
+    """Convert case insensitive filename into unix case sensitive filename
+
+    I more than one case insensitive matching file or folder is found, case sensitive matching is used
+
+    Parameters
+    ---------
+    x : str
+        Case insensitive filename
+
+    Returns
+    -------
+    Filename
+
+    """
+    filename = os.path.realpath(filename).replace("\\", "/")
+    ufn, rest = os.path.splitdrive(filename)
+    ufn += "/"
+    for f in rest[1:].split("/"):
+        f_lst = [f_ for f_ in os.listdir(ufn) if f_.lower() == f.lower()]
+        if len(f_lst) > 1:
+            f_lst = [f_ for f_ in f_lst if f_ == f]
+        if len(f_lst) == 0:
+            raise IOError("'%s' not found in '%s'" % (f, ufn))
+        ufn = os.path.join(ufn, f_lst[0])
+    return ufn.replace("\\", "/")
+
 
-- 
GitLab