summaryrefslogtreecommitdiff
path: root/icktool
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-04-21 15:14:14 +0300
committerLars Wirzenius <liw@liw.fi>2018-04-21 15:14:14 +0300
commit5a6f50e8b285c4f7e7a40627af19ab403234df42 (patch)
tree9eff07d7e54205da7a5dc477bb2ad62a01726f41 /icktool
parentf446562c11340ec9101802cfa7c917ed2eac1aa2 (diff)
downloadick2-5a6f50e8b285c4f7e7a40627af19ab403234df42.tar.gz
Add: show-log, status sorts by project name, show any resource, etc
Diffstat (limited to 'icktool')
-rwxr-xr-xicktool52
1 files changed, 40 insertions, 12 deletions
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()