From 5a6f50e8b285c4f7e7a40627af19ab403234df42 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 21 Apr 2018 15:14:14 +0300 Subject: Add: show-log, status sorts by project name, show any resource, etc --- icktool | 52 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) (limited to 'icktool') diff --git a/icktool b/icktool index 4328841..025a74d 100755 --- a/icktool +++ b/icktool @@ -137,6 +137,10 @@ class Icktool(cliapp.Application): cmd = self._command(ShowCommand) cmd.execute(args) + def cmd_show_log(self, args): + cmd = self._command(ShowLogCommand) + cmd.execute(args) + def _command(self, klass): api = self._new_api() token = self._new_token(api) @@ -279,7 +283,8 @@ class StatusCommand(Command): projects = self.api.show('/projects') builds = self.api.show('/builds') - for project in projects['projects']: + projects = self._sort_projects(projects) + for project in projects: project_name = project['project'] project_status = self.api.show( '/projects/{}/status'.format(project_name)) @@ -293,13 +298,21 @@ class StatusCommand(Command): build = _latest_build(project_name, builds) if build: - row['build_status'] = build['status'] + bs = build['status'] + if bs == 0: + bs = 'OK' + elif isinstance(bs, int): + bs = 'FAILED ({})'.format(bs) + row['build_status'] = bs row['log_id'] = build['log'] table.append_row(**row) self.output.write(table.format()) + def _sort_projects(self, projects): + return list(sorted(projects['projects'], key=lambda p: p['project'])) + class BuildGraphCommand(Command): @@ -366,22 +379,26 @@ class MakeItSoCommand(Command): def execute(self, args): obj = self._read_object() - self._create_resources('/projects', obj.get('projects', [])) - self._create_resources('/pipelines', obj.get('pipelines', [])) + self._create_resources('/projects', 'project', obj.get('projects', [])) + self._create_resources('/pipelines', 'pipeline', obj.get('pipelines', [])) def _read_object(self): return yaml.load(sys.stdin) - def _create_resources(self, path, objs): + def _create_resources(self, path, name_field, objs): for obj in objs: - self.api.create(path, obj) + try: + self.api.create(path, obj) + except ick2.HttpError: + update_path = '{}/{}'.format(path, obj[name_field]) + self.api.update(update_path, obj) class TriggerCommand(Command): def execute(self, args): - project = args[0] - self._prettyson(self.api.trigger(project)) + for project in args: + self._prettyson(self.api.trigger(project)) class ShowCommand(Command): @@ -389,13 +406,24 @@ class ShowCommand(Command): def execute(self, args): if not args: args = [ - 'projects', - 'pipelines', + '/projects', + '/pipelines', ] - for kind in args: - objs = self.api.show('/' + kind) + for what in args: + objs = self.api.show(what) self._prettyson(objs) +class ShowLogCommand(Command): + + def execute(self, args): + for log_id in args: + log = self.api.show_blob(log_id) + log = log.decode('UTF-8') + self.output.write(log) + if not log.endswith('\n'): + self.output.write('\n') + + Icktool(version=ick2.__version__).run() -- cgit v1.2.1