def __init__(self, fileName, attrs={}, afterLoadProc=None, basePath="", defSubDir="", moduleFile="", createIfNotFound=True): if basePath != "": basePath = base.pathWithLastSlash(basePath) if not os.path.exists(basePath): log.logger.error("Config.__init__, cesta " + basePath + " neexistuje.") basePath = "" self.fileName = basePath + fileName self.afterLoadProc = afterLoadProc self.attrs = attrs # Tabulka vsech atributu, jak nactenych, tak povolenych self._remapTable = { } # Tabulka mapovani downloadfulldatabase -> downloadFullDatabase self.moduleFile = moduleFile self.createIfNotFound = createIfNotFound self.isDefault = True if attrs != None: for key in attrs: setattr(self, key, attrs[key]) if key != key.lower(): self._remapTable[key.lower()] = key if os.path.exists(basePath + fileName): self.fileName = basePath + fileName else: path = base.normalizePathSep(os.path.dirname(__file__)) pathItems = path.split(os.sep) for i in range(0, len(pathItems)): path = os.sep.join(pathItems[0:i]) + os.sep + fileName if os.path.exists(path): self.fileName = path break if self.fileName == "": self.fileName = basePath + fileName if createIfNotFound: msg = u"Konfigurační soubor %s nebyl nenalezen." % ( base.pathWithLastSlash(basePath) + self.fileName) log.logger.error(msg) self.save() log.logger.error( u"Soubor byl vytvořen ze šablony. Nastavte prosím jeho hodnoty a spusťte program znovu." ) import sys sys.exit() else: self.loadFile()
def getDataDirFullPath(): result = RUIANDownloadConfig().dataDir if not os.path.isabs(result): result = getRUIANDownloaderPath() + result result = os.path.normpath(result) result = base.pathWithLastSlash(result) return result
def getRUIANToolboxPath(): global x_RUIANToolboxPath if x_RUIANToolboxPath == None: x_RUIANToolboxPath = base.pathWithLastSlash( os.path.split(os.path.dirname(__file__))[0]) x_RUIANToolboxPath = x_RUIANToolboxPath.replace("/", os.sep) x_RUIANToolboxPath = x_RUIANToolboxPath.replace("\\", os.sep) return x_RUIANToolboxPath
def convertRUIANDownloadCfg(config): if config == None: return config.downloadFullDatabase = isTrue(config.downloadFullDatabase) config.uncompressDownloadedFiles = isTrue(config.uncompressDownloadedFiles) config.runImporter = isTrue(config.runImporter) config.dataDir = config.dataDir.replace("/", os.sep) config.dataDir = config.dataDir.replace("\\", os.sep) config.dataDir = base.pathWithLastSlash(config.dataDir) if not os.path.isabs(config.dataDir): result = os.path.dirname( config.moduleFile) + os.path.sep + config.dataDir result = os.path.normpath(result) config.dataDir = base.pathWithLastSlash(result) config.ignoreHistoricalData = isTrue(config.ignoreHistoricalData) RUIANDownloadInfoFile().load(config.dataDir + "Info.txt") pass
def getMasterPath(moduleFile): path = getParentPath(moduleFile) masterPath = os.path.split(path)[0] return base.pathWithLastSlash(masterPath)
def getParentPath(moduleFile): if moduleFile == "": moduleFile = __file__ path = os.path.dirname(moduleFile) parentPath = os.path.split(path)[0] return base.pathWithLastSlash(parentPath)
def getSubDirPath(subDir): path = os.path.dirname(__file__) masterPath = os.path.split(path)[0] return base.pathWithLastSlash(os.path.join(masterPath, subDir))