chiark / gitweb /
Store the user data in the home directory for linux/mac.
[cura.git] / Cura / util / profile.py
index 599dcc3385e3ae803ff17681124d98219a40d004..62a32f9cc1f4f2ea56b959b5d3251c71622ca6a6 100644 (file)
@@ -3,11 +3,13 @@ from __future__ import division
 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.\r
 import __init__\r
 \r
-import os, traceback, math, re, zlib, base64, time, sys\r
+import os, traceback, math, re, zlib, base64, time, sys, platform \r
 if sys.version_info[0] < 3:\r
        import ConfigParser\r
 else:\r
        import configparser as ConfigParser\r
+
+from util import version
 \r
 #########################################################\r
 ## Default settings when none are found.\r
@@ -193,11 +195,16 @@ preferencesDefaultSettings = {
 \r
 ## Profile functions\r
 def getDefaultProfilePath():\r
-       basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))\r
-       #If we have a frozen python install, we need to step out of the library.zip\r
-       if hasattr(sys, 'frozen'):\r
-               basePath = os.path.normpath(os.path.join(basePath, ".."))\r
-       return os.path.normpath(os.path.join(basePath, "current_profile.ini"))\r
+       if platform.system() == "Windows":
+               basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))\r
+               #If we have a frozen python install, we need to step out of the library.zip\r
+               if hasattr(sys, 'frozen'):\r
+                       basePath = os.path.normpath(os.path.join(basePath, ".."))
+       else:
+               basePath = os.path.expanduser('~/.cura/%s' % version.getVersion(False))
+       if not os.path.isdir(basePath):
+               os.makedirs(basePath)\r
+       return os.path.join(basePath, 'current_profile.ini')\r
 \r
 def loadGlobalProfile(filename):\r
        #Read a configuration file as global config\r
@@ -305,11 +312,16 @@ global globalPreferenceParser
 globalPreferenceParser = None\r
 \r
 def getPreferencePath():\r
-       basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))\r
-       #If we have a frozen python install, we need to step out of the library.zip\r
-       if hasattr(sys, 'frozen'):\r
-               basePath = os.path.normpath(os.path.join(basePath, ".."))\r
-       return os.path.normpath(os.path.join(basePath, "preferences.ini"))\r
+       if platform.system() == "Windows":
+               basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))\r
+               #If we have a frozen python install, we need to step out of the library.zip\r
+               if hasattr(sys, 'frozen'):\r
+                       basePath = os.path.normpath(os.path.join(basePath, ".."))
+       else:
+               basePath = os.path.expanduser('~/.cura/%s' % version.getVersion(False))
+       if not os.path.isdir(basePath):
+               os.makedirs(basePath)\r
+       return os.path.join(basePath, 'preferences.ini')\r
 \r
 def getPreferenceFloat(name):\r
        try:\r