From 9daf600f77ecc116ff345e4f53c50994443e0973 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 14 Jul 2013 17:42:36 +0100 Subject: Add --verbose option for wall-of-text output --- yarn | 61 ++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 15 deletions(-) (limited to 'yarn') diff --git a/yarn b/yarn index c25a929..fb6e5a3 100755 --- a/yarn +++ b/yarn @@ -41,6 +41,12 @@ class YarnRunner(cliapp.Application): ['quiet', 'q'], 'be quiet, avoid progress reporting, only show errors') + self.settings.boolean( + ['verbose', 'v'], + 'make progress reporting be more verbose ("wall of text"), ' + 'instead of a one-line status info; this is turned ' + 'automatically if there is not terminal') + self.settings.string_list( ['shell-library', 's'], 'include a shell library for the IMPLEMENTS sections to use') @@ -62,22 +68,46 @@ class YarnRunner(cliapp.Application): 'after each scenario step; you probably ' 'want to use this with --tempdir') - def setup(self): + def info(self, msg): + if self.settings['verbose']: + logging.info(msg) + self.output.write('%s\n' % msg) + + def warning(self, msg): + if self.settings['verbose']: + logging.warning(msg) + self.output.write('WARNING: %s\n' % msg) + elif not self.settings['quiet']: + self.ts.notify('WARNING: %s' % msg) + + def error(self, msg): + if self.settings['verbose']: + logging.info(msg) + sys.stderr.write('%s\n' % msg) + elif not self.settings['quiet']: + self.ts.error(msg) + + def process_args(self, args): + # Do we have tty? If not, turn on --verbose. + try: + open('/dev/tty', 'w') + except IOError: + self.settings['verbose'] = True + self.ts = ttystatus.TerminalStatus(period=0.001) - if not self.settings['quiet']: + if not self.settings['quiet'] and not self.settings['verbose']: self.ts.format( '%ElapsedTime() %Index(scenario,scenarios): ' '%String(scenario_name): ' 'step %Index(step,steps): %String(step_name)') - def process_args(self, args): scenarios, implementations = self.parse_scenarios(args) self.connect_implementations(scenarios, implementations) shell_prelude = self.load_shell_libraries() self.ts['scenarios'] = scenarios self.ts['num_scenarios'] = len(scenarios) - logging.info('Found %d scenarios' % len(scenarios)) + self.info('Found %d scenarios' % len(scenarios)) start_time = time.time() failed_scenarios = [] @@ -86,8 +116,9 @@ class YarnRunner(cliapp.Application): failed_scenarios.append(scenario) duration = time.time() - start_time - self.ts.clear() - self.ts.finish() + if not self.settings['quiet']: + self.ts.clear() + self.ts.finish() if failed_scenarios: raise cliapp.AppException( @@ -102,11 +133,10 @@ class YarnRunner(cliapp.Application): def parse_scenarios(self, filenames): mdparser = yarnlib.MarkdownParser() for filename in filenames: + self.info('Parsing scenario file %s' % filename) blocks = mdparser.parse_file(filename) if not blocks: - msg = 'No scenario code blocks in %s' % filename - logging.warning(msg) - self.ts.error('WARNING: %s' % msg) + self.warning('No scenario code blocks in %s' % filename) block_parser = yarnlib.BlockParser() block_parser.parse_blocks(mdparser.blocks) @@ -142,12 +172,12 @@ class YarnRunner(cliapp.Application): def load_shell_libraries(self): if not self.settings['shell-library']: - logging.info('No shell libraries defined') + self.info('No shell libraries defined') return '' libs = [] for filename in self.settings['shell-library']: - logging.info('Loading shell library %s') + self.info('Loading shell library %s' % filename) with open(filename) as f: text = f.read() libs.append('# Loaded from %s\n\n%s\n\n' % (filename, text)) @@ -174,12 +204,13 @@ class YarnRunner(cliapp.Application): return scenarios def run_scenario(self, scenario, shell_prelude): - logging.info('Running scenario %s' % scenario.name) + self.info('Running scenario %s' % scenario.name) self.ts['scenario'] = scenario self.ts['scenario_name'] = scenario.name self.ts['steps'] = scenario.steps if self.settings['no-act']: + self.info('Pretending everything went OK') return True if self.settings['tempdir']: @@ -192,6 +223,7 @@ class YarnRunner(cliapp.Application): os.mkdir(self.scenario_dir(tempdir, scenario)) datadir = self.datadir(tempdir, scenario) os.mkdir(datadir) + self.info('DATADIR is %s' % datadir) cleanup = [s for s in scenario.steps if s.what == 'FINALLY'] normal = [s for s in scenario.steps if s not in cleanup] @@ -223,8 +255,7 @@ class YarnRunner(cliapp.Application): return ok def run_step(self, datadir, scenario, step, shell_prelude): - logging.info('Running step "%s %s"' % (step.what, step.text)) - logging.info('DATADIR is %s' % datadir) + self.info('Running step "%s %s"' % (step.what, step.text)) self.ts['step'] = step self.ts['step_name'] = '%s %s' % (step.what, step.text) @@ -251,7 +282,7 @@ class YarnRunner(cliapp.Application): logging.debug('Standard error: empty') if exit != 0: - self.ts.error( + self.error( 'ERROR: In scenario "%s"\nstep "%s %s" failed,\n' 'with exit code %d:\n' 'Standard output from shell command:\n%s' -- cgit v1.2.1