]> git.ipfire.org Git - pakfire.git/commitdiff
client: Allow watching jobs
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 2 Dec 2016 10:38:11 +0000 (11:38 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 2 Dec 2016 10:38:11 +0000 (11:38 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/cli.py
src/pakfire/client.py

index 743b631ac36b6edeb8407e76aefb5b40bbac6f40..0099d74bb74b1c094faa9dd9388e8781d79de26e 100644 (file)
@@ -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)
index fe38dd0b58391a22c4f9fa81ad004fa13cb2f040..b2a06e7739c5567f77f4df4d280b85c1e330421e 100644 (file)
@@ -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)