summaryrefslogtreecommitdiff
path: root/ick
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-05-09 10:08:24 +0300
committerLars Wirzenius <liw@liw.fi>2015-05-09 11:52:54 +0300
commit0dd8fdc5aab5d5947501421aff41d6c68b5a8da8 (patch)
tree22edceab9c9f1910e23cb98a141297206b3b38a6 /ick
parent0e8bbdf268eb1cb42f8ef9792fb51ec0b915d0e1 (diff)
downloadick-0dd8fdc5aab5d5947501421aff41d6c68b5a8da8.tar.gz
Implement the program
This allows the test suite to start working, even if it doesn't actually do anything.
Diffstat (limited to 'ick')
-rwxr-xr-xick107
1 files changed, 107 insertions, 0 deletions
diff --git a/ick b/ick
new file mode 100755
index 0000000..1d30a23
--- /dev/null
+++ b/ick
@@ -0,0 +1,107 @@
+#!/usr/bin/env python2
+# Copyright 2015 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# =*= License: GPL-3+ =*=
+
+
+import logging
+import subprocess
+
+import cliapp
+import yaml
+
+
+class Ick(cliapp.Application):
+
+ def process_args(self, args):
+ filename = self.parse_command_line_args(args)
+ ick = self.read_ick_file(filename)
+ self.logger = Logger(self.output)
+ self.build_projects(ick)
+
+ def parse_command_line_args(self, args):
+ if len(args) != 1:
+ raise cliapp.AppException('Must have exactly one argument')
+ return args[0]
+
+ def read_ick_file(self, filename):
+ with open(filename) as f:
+ return yaml.safe_load(f)
+
+ def build_projects(self, ick):
+ targets = ick.get('targets', {})
+ projects = ick.get('projects', {})
+ for project_name, project in projects.items():
+ self.build_project(project_name, project, targets)
+
+ def build_project(self, project_name, project, targets):
+ with self.logger:
+ self.logger.log(
+ 'Building project {project_name}', project_name=project_name)
+ for target_name, target in targets.items():
+ self.build_on_target(
+ project_name, project, target_name, target)
+
+ def build_on_target(self, project_name, project, target_name, target):
+ with self.logger:
+ self.logger.log(
+ 'Building {project_name} on {target_name}',
+ project_name=project_name, target_name=target_name)
+ for command in project.get('commands', []):
+ self.run_on_target(target['address'], command)
+
+ def run_on_target(self, address, command):
+ with self.logger:
+ self.logger.log(
+ 'On {address} run {command}',
+ address=address, command=command)
+ output = cliapp.ssh_runcmd(
+ address,
+ ['sh', '-euxc', command],
+ stderr=subprocess.STDOUT)
+ self.log_output(output)
+
+ def log_output(self, output):
+ with self.logger:
+ for lineno, line in enumerate(output.splitlines()):
+ self.logger.log(
+ '{lineno:>04}: {line}',
+ lineno=lineno+1,
+ line=line)
+
+
+class Logger(object):
+
+ def __init__(self, output):
+ self._level = 0
+ self._output = output
+
+ def __enter__(self):
+ self._level += 1
+
+ def __exit__(self, *args):
+ self._level -= 1
+
+ def log(self, msg, **kwargs):
+ one_indent = ' ' * 2
+ indent = one_indent * (self._level - 1)
+ formatted = indent + msg.format(**kwargs)
+ logging.info(formatted)
+ self._output.write(formatted + '\n')
+
+
+if __name__ == '__main__':
+ Ick().run()