#!/usr/bin/env python # -*- coding: utf-8 -*- # This file is part of Cockpit. # # Copyright (C) 2017 Red Hat, Inc. # # Cockpit is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Cockpit is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with Cockpit; If not, see . PRIORITY = 9 NAMES = [ "example-task", "po-refresh", "image-refresh", "koji-build", "npm-update", ] KVM_TASKS = [ "image-refresh" ] REDHAT_TASKS = [ "rhel-7", "rhel-atomic" ] # Server to tell us if we can create Red Hat images REDHAT_PING = "http://file.rdu.redhat.com" # Credentials for working on above contexts REDHAT_CREDS = "~/.rhel/login" import argparse import pipes import os import sys import urllib sys.dont_write_bytecode = True from task import github from task import sink BOTS = os.path.normpath(os.path.join(os.path.dirname(__file__))) BASE = os.path.normpath(os.path.join(BOTS, "..")) def main(): parser = argparse.ArgumentParser(description="Scan issues for tasks") parser.add_argument("-v", "--human-readable", "--verbose", action="store_true", default=False, dest="verbose", help="Print verbose information") opts = parser.parse_args() kvm = os.access("/dev/kvm", os.R_OK | os.W_OK) if not kvm: sys.stderr.write("tests-scan: No /dev/kvm access, not creating images here\n") try: urllib.urlopen(REDHAT_PING).read() redhat = os.path.exists(os.path.expanduser(REDHAT_CREDS)) except IOError: redhat = False for result in scan(opts.verbose): if not kvm and contains_any(result, KVM_TASKS): continue elif not redhat and contains_any(result, REDHAT_TASKS): continue sys.stdout.write(result + "\n") return 0 def contains_any(string, matches): for match in matches: if match in string: return True return False # Map all checkable work items to fixtures def tasks_for_issues(): results = [ ] whitelist = github.whitelist() for issue in github.GitHub().issues(state="open"): if issue["title"].strip().startswith("WIP"): continue login = issue.get("user", { }).get("login", { }) if login not in whitelist: continue checklist = github.Checklist(issue["body"]) for item, checked in checklist.items.items(): if not checked: results.append((item, issue)) return results def output_task(command, issue, verbose): name, unused, context = command.partition(" ") if name not in NAMES: return None number = issue.get("number", None) if number is None: return None context = context.strip() if verbose: return "issue-{issue} {name} {context} {priority}".format( issue=int(number), priority=PRIORITY, name=name, context=context ) else: if context: context = pipes.quote(context) return "PRIORITY={priority:04d} bots/{name} --issue='{issue}' {context}".format( issue=int(number), priority=PRIORITY, name=name, context=context ) # Default scan behavior run for each task def scan(verbose): global issues results = [ ] # Now go through each fixture for (command, issue) in tasks_for_issues(): result = output_task(command, issue, verbose) if result is not None: results.append(result) return results if __name__ == '__main__': sys.exit(main())