From: Michael Tremer Date: Fri, 2 Dec 2016 10:38:11 +0000 (+0100) Subject: client: Allow watching jobs X-Git-Tag: 0.9.28~1285^2~1432 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=badb4cf28b88ef3ef1d62f3eef03d823f45a98c3;p=pakfire.git client: Allow watching jobs Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/cli.py b/src/pakfire/cli.py index 743b631ac..0099d74bb 100644 --- a/src/pakfire/cli.py +++ b/src/pakfire/cli.py @@ -899,6 +899,11 @@ class CliClient(Cli): watch_build.add_argument("id", nargs=1, help=_("Build ID")) watch_build.set_defaults(func=self.handle_watch_build) + # watch-job + watch_job = subparsers.add_parser("watch-job", help=_("Watch the status of a job")) + watch_job.add_argument("id", nargs=1, help=_("Job ID")) + watch_job.set_defaults(func=self.handle_watch_job) + return parser.parse_args() def handle_build(self, ns): @@ -953,13 +958,21 @@ class CliClient(Cli): def handle_watch_build(self, ns): build = self.client.get_build(ns.id[0]) + return self._watch_something(build) + + def handle_watch_job(self, ns): + job = self.client.get_job(ns.id[0]) + + return self._watch_something(job) + + def _watch_something(self, o): while True: - s = build.dump() + s = o.dump() print(s) - # Break the loop if the build is not active any more + # Break the loop if the build/job is not active any more # (since we don't expect any changes) - if not build.is_active(): + if not o.is_active(): break time.sleep(60) diff --git a/src/pakfire/client.py b/src/pakfire/client.py index fe38dd0b5..b2a06e773 100644 --- a/src/pakfire/client.py +++ b/src/pakfire/client.py @@ -59,6 +59,8 @@ class Client(object): """ return self.hub.test() + # Builds + def create_build(self, filename, **kwargs): build_id = self.hub.create_build(filename, **kwargs) @@ -67,6 +69,11 @@ class Client(object): def get_build(self, build_id): return Build(self, build_id) + # Jobs + + def get_job(self, job_id): + return Job(self, job_id) + class _ClientObject(object): def __init__(self, client, id): @@ -203,6 +210,20 @@ class Job(_ClientObject): def __lt__(self, other): return self.arch < other.arch + @property + def name(self): + """ + The name of this job + """ + return self.data.get("name") + + @property + def type(self): + """ + The type of this build + """ + return self.data.get("type") + @property def arch(self): """ @@ -254,3 +275,22 @@ class Job(_ClientObject): s.append(_("in %s") % format_time(self.duration)) return " ".join(s) + + def dump(self): + s = [] + + # Name + s.append(self.name) + + # Append tag for test buils + if self.type == "test": + s.append("[T]") + + # UUID + s.append("(%s)" % self.id) + + # Show the builder for active jobs + if self.is_active() and self.builder: + s.append(_("Builder: %s") % self.builder) + + return " ".join(s)