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 main(argv): if not UpgradeConfig.checkVersions(): print "ERROR: Configuration files definition changed, please update the upgrade script" usage="usage: %prog [-v] bootstrap|upgrade [OPTIONS]" parser = optparse.OptionParser(usage=usage, version=VERSION) parser.add_option('-v', '--verbose', action="count", dest="verbose", default=0, help="Print more information; use more than one time for even more information") parser.add_option('-t', '--tag', action="store", type="string", dest="tag", default="", help="Transcoder version tag; used to be able to install more " "than one version of the transcoder at the same time") parser.add_option('-o', '--old-config-file', action="store", type="string", dest="oldConfigFile", metavar="OLD_CONFIG_FILE", default=DEFAULT_OLD_CONFIG_FILE, help="The path to the old configuration file to upgrade from; " "default value: '%s'" % DEFAULT_OLD_CONFIG_FILE) parser.add_option('-n', '--new-config-dir', action="store", type="string", dest="newConfigDir", metavar="NEW_CONFIG_DIR", default=None, help="The path to the new configuration directory; " "default value: '%s'" % DEFAULT_NEW_CONFIG_DIR) parser.add_option('-r', '--root-dir', action="store", type="string", dest="rootDir", metavar="DEFAULT_ROOT_DIR", default=DEFAULT_ROOT_DIR, help="The path to the root directory of the transcoder files; " "default value: '%s'" % DEFAULT_ROOT_DIR) parser.add_option('', '--disable-requests', action="store_true", dest="disableRequests", default=False, help="Disable the GET requests configuration for done and filed transcoding") parser.add_option('', '--change-mail', action="store", type="string", dest="changeMail", help="Change the eMail used for notifying the transcoding failures") parser.add_option('', '--keep-config', action="store_true", dest="keepConfig", default=False, help="Keep the actual configuration file if it exists (flumotion-transcoder.ini)") parser.add_option('', '--disable-backup', action="store_false", dest="doBackup", default=True, help="Do not rename the old files, just delete them.") options, args = parser.parse_args(argv[1:]) Loggable.level = min(5, options.verbose + 2) if args == ['bootstrap']: oldConfigFile = fileutils.makeAbsolute(options.oldConfigFile) rootDir = fileutils.makeAbsolute(options.rootDir) newConfigDir = options.newConfigDir if not newConfigDir: newConfigDir = DEFAULT_NEW_CONFIG_DIR % options.tag newConfigDir = fileutils.makeAbsolute(newConfigDir) if not os.path.exists(oldConfigFile): parser.error("Old configuration file '%s' not found" % oldConfigFile) if not os.access(oldConfigFile, os.F_OK | os.R_OK): parser.error("Cannot read old configuration file '%s'; check permissions" % oldConfigFile) if not os.path.exists(newConfigDir): try: os.makedirs(newConfigDir) except Exception, e: parser.error("New configuration directory '%s' cannot be created: %s" % (newConfigDir, str(e))) if not os.access(newConfigDir, os.F_OK | os.R_OK | os.W_OK | os.X_OK): parser.error("Not enough permissions to use directory '%s' as " "the new configuration directory" % newConfigDir) if not os.path.exists(rootDir): try: os.makedirs(rootDir) except Exception, e: parser.error("Default transcoder root directory '%s' cannot be created: %s" % (rootDir, str(e)))