From f474800d94255a60ed535727b9e25e97db66e5cb Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Wed, 4 Oct 2023 10:08:11 +0200 Subject: [PATCH] Arch: Made Arch Reference case-insensitive - issue #10874 --- src/Mod/Arch/ArchReference.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Mod/Arch/ArchReference.py b/src/Mod/Arch/ArchReference.py index 968fce78ddb4..ae2e209d5f08 100644 --- a/src/Mod/Arch/ArchReference.py +++ b/src/Mod/Arch/ArchReference.py @@ -213,6 +213,18 @@ def cleanShape(self,shapedata,obj,materials): print(obj.Label,": error removing splitter") return shape + def exists(self,filepath): + + "case-insensitive version of os.path.exists. Returns the actual file path or None" + + if os.path.exists(filepath): + return filepath + base, ext = os.path.splitext(filepath) + for e in [".fcstd",".FCStd",".FCSTD"]: + if os.path.exists(base + e): + return base + e + return None + def getFile(self,obj,filename=None): "gets a valid file, if possible" @@ -223,15 +235,15 @@ def getFile(self,obj,filename=None): return None if not filename.lower().endswith(".fcstd"): return None - if not os.path.exists(filename): + if not self.exists(filename): # search for the file in the current directory if not found basename = os.path.basename(filename) currentdir = os.path.dirname(obj.Document.FileName) altfile = os.path.join(currentdir,basename) if altfile == obj.Document.FileName: return None - elif os.path.exists(altfile): - return altfile + elif self.exists(altfile): + return self.exists(altfile) else: # search for subpaths in current folder altfile = None @@ -239,10 +251,10 @@ def getFile(self,obj,filename=None): for i in range(len(subdirs)): subpath = [currentdir]+subdirs[-i:]+[basename] altfile = os.path.join(*subpath) - if os.path.exists(altfile): - return altfile + if self.exists(altfile): + return self.exists(altfile) return None - return filename + return self.exists(filename) def getPartsList(self,obj,filename=None):