def addOsIfNotFound(self, session: Session, osInfo: OsInfo) \ -> OperatingSystem: """ Insert operating system into the db if it is not found. """ try: return self.getOsInfo(session, osInfo.getName(), osInfo.getVersion(), osInfo.getArch()) except OsNotFound: pass # Translate osInfo tmpOsInfo = osHelper.getOsInfo(osInfo.getName(), osInfo.getVersion(), osInfo.getArch()) # Check for existence of OS family dbOsFamily = self.addOsFamilyIfNotFound(session, tmpOsInfo.getOsFamilyInfo()) dbOs = OperatingSystem(name=osInfo.getName(), version=osInfo.getVersion(), arch=osInfo.getArch()) dbOs.family = dbOsFamily session.add(dbOs) return dbOs
def __configure(self): """ Configure all repositories from the config file. """ self._kitArchiveDir = self._cm.getKitDir() configFile = self._cm.getRepoConfigFile() if not os.path.exists(configFile): self._logger.debug('Repo configuration file [%s] not found' % (configFile)) else: self._logger.debug('Reading repo configuration file [%s]' % (configFile)) configParser = configparser.ConfigParser() configParser.read(configFile) try: osKeyList = configParser.sections() if osKeyList: self._logger.debug('Found OS sections [%s]' % (' '.join(osKeyList))) for osKey in osKeyList: self._logger.debug('Parsing OS section [%s]' % (osKey)) osData = osKey.split('__') osName = osData[0] osVersion = osData[1] osArch = osData[2] osInfo = OsInfo(osName, osVersion, osArch) # Ignore all repos that weren't enabled bEnabled = True if configParser.has_option(osKey, 'enabled'): value = configParser.get(osKey, 'enabled') bEnabled = value.lower() == 'true' if not bEnabled: self._logger.debug('Repo for [%s] is disabled' % (osInfo)) continue localPath = None if configParser.has_option(osKey, 'localPath'): localPath = configParser.get(osKey, 'localPath', True) if not localPath: localPath = self._repoRoot remoteUrl = None if configParser.has_option(osKey, 'remoteUrl'): remoteUrl = configParser.get(osKey, 'remoteUrl', True) repo = self.__configureRepo(osInfo, localPath, remoteUrl) self._repoMap[osKey] = repo if not os.path.exists(self._kitArchiveDir): self._logger.debug('Creating kit archive directory [%s]' % (self._kitArchiveDir)) os.makedirs(self._kitArchiveDir) osInfo = osUtility.getNativeOsInfo() repo = self.__configureRepo(osInfo, self._repoRoot) osKey = '%s__%s__%s' % (osInfo.getName(), osInfo.getVersion(), osInfo.getArch()) # Configure repo for native os if there are no repos configured. if osKey not in self._repoMap: self._repoMap[osKey] = repo except ConfigurationError: raise except Exception as ex: raise ConfigurationError(exception=ex)