summaryrefslogtreecommitdiff
path: root/icktool
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-11-24 23:46:18 +0100
committerLars Wirzenius <liw@liw.fi>2017-11-24 23:46:18 +0100
commit1e141c37b49536fe65e2c7dde3eee69b14b3eb56 (patch)
tree8614c72bd5e33b8b7249c64cb89d3cde5ddd819b /icktool
parent2fb6fd3069504014a06d32b526308844b6f06690 (diff)
downloadick2-1e141c37b49536fe65e2c7dde3eee69b14b3eb56.tar.gz
Add: icktool status
Diffstat (limited to 'icktool')
-rwxr-xr-xicktool73
1 files changed, 68 insertions, 5 deletions
diff --git a/icktool b/icktool
index 8a04fe1..8b89a84 100755
--- a/icktool
+++ b/icktool
@@ -102,9 +102,43 @@ class Icktool(cliapp.Application):
obj = json.loads(text)
self._prettyson(obj)
- def cmd_list_projects(self, args):
+ def cmd_status(self, args):
+ rows = []
+ projects = self._get_projects()
+ builds = self._get_builds()['builds']
+ for project in projects['projects']:
+ pipelines = project['pipelines']
+ for pipeline in pipelines:
+ build = self._get_latest_build(
+ project['project'], pipeline['name'], builds)
+ row = {
+ 'project': project['project'],
+ 'pipeline': pipeline['name'],
+ 'build_id': build['build_id'],
+ 'status': pipeline['status'],
+ 'log': build['log'],
+ }
+ rows.append(row)
+ self._pretty_table(rows, ['project', 'pipeline', 'status', 'log'])
+
+ def _get_projects(self):
rc = self._new_rc('/projects', 'project')
- self._prettyson(rc.list())
+ return rc.list()
+
+ def _get_builds(self):
+ rc = self._new_rc('/builds', 'build')
+ return rc.list()
+
+ def _get_latest_build(self, project_name, pipeline_name, builds):
+ latest = None
+ for build in builds:
+ if (build['project'] == project_name and
+ build['pipeline'] == pipeline_name):
+ latest = build
+ return latest
+
+ def cmd_list_projects(self, args):
+ self._prettyson(self._get_projects())
def cmd_create_project(self, args):
rc = self._new_rc('/projects', 'project')
@@ -190,8 +224,7 @@ class Icktool(cliapp.Application):
rc.delete(name)
def cmd_list_builds(self, args):
- rc = self._new_rc('/builds', 'build')
- self._prettyson(rc.list())
+ self._prettyson(self._get_builds())
def cmd_list_logs(self, args):
rc = self._new_rc('/logs', 'log')
@@ -214,7 +247,9 @@ class Icktool(cliapp.Application):
gen = TokenGenerator()
gen.set_cmd(cmd)
gen.set_scopes(scopes)
- return gen.new_token()
+ token = gen.new_token()
+ self.settings['token'] = token
+ return token
def _new_api(self):
token = self.settings['token'] or self._new_token()
@@ -235,6 +270,34 @@ class Icktool(cliapp.Application):
def _read_object(self):
return yaml.load(sys.stdin)
+ def _pretty_table(self, rows, columns):
+ headings = {
+ column: column
+ for column in columns
+ }
+
+ widths = {
+ column: 0
+ for column in columns
+ }
+
+ for row in [headings] + rows:
+ for column in columns:
+ widths[column] = max(widths[column], len(row[column]))
+
+ underlines = {
+ column: '-' * widths[column]
+ for column in columns
+ }
+
+ for row in [headings, underlines] + rows:
+ self.output.write(
+ '{}\n'.format(self._pretty_row(widths, row, columns)))
+
+ def _pretty_row(self, widths, row, columns):
+ parts = ['%*s' % (widths[c], row[c]) for c in columns]
+ return ' | '.join(parts)
+
class API: