From: Daid Date: Mon, 22 Oct 2012 12:01:19 +0000 (+0200) Subject: Store the user data in the home directory for linux/mac. X-Git-Tag: 13.03~240 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=09f404081ee2677ce688c5c73c055bdb7d9cdb62;p=cura.git Store the user data in the home directory for linux/mac. --- diff --git a/Cura/util/profile.py b/Cura/util/profile.py index 599dcc33..62a32f9c 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -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. import __init__ -import os, traceback, math, re, zlib, base64, time, sys +import os, traceback, math, re, zlib, base64, time, sys, platform if sys.version_info[0] < 3: import ConfigParser else: import configparser as ConfigParser + +from util import version ######################################################### ## Default settings when none are found. @@ -193,11 +195,16 @@ preferencesDefaultSettings = { ## Profile functions def getDefaultProfilePath(): - basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) - #If we have a frozen python install, we need to step out of the library.zip - if hasattr(sys, 'frozen'): - basePath = os.path.normpath(os.path.join(basePath, "..")) - return os.path.normpath(os.path.join(basePath, "current_profile.ini")) + if platform.system() == "Windows": + basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) + #If we have a frozen python install, we need to step out of the library.zip + if hasattr(sys, 'frozen'): + 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) + return os.path.join(basePath, 'current_profile.ini') def loadGlobalProfile(filename): #Read a configuration file as global config @@ -305,11 +312,16 @@ global globalPreferenceParser globalPreferenceParser = None def getPreferencePath(): - basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) - #If we have a frozen python install, we need to step out of the library.zip - if hasattr(sys, 'frozen'): - basePath = os.path.normpath(os.path.join(basePath, "..")) - return os.path.normpath(os.path.join(basePath, "preferences.ini")) + if platform.system() == "Windows": + basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) + #If we have a frozen python install, we need to step out of the library.zip + if hasattr(sys, 'frozen'): + 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) + return os.path.join(basePath, 'preferences.ini') def getPreferenceFloat(name): try: diff --git a/Cura/util/version.py b/Cura/util/version.py index e5701a8b..052ab7bd 100644 --- a/Cura/util/version.py +++ b/Cura/util/version.py @@ -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()