chiark / gitweb /
Store the user data in the home directory for linux/mac.
authorDaid <Daid303@gmail.com>
Mon, 22 Oct 2012 12:01:19 +0000 (14:01 +0200)
committerDaid <Daid303@gmail.com>
Mon, 22 Oct 2012 12:01:19 +0000 (14:01 +0200)
Cura/util/profile.py
Cura/util/version.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
index e5701a8ba601ee716434da9904993f6bd13766a8..052ab7bd62dc63424712d363bb8e010d6622e73d 100644 (file)
@@ -1,9 +1,11 @@
 import os
 
-def getVersion():
+def getVersion(getGitVersion = True):
        gitPath = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], "../../.git"))
        versionFile = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], "../version"))
        if os.path.exists(gitPath):
+               if not getGitVersion:
+                       return "dev"
                f = open(gitPath + "/refs/heads/master", "r")
                version = f.readline()
                f.close()