inconsistent paths returned for windows builds

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

inconsistent paths returned for windows builds

Post by looo »

I guess this is the root of the problem we encounter with the conda-windows builds which do not show images in the StartPage.
see here: https://forum.freecadweb.org/viewtopic. ... 50#p260478

Code: Select all

>>> FreeCAD.getHomePath()
'C:/Users/katja/Miniconda3/envs/freecad/Library/'
>>> FreeCAD.getResourceDir()
'C:/Users/katja/Miniconda3/envs/freecad/Library/data/'
>>> FreeCAD.getUserAppDataDir()
'C:\\Users\\katja\\AppData\\Roaming\\FreeCAD\\'
>>> FreeCAD.getUserMacroDir()
'C:\\Users\\katja\\AppData\\Roaming\\FreeCAD\\Macro/'
os.path.join will work different for these paths:

Code: Select all

>>> os.path.join(FreeCAD.getHomePath(), "test")
'C:/Users/katja/Miniconda3/envs/freecad/Library/test'
>>> os.path.join(FreeCAD.getResourceDir(), "test")
'C:/Users/katja/Miniconda3/envs/freecad/Library/data/test'
>>> os.path.join(FreeCAD.getUserAppDataDir(), "test")
'C:\\Users\\katja\\AppData\\Roaming\\FreeCAD\\test'
>>> os.path.join(FreeCAD.getUserMacroDir(), "test")
'C:\\Users\\katja\\AppData\\Roaming\\FreeCAD\\Macro/test'
So it seems only FreeCAD.getUserAppDataDir() works correctly. The others seems to have either mixed separators or unix separators, which do not work on windows. os.path.join seems to look at the ending separator and slects either windows or unix style. So I guess these function should all return windows paths for windows builds. Any ideas why separators are mixed here?
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: inconsistent paths returned for windows builds

Post by looo »

Another way to fix the paths in the html-file is to write a "file:///" in front of the paths. At least this worked in the browser.
yorik wrote:
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: inconsistent paths returned for windows builds

Post by looo »

@wmayer any idea where to fix this?
User avatar
yorik
Founder
Posts: 13660
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: inconsistent paths returned for windows builds

Post by yorik »

Normally by passing a path to python's os module we should be able to get rid of this problem, as it can take any combination of \ and /.
For the startpage, there are likely several problems there:

- "hard-coded" icons(the icons in the "help" tab), that is, their path is something like userappdata/path/to/icons
- icons created on the fly and stored in the temp directory (basically all the file/mime icons). python os.mkdtemp is what is used to create these temp files.
- the URLs that are called when you click on a file. These urls are relative (ex. just "LoadMRU.py"), so normally they should just work, independently of where they are, there is no C: or D: path there
Post Reply