diff clients/editor/scripts/settings.py @ 273:815354ba295e

* Added function to fife_utils: getUserDataDirectory. Returns the proper path to save setting and data files depending on OS. * Made rio_de_hola save its settings in the proper location.
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 16 Jun 2009 14:24:26 +0000
parents 987a4ea829c1
children 8b125ec749d7
line wrap: on
line diff
--- a/clients/editor/scripts/settings.py	Tue Jun 16 11:28:35 2009 +0000
+++ b/clients/editor/scripts/settings.py	Tue Jun 16 14:24:26 2009 +0000
@@ -1,5 +1,6 @@
 import shutil
 import os
+from fife_utils import getUserDataDirectory
 try:
 	import xml.etree.cElementTree as ET
 except:
@@ -20,7 +21,7 @@
 			
 		Settings.instance = self
 		
-		self._appdata = GetUserDataDirectory("fife", "editor")
+		self._appdata = getUserDataDirectory("fife", "editor")
 	
 		if os.path.exists(self._appdata+'/settings.xml') is False:
 			shutil.copyfile('settings-dist.xml', self._appdata+'/settings.xml')
@@ -219,52 +220,3 @@
 			dict[kv_pair[0]] = kv_pair[1]
 		return dict
 
-def GetUserDataDirectory(vendor, appname):
-	""" Gets location to store the settings file, depending on OS.
-	See:
-	Brian Vanderburg II @ http://mail.python.org/pipermail/python-list/2008-May/660779.html
-	"""
-	dir = ""
-
-	# WINDOWS
-	if os.name == "nt":
-
-		# Try env APPDATA or USERPROFILE or HOMEDRIVE/HOMEPATH
-		if "APPDATA" in os.environ:
-			dir = os.environ["APPDATA"]
-
-		if ((dir is None) or (not os.path.isdir(dir))) and ("USERPROFILE" in os.environ):
-			dir = os.environ["USERPROFILE"]
-			if os.path.isdir(os.path.join(dir, "Application Data")):
-				dir = os.path.join(dir, "Application Data")
-
-		if ((dir is None) or (not os.path.isdir(dir))) and ("HOMEDRIVE" in os.environ) and ("HOMEPATH" in os.environ):
-			dir = os.environ["HOMEDRIVE"] + os.environ["HOMEPATH"]
-			if os.path.isdir(os.path.join(dir, "Application Data")):
-				dir = os.path.join(dir, "Application Data")
-
-		if (dir is None) or (not os.path.isdir(dir)):
-			dir = os.path.expanduser("~")
-			
-		# On windows, add vendor and app name
-		dir = os.path.join(dir, vendor, appname)
-
-	# Mac
-	elif os.name == "mac": # ?? may not be entirely correct
-		dir = os.path.expanduser("~")
-		dir = os.path.join(dir, "Library", "Application Support")
-		dir = os.path.join(dir, vendor, appname)
-
-	# Unix/Linux/all others
-	if dir is None:
-		dir = os.path.expanduser("~")
-		dir = os.path.join(dir, "."+vendor, appname)
-		
-	# Create vendor/appname folder if it doesn't exist
-	if not os.path.isdir(dir):
-		os.makedirs(dir)
-		
-	print dir
-
-	return dir
-