From 659bc5b577097a451b162c9c552e803e3a824e39 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 20 Apr 2018 18:09:20 +0300 Subject: Change: adjust to _new_token change, add status and trigger commands --- icktool | 56 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'icktool') diff --git a/icktool b/icktool index 100f08a..81dd035 100755 --- a/icktool +++ b/icktool @@ -109,21 +109,47 @@ class Icktool(cliapp.Application): self.output.write('{}\n'.format(scope)) def cmd_token(self, args): - token = self._new_token() + api = self._new_api() + token = self._new_token(api) self.output.write('{}\n'.format(token)) def cmd_version(self, args): - token = self._new_token() api = self._new_api() + token = self._new_token(api) api.set_token(token) version = api.get_version() self._prettyson(version) + def cmd_status(self, args): + api = self._new_api() + token = self._new_token(api) + api.set_token(token) + projects = api.show('/projects') + builds = api.show('/builds') + for project in projects['projects']: + project_name = project['project'] + status = api.show('/projects/{}/status'.format(project_name)) + build = self._latest_build(project_name, builds) + self._prettyson(builds) + if build: + actions = build['actions'] + current = build['current_action'] + log = build['log'] + print(project_name, status['status'], log, actions[current]) + else: + print(project_name, status['status'], 'no builds') + + def _latest_build(self, project_name, builds): + builds = [b for b in builds['builds'] if b['project'] == project_name] + if builds: + return builds[-1] + return None + def cmd_make_it_so(self, argv): obj = self._read_object() - token = self._new_token() api = self._new_api() + token = self._new_token(api) api.set_token(token) self._create_resources(api, '/projects', obj.get('projects', [])) @@ -136,9 +162,16 @@ class Icktool(cliapp.Application): for obj in objs: api.create(path, obj) + def cmd_trigger(self, args): + project = args[0] + api = self._new_api() + token = self._new_token(api) + api.set_token(token) + self._prettyson(api.trigger(project)) + def cmd_show(self, args): - token = self._new_token() api = self._new_api() + token = self._new_token(api) api.set_token(token) if not args: args = [ @@ -184,19 +217,4 @@ class Icktool(cliapp.Application): self.output.write('\n') -class Command: - - def __init__(self, api): - self._api = api - - def execute(self): - raise NotImplementedError() - - -class VersionCommand(Command): - - def execute(self): - self._api.get_version() - - Icktool(version=ick2.__version__).run() -- cgit v1.2.1