diff options
author | Lars Wirzenius <liw@liw.fi> | 2016-02-24 19:37:17 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2016-02-24 20:07:51 +0200 |
commit | 199190d6cdd18a6374d4338ebb31bd8f2659e55a (patch) | |
tree | 5de3df1d51ce6397af200b6a8f1e5099e3063bd1 | |
parent | a5bd847ccfe517b8e1c0e5e5f93ac5a570203858 (diff) | |
download | ick-199190d6cdd18a6374d4338ebb31bd8f2659e55a.tar.gz |
Add --verbose option
-rw-r--r-- | NEWS | 3 | ||||
-rwxr-xr-x | ick | 34 | ||||
-rw-r--r-- | icklib/__init__.py | 1 | ||||
-rw-r--r-- | icklib/progress.py | 120 | ||||
-rw-r--r-- | icklib/project.py | 2 | ||||
-rw-r--r-- | without-tests | 1 |
6 files changed, 138 insertions, 23 deletions
@@ -10,6 +10,9 @@ Version 0.13+git, not yet released * Ick self-tests now include pep8 and pylint checkers. This resulted in some minor, non-functional changes to the source code. +* Ick now has an option `--verbose` to provide a third kind of + progress output: a wall of text to stdout. + Version 0.13, released 2016-02-16 ---------------------------------- @@ -18,7 +18,6 @@ import cliapp -import ttystatus import yaml import icklib @@ -36,13 +35,18 @@ class Ick(cliapp.Application): 'only build PROJECT (can be used multiple times)') self.settings.boolean( - ['quiet', 'silent'], + ['quiet', 'silent', 'q'], 'reduce how much output from commands is shown') + self.settings.boolean( + ['verbose', 'v'], + 'be more verbose and use wall-of-text progress reporting, ' + 'instead of a fancy terminal one') + def process_args(self, args): filename = self.parse_command_line_args(args) ick = self.read_ick_file(filename) - self.progress = self.create_ttystatus() + self.progress = self.create_progress() self.build_projects(ick) self.progress.finish() @@ -55,27 +59,13 @@ class Ick(cliapp.Application): with open(filename) as f: return yaml.safe_load(f) - def create_ttystatus(self): - ts = ttystatus.TerminalStatus(period=1) - + def create_progress(self): if self.settings['quiet']: - ts.max_output_lines = 0 + return icklib.QuietProgress() + elif self.settings['verbose']: + return icklib.VerboseProgress() else: - _, height = ts.get_terminal_size() - format_lines = [ - '%ElapsedTime() ' - 'Project %Index(project,projects) %String(project_name)', - 'Pipeline: %String(pipeline)', - 'Step: %String(step)', - 'Target: %String(target)', - 'Command: %String(command)', - 'Output: %String(line0)', - ] - ts.max_output_lines = height - len(format_lines) - for i in range(1, ts.max_output_lines): - format_lines.append(' : %%String(line%d)' % i) - ts.format('\n'.join(format_lines)) - return ts + return icklib.FancyProgress() def build_projects(self, ick): statedir = icklib.create_statedir_from_ick(ick) diff --git a/icklib/__init__.py b/icklib/__init__.py index bdc841b..bf04a7b 100644 --- a/icklib/__init__.py +++ b/icklib/__init__.py @@ -29,3 +29,4 @@ from .info import InformationStore from .buildinfo import BuildInformation from .projectinfo import ProjectInformation from .statedir import StateDirectory, create_statedir_from_ick +from .progress import QuietProgress, FancyProgress, VerboseProgress diff --git a/icklib/progress.py b/icklib/progress.py new file mode 100644 index 0000000..fc53d30 --- /dev/null +++ b/icklib/progress.py @@ -0,0 +1,120 @@ +# Copyright 2016 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 sys + +import ttystatus + + +class _Progress(object): + + def __init__(self): + self.max_output_lines = None + + def __setitem__(self, key, value): + raise NotImplementedError() + + def finish(self): + raise NotImplementedError() + + +class QuietProgress(_Progress): + + def __init__(self): + super(QuietProgress, self).__init__() + self.max_output_lines = 0 + + def __setitem__(self, key, value): + pass + + def finish(self): + pass + + +class FancyProgress(_Progress): + + def __init__(self): + super(FancyProgress, self).__init__() + self._ts = self._setup_ttystatus() + + def __setitem__(self, key, value): + self._ts[key] = value + + def finish(self): + self._ts.finish() + + def _setup_ttystatus(self): + ts = ttystatus.TerminalStatus(period=1) + + _, height = ts.get_terminal_size() + format_lines = [ + '%ElapsedTime() ' + 'Project %Index(project,projects) %String(project_name)', + 'Pipeline: %String(pipeline)', + 'Step: %String(step)', + 'Target: %String(target)', + 'Command: %String(command)', + 'Output: %String(line0)', + ] + + self.max_output_lines = height - len(format_lines) + for i in range(1, self.max_output_lines): + format_lines.append(' : %%String(line%d)' % i) + ts.format('\n'.join(format_lines)) + + return ts + + +class VerboseProgress(_Progress): + + def __init__(self): + super(VerboseProgress, self).__init__() + self.max_output_lines = 0 + self._values = {} + + def __setitem__(self, key, value): + if key not in self._values or self._values[key] != value: + self._values[key] = value + self._notify(key, value) + + def _notify(self, key, value): + indent = ' ' * 2 + formats = { + 'projects': None, + 'project': None, + 'project_name': 'Project: {key}', + 'pipeline': indent + 'pipeline: {key}', + 'step': indent*2 + '{value}', + 'target': indent*3 + '{value}', + 'command': indent*4 + '{value}', + } + +# sys.stdout.write('# {}={}\n'.format(key, value)) + if key.startswith('line'): + pass + elif key in formats: + if value: + fmt = formats[key] + if fmt is not None: + sys.stdout.write(formats[key].format(key=key, value=value)) + sys.stdout.write('\n') + else: + sys.stdout.write('==== {}={}\n'.format(key, value)) + + def finish(self): + pass diff --git a/icklib/project.py b/icklib/project.py index ce504c5..f7dbe68 100644 --- a/icklib/project.py +++ b/icklib/project.py @@ -191,7 +191,7 @@ class Project(object): def report_running_on_target(self, target, displayed_cmd): progress = { - 'target': target.address, + 'target': target.name, 'command': '\\n'.join(displayed_cmd.split('\n')), } for i in range(self.run_state.progress.max_output_lines): diff --git a/without-tests b/without-tests index 4fc40b0..cf75ea5 100644 --- a/without-tests +++ b/without-tests @@ -3,3 +3,4 @@ icklib/run_state.py icklib/project.py icklib/info.py icklib/version.py +icklib/progress.py |