def dist_git_importing_queue(): """ Return list of builds that are waiting for dist git to import the sources. """ builds_list = [] for task in BuildsLogic.get_build_importing_queue().limit(200): copr = task.build.copr # we are using fake username's here if copr.is_a_group_project: user_name = u"@{}".format(copr.group.name) else: user_name = copr.owner.name task_dict = { "task_id": "{}-{}".format(task.build.id, helpers.chroot_to_branch(task.mock_chroot.name)), "user": user_name, "project": task.build.copr.name, "branch": helpers.chroot_to_branch(task.mock_chroot.name), "source_type": task.build.source_type, "source_json": task.build.source_json, } if task_dict not in builds_list: builds_list.append(task_dict) response_dict = {"builds": builds_list} return flask.jsonify(response_dict)
def dist_git_importing_queue(): """ Return list of builds that are waiting for dist git to import the sources. """ builds_list = [] builds_for_import = BuildsLogic.get_build_importing_queue().filter(models.Build.is_background == false()).limit(200).all() if not builds_for_import: builds_for_import = BuildsLogic.get_build_importing_queue().filter(models.Build.is_background == true()).limit(30) for task in builds_for_import: copr = task.build.copr task_dict = { "task_id": task.import_task_id, "user": copr.owner_name, # TODO: user -> owner "project": task.build.copr.name, "branch": helpers.chroot_to_branch(task.mock_chroot.name), "source_type": task.build.source_type, "source_json": task.build.source_json, } if task_dict not in builds_list: builds_list.append(task_dict) response_dict = {"builds": builds_list} return flask.jsonify(response_dict)
def waiting(): """ Return list of waiting actions and builds. """ # models.Actions actions_list = [ action.to_dict(options={ "__columns_except__": ["result", "message", "ended_on"] }) for action in actions_logic.ActionsLogic.get_waiting() ] # tasks represented by models.BuildChroot with some other stuff builds_list = [] for task in BuildsLogic.get_build_task_queue().limit(200): try: copr = task.build.copr # we are using fake username's here if copr.is_a_group_project: user_name = u"@{}".format(copr.group.name) else: user_name = copr.user.name record = { "task_id": task.task_id, "build_id": task.build.id, "project_owner": user_name, "project_name": task.build.copr.name, "submitter": task.build.user.name if task.build.user else None, # there is no user for webhook builds "pkgs": task.build.pkgs, # TODO to be removed "chroot": task.mock_chroot.name, "repos": task.build.repos, "memory_reqs": task.build.memory_reqs, "timeout": task.build.timeout, "enable_net": task.build.enable_net, "git_repo": task.build.package.dist_git_repo, "git_hash": task.git_hash, "git_branch": helpers.chroot_to_branch(task.mock_chroot.name), "package_name": task.build.package.name, "package_version": task.build.pkg_version } copr_chroot = CoprChrootsLogic.get_by_name_safe(task.build.copr, task.mock_chroot.name) if copr_chroot: record["buildroot_pkgs"] = copr_chroot.buildroot_pkgs else: record["buildroot_pkgs"] = "" builds_list.append(record) except Exception as err: app.logger.exception(err) response_dict = {"actions": actions_list, "builds": builds_list} return flask.jsonify(response_dict)
def waiting(): """ Return list of waiting actions and builds. """ # models.Actions actions_list = [ action.to_dict( options={"__columns_except__": ["result", "message", "ended_on"]}) for action in actions_logic.ActionsLogic.get_waiting() ] # tasks represented by models.BuildChroot with some other stuff builds_list = [] for task in BuildsLogic.get_build_task_queue().limit(200): try: copr = task.build.copr # we are using fake username's here if copr.is_a_group_project: user_name = u"@{}".format(copr.group.name) else: user_name = copr.owner.name record = { "task_id": "{}-{}".format(task.build.id, task.mock_chroot.name), "build_id": task.build.id, "project_owner": user_name, "project_name": task.build.copr.name, "submitter": task.build.user.name, "pkgs": task.build.pkgs, # TODO to be removed "chroot": task.mock_chroot.name, "repos": task.build.repos, "memory_reqs": task.build.memory_reqs, "timeout": task.build.timeout, "enable_net": task.build.enable_net, "git_repo": task.build.package.dist_git_repo, "git_hash": task.git_hash, "git_branch": helpers.chroot_to_branch(task.mock_chroot.name), "package_name": task.build.package.name, "package_version": task.build.pkg_version } copr_chroot = CoprChrootsLogic.get_by_name_safe( task.build.copr, task.mock_chroot.name) if copr_chroot: record["buildroot_pkgs"] = copr_chroot.buildroot_pkgs else: record["buildroot_pkgs"] = "" builds_list.append(record) except Exception as err: app.logger.exception(err) response_dict = {"actions": actions_list, "builds": builds_list} return flask.jsonify(response_dict)
def run(self, chroot_names, branch=None): for chroot_name in chroot_names: if not branch: branch = chroot_to_branch(chroot_name) branch_object = coprs_logic.BranchesLogic.get_or_create(branch) try: chroot = coprs_logic.MockChrootsLogic.add(chroot_name) chroot.distgit_branch = branch_object db.session.commit() except exceptions.MalformedArgumentException: self.print_invalid_format(chroot_name) except exceptions.DuplicateException: self.print_already_exists(chroot_name)
def create_chroot_function(chroot_names, branch=None, activated=True): """Creates a mock chroot in DB""" for chroot_name in chroot_names: if not branch: branch = chroot_to_branch(chroot_name) branch_object = coprs_logic.BranchesLogic.get_or_create(branch) try: chroot = coprs_logic.MockChrootsLogic.add(chroot_name) chroot.distgit_branch = branch_object chroot.is_active = activated db.session.commit() except exceptions.MalformedArgumentException: print_invalid_format(chroot_name) except exceptions.DuplicateException: print_already_exists(chroot_name)
def waiting(): """ Return a single action and a single build. """ action_record = None build_record = None action = actions_logic.ActionsLogic.get_waiting().first() if action: action_record = action.to_dict(options={ "__columns_except__": ["result", "message", "ended_on"] }) task = BuildsLogic.get_build_task() if task: try: build_record = { "task_id": task.task_id, "build_id": task.build.id, "project_owner": task.build.copr.owner_name, "project_name": task.build.copr.name, "submitter": task.build.user.name if task.build.user else None, # there is no user for webhook builds "pkgs": task.build.pkgs, # TODO to be removed "chroot": task.mock_chroot.name, "repos": task.build.repos, "memory_reqs": task.build.memory_reqs, "timeout": task.build.timeout, "enable_net": task.build.enable_net, "git_repo": task.build.package.dist_git_repo, "git_hash": task.git_hash, "git_branch": helpers.chroot_to_branch(task.mock_chroot.name), "package_name": task.build.package.name, "package_version": task.build.pkg_version } copr_chroot = CoprChrootsLogic.get_by_name_safe(task.build.copr, task.mock_chroot.name) if copr_chroot: build_record["buildroot_pkgs"] = copr_chroot.buildroot_pkgs else: build_record["buildroot_pkgs"] = "" except Exception as err: app.logger.exception(err) response_dict = {"action": action_record, "build": build_record} return flask.jsonify(response_dict)
def import_task_id(self): return "{}-{}".format(self.build_id, helpers.chroot_to_branch(self.name))