def GetCatalogGenerationResult(sqo_osrel, sqo_arch, sqo_catrel): """Get rows with catalog results. CatalogEntry catalogname version pkgname basename md5_sum size deps category i_deps """ join = [ sqlbuilder.INNERJOINOn(None, Srv4FileInCatalog, Srv4FileInCatalog.q.srv4file==Srv4FileStats.q.id), sqlbuilder.INNERJOINOn(None, CatalogGenData, Srv4FileStats.q.md5_sum==CatalogGenData.q.md5_sum), sqlbuilder.INNERJOINOn(None, Maintainer, Srv4FileStats.q.maintainer==Maintainer.q.id), ] where = sqlbuilder.AND( Srv4FileInCatalog.q.osrel==sqo_osrel, Srv4FileInCatalog.q.arch==sqo_arch, Srv4FileInCatalog.q.catrel==sqo_catrel, Srv4FileStats.q.use_to_generate_catalogs==True, ) select = sqlbuilder.Select( ['catalogname', # 0 'version_string', # 1 'pkgname', # 2 'basename', # 3 'srv4_file_stats.md5_sum', # Hardcoded table name, is it portable? 'size', # 5 'deps', # 6 'i_deps', # 7 'pkginfo_name', # 8 # The above columns are used to generate catalogs. # Additional columns can be added blow. # 'maintainer.id', # 9 'maintainer.email', # 9 'mtime', # 10 'created_on', # 11 'created_by', # 12 'bundle', # 13 ], where=where, orderBy='catalogname', join=join) query = sqlobject.sqlhub.processConnection.sqlrepr(select) rows = sqlobject.sqlhub.processConnection.queryAll(query) return rows
def GetRecentlyBuiltPackages(): join = [ # sqlbuilder.INNERJOINOn(None, # Srv4FileInCatalog, # Srv4FileInCatalog.q.srv4file==Srv4FileStats.q.id), # sqlbuilder.INNERJOINOn(None, # CatalogGenData, # Srv4FileStats.q.md5_sum==CatalogGenData.q.md5_sum), ] where = sqlbuilder.AND( # Srv4FileStats.q.use_to_generate_catalogs==True, ) select = sqlbuilder.Select( [ 'srv4_file_stats.md5_sum', # Hardcoded table name, is it portable? 'srv4_file_stats.catalogname', # 'version_string', # 'pkgname', # 'basename', # 'size', # 'deps', # 'i_deps', # 'pkginfo_name', # The above columns are used to generate catalogs. # Additional columns can be added blow. 'srv4_file_stats.maintainer_id', 'srv4_file_stats.mtime', # 'created_on', # 'created_by', ], where=where, orderBy='-mtime', join=join, limit=30) query = sqlobject.sqlhub.processConnection.sqlrepr(select) rows = sqlobject.sqlhub.processConnection.queryAll(query) return rows
def robolog(self, team, last_received_ping=0): """ Return the log being appended direct from the robot. offset is the position to stream from. """ # First check to see if live robot logging is enabled on the server # If it isn't enabled then return "disabled" to tell client not to poll if not config.get("robolog.enabled"): return {"ping": 0, "data": "", "present": 0, "disabled": True} try: team = int(team) except ValueError: log.error("Invalid team value") return {"ping": 0, "data": "", "present": 0} try: last_received_ping = int(last_received_ping) except ValueError: log.error("Invalid last_received_ping") return {"ping": 0, "data": "", "present": 0} log.debug("RoboIde team = %d", team) log.debug("RoboIde last_received_ping = %d", last_received_ping) if not (team in srusers.getteams()): log.error("Team not in the users teams") log.error(srusers.getteams()) return {"ping": 0, "data": "", "present": 0} try: team = model.TeamNames.get(id=team) except: #Fake team! log.debug("Team not found") return {"ping": 0, "data": "", "present": 0} try: present = model.RoboPresent.selectBy(team=team)[0].present except: present = False most_recent_ping = 0 most_recent_ping_date = None robologs = model.RoboLogs.selectBy(team=team) robologs = robologs.orderBy(sqlbuilder.DESC(model.RoboLogs.q.id)) most_recent_ping = robologs[0].id log.debug("Robot presence is: %d" % present) last_received_ping = int(last_received_ping) logs = model.RoboLogs.select( sqlbuilder.AND(model.RoboLogs.q.team == team, model.RoboLogs.q.id > last_received_ping)) data = "\n".join([l.value for l in logs]) data = data.replace('&', '&') data = data.replace('"', '"') data = data.replace("'", ''') data = data.replace(">", '>') data = data.replace("<", '<') return { "data": data, "present": int(present), "ping": most_recent_ping }
def select(cls, clause=None, *args, **kwargs): parentClass = cls.sqlmeta.parentClass childUpdate = kwargs.pop('childUpdate', None) # childUpdate may have one of three values: # True: # select was issued by parent class to create child objects. # Execute select without modifications. # None (default): # select is run by application. If this class is inheritance # child, delegate query to the parent class to utilize # InheritableIteration optimizations. Selected records # are restricted to this (child) class by adding childName # filter to the where clause. # False: # select is delegated from inheritance child which is parent # of another class. Delegate the query to parent if possible, # but don't add childName restriction: selected records # will be filtered by join to the table filtered by childName. if (not childUpdate) and parentClass: if childUpdate is None: # this is the first parent in deep hierarchy addClause = parentClass.q.childName == cls.sqlmeta.childName # if the clause was one of TRUE varians, replace it if (clause is None) or (clause is sqlbuilder.SQLTrueClause) \ or ( isinstance(clause, string_type) and (clause == 'all')): clause = addClause else: # patch WHERE condition: # change ID field of this class to ID of parent class # XXX the clause is patched in place; it would be better # to build a new one if we have to replace field clsID = cls.q.id parentID = parentClass.q.id def _get_patched(clause): if isinstance(clause, sqlbuilder.SQLOp): _patch_id_clause(clause) return None elif not isinstance(clause, sqlbuilder.Field): return None elif (clause.tableName == clsID.tableName) \ and (clause.fieldName == clsID.fieldName): return parentID else: return None def _patch_id_clause(clause): if not isinstance(clause, sqlbuilder.SQLOp): return expr = _get_patched(clause.expr1) if expr: clause.expr1 = expr expr = _get_patched(clause.expr2) if expr: clause.expr2 = expr _patch_id_clause(clause) # add childName filter clause = sqlbuilder.AND(clause, addClause) return parentClass.select(clause, childUpdate=False, *args, **kwargs) else: return super(InheritableSQLObject, cls).select(clause, *args, **kwargs)