Skip to content

Commit

Permalink
Use flush method
Browse files Browse the repository at this point in the history
  • Loading branch information
twaugh committed Oct 6, 2015
1 parent fa81664 commit 9ec94d7
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions journal_brief/cli/main.py
Expand Up @@ -100,9 +100,18 @@ def show_stats(self, entries, exclusions):
for stat in stats:
print(strf.format(FREQ=stat.hits, EXCLUSION=repr(stat.exclusion)))

def debrief(self, jfilter):
dbr = Debriefer(ignore_fields=self.args.ignore)
dbr.format(jfilter, output_stream=sys.stdout)
def format_output(self, formatters, jfilter):
for entry in jfilter:
for formatter in formatters:
output = formatter.format(entry)
if output:
print(output)

def flush_output(self, formatters):
for formatter in formatters:
output = formatter.flush()
if output:
print(output)

def run(self):
if self.config.get('debug'):
Expand All @@ -128,7 +137,6 @@ def run(self):
log_level = int(PRIORITY_MAP[priority])
log.debug("priority=%r from args/config", log_level)

outputs = self.config.get('output', 'short').split(',')
reader = SelectiveReader(this_boot=self.args.b,
log_level=log_level,
inclusions=self.config.get('inclusions'))
Expand All @@ -138,15 +146,19 @@ def run(self):
seek_cursor=not self.args.b) as entries:
exclusions = self.config.get('exclusions', [])
jfilter = JournalFilter(entries, exclusions=exclusions)
if self.args.cmd == 'debrief':
self.debrief(jfilter)
elif self.args.cmd == 'stats':
if self.args.cmd == 'stats':
self.show_stats(entries, exclusions)
else:
for output in outputs:
formatter = get_formatter(output)
formatter.format(jfilter, output_stream=sys.stdout)
## TODO: But now all the entries have been read!
if self.args.cmd == 'debrief':
dbr = Debriefer(ignore_fields=self.args.ignore)
formatters = [dbr]
else:
formatters = self.config.get('output', 'short').split(',')

try:
self.format_output(formatters, jfilter)
finally:
self.flush_output(formatters)


def run():
Expand Down

0 comments on commit 9ec94d7

Please sign in to comment.