diff options
author | Lars Wirzenius <liw@liw.fi> | 2018-04-21 15:18:53 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2018-04-21 15:18:53 +0300 |
commit | e9e51f252d8188821162ea859f86d6ee664978e7 (patch) | |
tree | 9eff07d7e54205da7a5dc477bb2ad62a01726f41 | |
parent | c84ce7c6ab029dd788a87428d2d74e7f5c5a5cd4 (diff) | |
parent | 5a6f50e8b285c4f7e7a40627af19ab403234df42 (diff) | |
download | ick2-e9e51f252d8188821162ea859f86d6ee664978e7.tar.gz |
Merge: icktool fixes
-rw-r--r-- | ick2/client.py | 4 | ||||
-rwxr-xr-x | icktool | 52 |
2 files changed, 44 insertions, 12 deletions
diff --git a/ick2/client.py b/ick2/client.py index 008cfd7..7d0af57 100644 --- a/ick2/client.py +++ b/ick2/client.py @@ -210,6 +210,10 @@ class ControllerClient: url = self.url(path) return self._api.get_dict(url) + def show_blob(self, path): # pragma: no cover + url = self.url(path) + return self._api.get_blob(url) + def create(self, path, obj): # pragma: no cover url = self.url(path) return self._api.post(url, body=obj) @@ -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() |