]> git.ipfire.org Git - pbs.git/blame - src/web/handlers_jobs.py
Use autotools
[pbs.git] / src / web / handlers_jobs.py
CommitLineData
f6e6ff79
MT
1#!/usr/bin/python
2
3import tornado.web
4
5from handlers_base import BaseHandler
6
7
9177f86a
MT
8class JobsIndexHandler(BaseHandler):
9 def get(self):
10 # Filter for a certain arch.
11 arch_name = self.get_argument("arch", None)
12 if arch_name:
13 arch = self.pakfire.arches.get_by_name(arch_name)
14 else:
15 arch = None
16
17 # Check if we need to filter for a certain builder.
18 builder_name = self.get_argument("builder", None)
19 if builder_name:
20 builder = self.pakfire.builders.get_by_name(builder_name)
21 else:
22 builder = None
23
24 # Filter for a certain date.
25 date = self.get_argument("date", None)
26
27 # Get all jobs, that fulfill the criteria.
28 jobs = self.pakfire.jobs.get_latest(limit=50, arch=arch, builder=builder,
29 date=date)
30
31 self.render("jobs-index.html", jobs=jobs, arch=arch, builder=builder,
32 date=date)
33
34
35class JobsFilterHandler(BaseHandler):
36 def get(self):
37 arches = self.pakfire.arches.get_all(really=True)
38 builders = self.pakfire.builders.get_all()
39
40 self.render("jobs-filter.html", arches=arches, builders=builders)
41
42
f6e6ff79
MT
43class JobDetailHandler(BaseHandler):
44 def get(self, uuid):
45 job = self.pakfire.jobs.get_by_uuid(uuid)
46 if not job:
47 raise tornado.web.HTTPError(404, "No such job: %s" % job)
48
49 # Cache the log.
50 log = job.get_log()
51
52 self.render("jobs-detail.html", job=job, build=job.build, log=log)
53
54
55class JobBuildrootHandler(BaseHandler):
8cfba2fb 56 def get(self, uuid):
f6e6ff79
MT
57 job = self.pakfire.jobs.get_by_uuid(uuid)
58 if not job:
59 raise tornado.web.HTTPError(404, "Job not found: %s" % uuid)
60
f6e6ff79
MT
61 tries = self.get_argument("tries", None)
62 buildroot = job.get_buildroot(tries)
63
8cfba2fb
MT
64 # Calculate the download size and buildroot size.
65 download_size = 0
66 buildroot_size = 0
67
68 for name, uuid, pkg in buildroot:
69 if not pkg:
70 continue
71
72 download_size += pkg.filesize
73 buildroot_size += pkg.size
74
75 self.render("jobs-buildroot.html", job=job, build=job.build,
76 buildroot=buildroot, download_size=download_size,
77 buildroot_size=buildroot_size)
f6e6ff79
MT
78
79
80class JobScheduleHandler(BaseHandler):
81 allowed_types = ("test", "rebuild",)
82
83 @tornado.web.authenticated
84 def get(self, uuid):
85 type = self.get_argument("type")
86 assert type in self.allowed_types
87
88 job = self.pakfire.jobs.get_by_uuid(uuid)
89 if not job:
90 raise tornado.web.HTTPError(404, "Job not found: %s" % uuid)
91
92 self.render("job-schedule-%s.html" % type, type=type, job=job, build=job.build)
93
94 @tornado.web.authenticated
95 def post(self, uuid):
96 type = self.get_argument("type")
97 assert type in self.allowed_types
98
99 job = self.pakfire.jobs.get_by_uuid(uuid)
100 if not job:
101 raise tornado.web.HTTPError(404, "Job not found: %s" % uuid)
102
103 # Get the start offset.
104 offset = self.get_argument("offset", 0)
105 try:
106 offset = int(offset)
107 except TypeError:
108 offset = 0
109
110 # Submit the build.
111 if type == "test":
112 job = job.schedule_test(offset)
113
114 elif type == "rebuild":
115 job.schedule_rebuild(offset)
116
117 self.redirect("/job/%s" % job.uuid)
118
119
120class JobAbortHandler(BaseHandler):
121 def get_job(self, uuid):
122 job = self.pakfire.jobs.get_by_uuid(uuid)
123 if not job:
124 raise tornado.web.HTTPError(404, "Job not found: %s" % uuid)
125
126 return job
127
128 @tornado.web.authenticated
129 def get(self, uuid):
130 job = self.get_job(uuid)
131
132 # XXX Check if user has the right to manage the job.
133
134 self.render("jobs-abort.html", job=job)
135
136 @tornado.web.authenticated
137 def post(self, uuid):
138 job = self.get_job(uuid)
139
140 # XXX Check if user has the right to manage the job.
141
142 # Only running builds can be set to aborted state.
143 if not job.state == "running":
144 # XXX send the user a nicer error message.
145 self.redirect("/job/%s" % job.uuid)
146 return
147
148 # Set the job into aborted state.
149 job.state = "aborted"
150
151 # 0 means the job was aborted by the user.
152 job.aborted_state = 0
153
154 self.redirect("/job/%s" % job.uuid)