def get_configpath(self): """ Return the full path to the configuration file. @author: Brendan Johan Lee @contact: [email protected] @version: 1.0 @return: full path to .conf file @rtype: str """ configpath = os.path.expanduser(DEFAULT_PATH) fileUtils.check_dir(configpath) configpath = os.path.join(configpath, 'glocalizer.conf') return configpath
def __init__(self, configpath=None): configpath = os.path.expanduser(configpath or DEFAULT_PATH) self.mt_counter=0 self.configpath = fileUtils.check_dir(configpath) self.locationpath = os.path.join(self.configpath, 'locations') self.locations = {} #implementation of the method is set in maps.py:__init__() self.tile_repository = tilesRepoFS.TilesRepositoryFS(self) if (os.path.exists(self.locationpath)): self.read_locations() else: self.write_locations()
def coord_to_path(self, tile_coord, layer, mapServ): self.lock.acquire() path = os.path.join(self.configpath, mapServ) path = fileUtils.check_dir(path) path = fileUtils.check_dir(path, '%s' % LAYER_DIRS[layer]) path = fileUtils.check_dir(path, '%d' % tile_coord[2]) path = fileUtils.check_dir(path, "%d" % (tile_coord[0] / 1024)) path = fileUtils.check_dir(path, "%d" % (tile_coord[0] % 1024)) path = fileUtils.check_dir(path, "%d" % (tile_coord[1] / 1024)) self.lock.release() return os.path.join(path, "%d.png" % (tile_coord[1] % 1024))
def read(self, configpath): """ Read the configuration from a given file @author: Brendan Johan Lee @contact: [email protected] @version: 1.0 @param configpath: full path to file to read from @type configpath: str """ def read_config(section, keyOption, defaultValue, castFunction): """ Read a configuration option @author: Brendan Johan Lee @contact: [email protected] @version: 1.0 @param section: section to read from @type section: str @param keyOption: key to read @type keyOption: str @param defaultValue: value to use as default if option not existing @type defaultValue: castable @param castFunction: type to cast the object to before returning @type castFunction: castable @return: value of configuration option @rtype: castable """ try: strValue = config.get(section, keyOption) return castFunction(strValue) except Exception: return defaultValue config = ConfigParser.RawConfigParser() config.read(configpath) self.init_width = read_config(SECTION_INIT,'width', 550, int) self.init_height = read_config(SECTION_INIT,'height', 450, int) self.init_zoom = read_config(SECTION_INIT,'zoom', MAP_MAX_ZOOM_LEVEL-10, int) self.init_center = read_config(SECTION_INIT,'center', ((1,0),(9,200)), str_to_tuple) self.init_path = os.path.join(os.path.expanduser(USER_PATH), TILES_PATH) strPath = read_config(SECTION_INIT,'path', self.init_path, str) if not strPath.strip().lower() in ['none', '']: strPath = fileUtils.check_dir(strPath) if os.path.isdir(strPath): self.init_path = strPath self.map_service = read_config(SECTION_INIT,'map_service', MAP_SERVERS[GOOGLE], str) self.cloudMade_styleID = read_config(SECTION_INIT,'cloudmade_styleid', 1, int) self.db_host = read_config(SECTION_DATABASE,'host','localhost',str) self.db_port = read_config(SECTION_DATABASE,'port',5432,int) self.db_name = read_config(SECTION_DATABASE,'name','gloc',str) self.db_username = read_config(SECTION_DATABASE,'username','gloc',str) self.db_password = read_config(SECTION_DATABASE,'password','99ab97a',str)