From 4c089769989460b7bb5e255baaa0e2f5f8ed02ce Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 13 Jan 2018 15:36:05 +0200 Subject: Add: icktool make-it-so command --- icktool | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'icktool') diff --git a/icktool b/icktool index 9a5976a..b314c58 100755 --- a/icktool +++ b/icktool @@ -163,6 +163,22 @@ class Icktool(cliapp.Application): latest = build return latest + def cmd_make_it_so(self, args): + obj = self._read_object() + + projects = self._new_rc('/projects', 'project') + self._make_it_so(projects, obj.get('projects', [])) + + pipelines = self._new_rc('/pipelines', 'name') + self._make_it_so(pipelines, obj.get('pipelines', [])) + + def _make_it_so(self, rc, objs): + for obj in objs: + if projects.exists(obj): + projects.update(obj) + else: + project.create(obj) + def cmd_list_projects(self, args): self._prettyson(self._get_projects()) @@ -506,6 +522,10 @@ class ResourceCommands: self._report(code, 200, text) return json.loads(text) + def exists(self, obj): + code, text = self._api.get(self._id_path(obj[self._name])) + return code == 200 + def delete(self, name): code, text = self._api.delete(self._id_path(name)) self._report(code, 200, text) -- cgit v1.2.1