Package arcmap :: Module datafiles
[hide private]
[frames] | no frames]

Source Code for Module arcmap.datafiles

  1  ################################################################################ 
  2  # Authors: Brian Schott (Sir Alaran) 
  3  # Copyright: Brian Schott (Sir Alaran) 
  4  # Date: Sep 24 2009 
  5  # License: 
  6  # 
  7  # This program is free software: you can redistribute it and/or modify 
  8  # it under the terms of the GNU General Public License as published by 
  9  # the Free Software Foundation, either version 3 of the License, or 
 10  # (at your option) any later version. 
 11  # 
 12  # This program is distributed in the hope that it will be useful, 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 15  # GNU General Public License for more details. 
 16  # 
 17  # You should have received a copy of the GNU General Public License 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 19  ################################################################################ 
 20   
 21  """ 
 22  Functions for getting paths for data files 
 23  """ 
 24   
 25  import os 
 26  import sys 
 27  import platform 
 28  import preferences 
 29  try: 
 30          import _winreg 
 31  except ImportError: 
 32          pass 
 33   
34 -def programDataPath():
35 """ 36 @rtype: str 37 @return: the directory for the program's read-only data 38 Mac OS-X support is non-existant 39 """ 40 if platform.system() == "Windows": 41 try: 42 key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Arctographer") 43 except WindowsError: 44 path = "." 45 else: 46 path = _winreg.QueryValueEx(key, "Path")[0] 47 return path 48 elif platform.system() == "Linux": 49 possibilities = [ 50 "/usr/share/arctographer", 51 "/usr/share/games/arctographer", 52 "/usr/local/share/arctographer", 53 "/usr/local/share/games/arctographer", 54 os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir) 55 ] 56 for p in possibilities: 57 if os.path.exists(p): 58 return p 59 else: 60 raise Exception("Unsupported operating system")
61
62 -def userConfigPath():
63 """ 64 Mac OS-X support is non-existant 65 @rtype: str 66 @return: the directory for storting user configuration files 67 """ 68 if platform.system() == "Windows": 69 path = os.path.join(os.path.expanduser("~"), "AppData", "Local", "Artographer-0.3") 70 return path 71 elif platform.system() == "Linux": 72 path = os.path.join(os.path.expanduser("~"), ".config", "arctographer") 73 return path 74 else: 75 raise Exception("Unsupported operating system")
76 77
78 -def getIconPath(iconName):
79 """ 80 Gets the path that icons are stored in 81 """ 82 return os.path.join(programDataPath(), "icons", iconName)
83
84 -def getTilesetPath(fileName):
85 """ 86 Gets the path for a tileset 87 """ 88 if preferences.files["use_prefixes"]: 89 return os.path.join(preferences.files["data_prefix"], 90 preferences.files["tileset_prefix"], 91 os.path.basename(fileName)) 92 else: 93 return fileName
94
95 -def getParallaxPath(fileName):
96 """ 97 Gets a path for a parallax background 98 """ 99 if preferences.files["use_prefixes"]: 100 return os.path.join(preferences.files["data_prefix"], 101 preferences.files["parallax_prefix"], 102 os.path.basename(fileName)) 103 else: 104 return fileName
105 106
107 -class FileNotFoundError(Exception):
108 - def __init__(self, fileName):
109 self.__fileName = fileName
110
111 - def __str__(self):
112 return (("Could not find the file \"%s\". Please check your file " 113 +"preferences and make sure that the file exists.") 114 % self.__fileName)
115