mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-05-02 06:30:55 +08:00
Add ModuleBuild methods for getting list of streams, last build in a name:stream and all builds in name:stream:version.
This commit is contained in:
@@ -38,10 +38,12 @@ from module_build_service import db, log, get_url_for, app, conf
|
||||
import module_build_service.messaging
|
||||
|
||||
from sqlalchemy.orm import lazyload
|
||||
from sqlalchemy import func, and_
|
||||
import gi
|
||||
gi.require_version('Modulemd', '1.0') # noqa
|
||||
from gi.repository import Modulemd
|
||||
|
||||
|
||||
# Just like koji.BUILD_STATES, except our own codes for modules.
|
||||
BUILD_STATES = {
|
||||
# This is (obviously) the first state a module build enters.
|
||||
@@ -241,6 +243,42 @@ class ModuleBuild(MBSBase):
|
||||
if component.batch <= self.batch
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def get_last_build_in_all_streams(session, name):
|
||||
"""
|
||||
Returns list of all last ModuleBuilds in "ready" state for all
|
||||
streams for given module `name`.
|
||||
"""
|
||||
subq = session.query(
|
||||
func.max(ModuleBuild.id).label('id')
|
||||
).group_by(ModuleBuild.name, ModuleBuild.stream).filter_by(
|
||||
name=name, state=BUILD_STATES["ready"]).subquery('t2')
|
||||
query = session.query(ModuleBuild).join(
|
||||
subq, and_(ModuleBuild.id == subq.c.id))
|
||||
return query.all()
|
||||
|
||||
@staticmethod
|
||||
def get_last_build_in_stream(session, name, stream):
|
||||
"""
|
||||
Returns the last build in "ready" state for given name:stream.
|
||||
"""
|
||||
query = session.query(ModuleBuild)
|
||||
query = query.filter_by(name=name, stream=stream,
|
||||
state=BUILD_STATES["ready"])
|
||||
query = query.order_by(ModuleBuild.id.desc())
|
||||
return query.first()
|
||||
|
||||
@staticmethod
|
||||
def get_builds_in_version(session, name, stream, version):
|
||||
"""
|
||||
Returns list of all module builds in "ready" state for given
|
||||
name:stream:version - it means all the contexts of this module.
|
||||
"""
|
||||
query = session.query(ModuleBuild)
|
||||
query = query.filter_by(name=name, stream=stream, version=version,
|
||||
state=BUILD_STATES["ready"])
|
||||
return query.all()
|
||||
|
||||
def mmd(self):
|
||||
try:
|
||||
mmd = Modulemd.Module().new_from_string(self.modulemd)
|
||||
|
||||
Reference in New Issue
Block a user