Skip to content

Commit

Permalink
Arch: Made Arch Reference case-insensitive - issue FreeCAD#10874
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Oct 16, 2023
1 parent 71a9eca commit f474800
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/Mod/Arch/ArchReference.py
Expand Up @@ -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"
Expand All @@ -223,26 +235,26 @@ 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
subdirs = self.splitall(os.path.dirname(filename))
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):

Expand Down

0 comments on commit f474800

Please sign in to comment.