Merge lp:~ben-hutchings/ensoft-sextant/audit-table into lp:ensoft-sextant

Proposed by Ben Hutchings
Status: Merged
Approved by: Robert
Approved revision: 28
Merged at revision: 27
Proposed branch: lp:~ben-hutchings/ensoft-sextant/audit-table
Merge into: lp:ensoft-sextant
Diff against target: 53 lines (+35/-8)
1 file modified
src/sextant/__main__.py (+35/-8)
To merge this branch: bzr merge lp:~ben-hutchings/ensoft-sextant/audit-table
Reviewer Review Type Date Requested Status
Robert Approve
Review via email: mp+236362@code.launchpad.net

This proposal supersedes a proposal from 2014-09-26.

Commit message

Audit updates: added a width restriction on the table columns, added some whitespace and changed the title of the user ID column to 'User ID.'

Description of the change

Applied diff notes - added a width restriction on the table columns, added some whitespace and changed the title of the user ID column to 'User ID.'

To post a comment you must log in.
Revision history for this message
Robert (rjwills) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Robert (rjwills) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Robert (rjwills) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/sextant/__main__.py'
--- src/sextant/__main__.py 2014-09-26 11:25:09 +0000
+++ src/sextant/__main__.py 2014-09-29 15:03:52 +0000
@@ -81,14 +81,41 @@
81 location = _displayable_url(args)81 location = _displayable_url(args)
82 logging.warning('No programs on database at {}.'.format(location))82 logging.warning('No programs on database at {}.'.format(location))
83 else:83 else:
84 for program in audited:84 # print data about all the programs in the database in a formatted table
85 st = ('Program {progname} with {numfuncs} functions '85 titles = ("Name", "#Func", "Uploader", "User-ID", "Upload Date")
86 'uploaded by {uploader} (id {uploaderid}) on {date}.')86 colminlens = (len(entry) for entry in titles)
87 print(st.format(progname=program.program_name,87 # maximum lengths to avoid one entry from throwing the whole table
88 numfuncs=program.number_of_funcs,88 # date format is <YYYY:MM:DD HH:MM:SS.UUUUUU> = 26 characters
89 uploader=program.uploader,89 COLMAXLENS = (25, 5, 25, 10, 26)
90 uploaderid=program.uploader_id,90
91 date=program.date))91 # make a table of the strings of each data entry we will display
92 text = [map(str, (p.program_name, p.number_of_funcs,
93 p.uploader, p.uploader_id, p.date))
94 for p in audited]
95
96 # and a table of the corresponding lengths for every text entry
97 textlens = ((len(entry) for entry in pentry) for pentry in text)
98
99 # the maxes of the column maxes of the textlens table and the
100 # lengths of the title row words give the column widths
101 textcollens = map(max, zip(*textlens))
102 # the lambda is exactly equivalent to calling
103 # min(max(colminlens, textcollens), COLMAXLENS),
104 # eg for x < low: sorted((low, x, high))[1] = (x, low, high)[1] = low
105 collens = map(lambda l: sorted(l)[1], zip(colminlens, textcollens, COLMAXLENS))
106
107 # insert the column widths into the format string
108 st = ('{{0:{0}}} {{1:>{1}}} {{2:{2}}} {{3:{3}}} '
109 '{{4:{4}}}'.format(*collens))
110
111 # write the title line so we know how long to make the separator line
112 titleline = st.format(*titles)
113 sepline = '-' * len(titleline)
114
115 # output the formatted table
116 print(titleline)
117 print(sepline)
118 print('\n'.join(st.format(*pentry) for pentry in text))
92119
93120
94def _add_program(args):121def _add_program(args):

Subscribers

People subscribed via source and target branches