Ext: Updated totals.py for both Python 2 and 3

This commit is contained in:
Paul Beckingham 2017-04-14 23:59:24 -04:00
parent b619b2b574
commit d55ca5b474

View file

@ -94,7 +94,7 @@ for tag in totals:
max_width = len(tag) max_width = len(tag)
if 'temp.report.start' not in configuration: if 'temp.report.start' not in configuration:
print 'There is no data in the database' print('There is no data in the database')
exit() exit()
start = datetime.datetime.strptime(configuration['temp.report.start'], DATEFORMAT) start = datetime.datetime.strptime(configuration['temp.report.start'], DATEFORMAT)
@ -102,34 +102,34 @@ end = datetime.datetime.strptime(configuration['temp.report.end'], DATEFORMAT)
if max_width > 0: if max_width > 0:
# Compose report header. # Compose report header.
print '\nTotal by Tag, for %s - %s\n' % (start, end) print('\nTotal by Tag, for %s - %s\n' % (start, end))
# Compose table header. # Compose table header.
if configuration['color'] == 'on': if configuration['color'] == 'on':
print '%-*s %10s' % (max_width, 'Tag', 'Total') print('%-*s %10s' % (max_width, 'Tag', 'Total'))
else: else:
print '%-*s %10s' % (max_width, 'Tag', 'Total') print('%-*s %10s' % (max_width, 'Tag', 'Total'))
print '-' * max_width, '----------' print('{} {}'.format('-' * max_width, '----------'))
# Compose table rows. # Compose table rows.
grand_total = 0 grand_total = 0
for tag in sorted(totals): for tag in sorted(totals):
formatted = format_seconds(totals[tag].seconds) formatted = format_seconds(totals[tag].seconds)
grand_total += totals[tag].seconds grand_total += totals[tag].seconds
print '%-*s %10s' % (max_width, tag, formatted) print('%-*s %10s' % (max_width, tag, formatted))
if untagged is not None: if untagged is not None:
formatted = format_seconds(untagged.seconds) formatted = format_seconds(untagged.seconds)
grand_total += untagged.seconds grand_total += untagged.seconds
print '%-*s %10s' % (max_width, '', formatted) print('%-*s %10s' % (max_width, '', formatted))
# Compose total. # Compose total.
if configuration['color'] == 'on': if configuration['color'] == 'on':
print ' ' * max_width, ' ' print('{} {}'.format(' ' * max_width, ' '))
else: else:
print ' ' * max_width, '----------' print('{} {}'.format(' ' * max_width, '----------'))
print '%-*s %10s' % (max_width, 'Total', format_seconds(grand_total)) print('%-*s %10s' % (max_width, 'Total', format_seconds(grand_total)))
else: else:
print 'No data in the range %s - %s' % (start, end) print('No data in the range %s - %s' % (start, end))