def _getOsFamily(self, session: Session, osFamilyInfo: OsFamilyInfo) -> OperatingSystemFamily: \ # pylint: disable=no-self-use if osFamilyInfo.getName() and osFamilyInfo.getVersion() and \ osFamilyInfo.getArch(): osFamilyFilter = and_( OperatingSystemFamily.name == osFamilyInfo.getName(), OperatingSystemFamily.version == osFamilyInfo.getVersion(), OperatingSystemFamily.arch == osFamilyInfo.getArch()) elif osFamilyInfo.getName() and osFamilyInfo.getVersion(): osFamilyFilter = and_( OperatingSystemFamily.name == osFamilyInfo.getName(), OperatingSystemFamily.version == osFamilyInfo.getVersion(), OperatingSystemFamily.arch == None # noqa ) else: osFamilyFilter = and_( OperatingSystemFamily.name == osFamilyInfo.getName(), OperatingSystemFamily.version == None, # noqa OperatingSystemFamily.arch == None # noqa ) try: return session.query(OperatingSystemFamily).filter( osFamilyFilter).one() except NoResultFound: pass return None
def addOsFamilyIfNotFound(self, session: Session, osFamilyInfo: OsFamilyInfo) \ -> OperatingSystemFamily: familyName = osFamilyInfo.getName() familyVers = osFamilyInfo.getVersion() familyArch = osFamilyInfo.getArch() dbOsFamily = self._getOsFamily(session, osFamilyInfo) if dbOsFamily: return dbOsFamily # The 'root' entry is an exception since it doesn't have a # parent. Just add it... if familyName == 'root': dbOsFamily = self.__addOsFamilyRoot(session) else: # ... otherwise, check for the parent of the specified # and it's parent should be 'root' osFamilyInfoParent = OsFamilyInfo(familyName, familyVers) dbOsFamilyParent = self._getOsFamily(session, osFamilyInfoParent) if not dbOsFamilyParent: # Check for the root entry osFamilyInfoRoot = OsFamilyInfo('root') dbOsFamilyRoot = self._getOsFamily(session, osFamilyInfoRoot) if not dbOsFamilyRoot: dbOsFamilyRoot = self.__addOsFamilyRoot(session) dbOsFamilyParent = OperatingSystemFamily(name=familyName, version=familyVers) session.add(dbOsFamilyParent) dbOsFamilyRoot.children.append(dbOsFamilyParent) dbOsFamily = OperatingSystemFamily(name=familyName, version=familyVers, arch=familyArch) session.add(dbOsFamily) dbOsFamilyParent.children.append(dbOsFamily) return dbOsFamily