def _getDir(self, rootName, folder, template): if folder != None: folder = self._expandDir(folder) folder = fileutils.ensureAbsDirPath(folder) folder = fileutils.cleanupPath(folder) return virtualpath.VirtualPath(folder, rootName) folder = fileutils.ensureAbsDirPath(template % self.subdir) folder = fileutils.cleanupPath(folder) return virtualpath.VirtualPath(folder, rootName)
def __loadAdminData(self): self.debug("Loading admin data from '%s'", self._adminPath) loader = inifile.IniFile() adminData = dataprops.AdminData() loader.loadFromFile(adminData, self._adminPath) self._adminData = adminData basePath = os.path.dirname(self._adminPath) relDir = self._adminData.customersDir absPath = fileutils.makeAbsolute(relDir, basePath) absDir = fileutils.ensureAbsDirPath(absPath) self._customersDir = absDir fileutils.ensureDirExists(self._customersDir, "customers configuration") self.debug("Loading customers data from directory '%s'", absDir) self._customersData.clear() files = os.listdir(absDir) for f in files: if f.startswith(".") or not f.endswith('.ini'): self.log("Ignoring customer data file '%s'", f) continue self.log("Loading customer data file '%s'", f) data = dataprops.CustomerData() try: loader.loadFromFile(data, absDir + f) except Exception, e: log.notifyException(self, e, "Fail to load customer data " "from file '%s'", absDir + f) continue identifier = f.rsplit(os.path.extsep, 1)[0] self._customersData[identifier] = data
def __loadActivityData(self): basePath = os.path.dirname(self._adminPath) relDir = self._adminData.activitiesDir absPath = fileutils.makeAbsolute(relDir, basePath) absDir = fileutils.ensureAbsDirPath(absPath) self._activeActivitiesDir = absDir self._failedActivitiesDir = fileutils.ensureAbsDirPath(absDir + "failed") self._doneActivitiesDir = fileutils.ensureAbsDirPath(absDir + "done") self._invalidActivitiesDir = fileutils.ensureAbsDirPath(absDir + "invalid") fileutils.ensureDirExists(self._activeActivitiesDir, "activities data base") fileutils.ensureDirExists(self._failedActivitiesDir, "failed activities") fileutils.ensureDirExists(self._doneActivitiesDir, "done activities") fileutils.ensureDirExists(self._invalidActivitiesDir, "invalid activities") self.debug("Loading activities data from directory '%s'", absDir) loader = inifile.IniFile() self._activitiesData.clear() files = os.listdir(absDir) for f in files: if not f.endswith('.ini'): self.log("Ignoring activity data file '%s'", f) continue if f.startswith("transcoding-"): data = dataprops.TranscodingActivityData() elif f.startswith("notification-"): data = dataprops.NotificationActivityData() else: self.log("Ignoring activity data file '%s'", f) continue self.log("Loading activity data file '%s'", f) try: loader.loadFromFile(data, absDir + f) except Exception, e: log.notifyException(self, e, "Fail to load activity data " "from file '%s'", absDir + f) self.__safeMove(absDir, self._invalidActivitiesDir, f) continue if data.state == ActivityStateEnum.done: self.__safeMove(absDir, self._doneActivitiesDir, f) elif data.state == ActivityStateEnum.failed: self.__safeMove(absDir, self._failedActivitiesDir, f) else: self._activitiesData[f] = (absDir + f, data)
def __get__(self, obj, type=None): storeValue = getattr(obj.store, self._storePropertyName) if storeValue != None: value = obj._expandDir(storeValue) value = fileutils.ensureAbsDirPath(value) value = fileutils.cleanupPath(value) return virtualpath.VirtualPath(value) return getattr(obj.parent, self._basePropertyName)
def _getFileFromWork(self, path): workDir = self.getWorkDir().localize(self.local) workDir = fileutils.ensureAbsDirPath(workDir) workDir = re.escape(workDir) pattern = "^%s%s" % (workDir, WORK_FILE_PATTERN % self._random) regex = re.compile(pattern) match = regex.match(os.path.realpath(path)) if not match: raise Exception("'%s' is not a temporary file" % path) return match.group(1)
def __init__(self, tag, oldConfigFile, newConfigDir, rootDir, disableRequests=None, changeMail=None, keepConfig=None, doBackup=True): self._tag = tag self._oldFile = oldConfigFile self._newDir = fileutils.ensureAbsDirPath(newConfigDir) self._rootDir = fileutils.ensureAbsDirPath(rootDir) self._disableRequests = disableRequests or False self._changeMail = changeMail self._keepConfig = keepConfig or False self._doBackup = doBackup self._adminConfigPath = self._newDir + "transcoder-admin.ini" self._adminDataPath = self._newDir + "transcoder-data.ini" self._customerDataDir = self._newDir + "customers/" self._customerDataRelDir = "customers" if self._tag: self._tempDir = "/var/tmp/flumotion/transcoder/%s/" % self._tag else: self._tempDir = "/var/tmp/flumotion/transcoder/" if not os.path.exists(self._customerDataDir): os.makedirs(self._customerDataDir)
def upgradeAdminData(self, oldConfig): self.debug("Creating data container for transcoder global data") adminData = dataprops.AdminData() adminData.accessForceGroup = oldConfig.groupName adminData.discovererMaxInterleave = oldConfig.maxInterleave adminData.customersDir = self._customerDataRelDir base = fileutils.ensureAbsDirPath("/var/cache/flumotion/transcoder/%s" % self._tag) adminData.activitiesDir = base + "activities" self.info("Saving transcoder global data to '%s'", self._adminDataPath) saver = inifile.IniFile() saver.saveToFile(adminData, self._adminDataPath)