vinaigrette/scripts/rebuildd-job

71 lines
2.1 KiB
Python

#!/usr/bin/python
from rebuildd.Rebuildd import Rebuildd
from rebuildd.RebuilddConfig import RebuilddConfig
from rebuildd.Package import Package
from rebuildd.JobStatus import JobStatus
from rebuildd.Job import Job
from tabulate import tabulate
import sys, os.path
import argparse
def main():
actions = {
"list": list_,
"add": add_
}
parser = argparse.ArgumentParser(description='A simple script to list and add rebuildd jobs, not shit like the original rebuildd-job :|.',
usage='''rebuildd-job <command> <args>
The available commands are :
list - Lists the most recent jobs
add - Add a specific job (for example to requeue a job that failed ...)
''')
parser.add_argument('action', help="Action to run")
if len(sys.argv) < 2:
parser.print_help()
exit(1)
args = parser.parse_args(sys.argv[1:2])
if not args.action in actions.keys():
print "Unrecognized action"
parser.print_help()
exit(1)
else:
Rebuildd()
actions[args.action]()
def list_():
parser = argparse.ArgumentParser(description='Lists the most recent jobs')
parser.add_argument('N', nargs="?", help="Number of jobs to list (10 by default)", default=10)
args = parser.parse_args(sys.argv[2:])
try:
args.N = int(args.N)
except:
raise AssertionError("Invalid value for N, not an integer ?")
jobs = Job.selectBy()[-args.N:]
headers = [ "id", "package", "version", "dist", "arch", "status" ]
data = [ [ job.id, job.package.name, job.package.version, job.dist, job.arch, JobStatus.whatis(job.status)] for job in jobs ]
print tabulate(data, headers=headers)
def add_():
parser = argparse.ArgumentParser(description='Lists the most recent jobs')
parser.add_argument('package')
parser.add_argument('version')
parser.add_argument('dist')
parser.add_argument('arch')
args = parser.parse_args(sys.argv[2:])
Rebuildd().add_job(args.package, args.version, 10, args.dist, mailto=None, arch=args.arch)
main()