diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-11-24 23:46:18 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-11-24 23:46:18 +0100 |
commit | 1e141c37b49536fe65e2c7dde3eee69b14b3eb56 (patch) | |
tree | 8614c72bd5e33b8b7249c64cb89d3cde5ddd819b | |
parent | 2fb6fd3069504014a06d32b526308844b6f06690 (diff) | |
download | ick2-1e141c37b49536fe65e2c7dde3eee69b14b3eb56.tar.gz |
Add: icktool status
-rw-r--r-- | NEWS | 2 | ||||
-rwxr-xr-x | icktool | 73 |
2 files changed, 70 insertions, 5 deletions
@@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. Version 0.17+git, not yet released ---------------------------------- +* Add subommand `icktool status` which shows current status of every + pipeline in every project. Version 0.17, released 2017-11-19 ---------------------------------- @@ -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: |