Merge lp:~cboylan/boots/boots_presenter into lp:boots

Proposed by Clark Boylan
Status: Merged
Merge reported by: Max Goodhart
Merged at revision: not available
Proposed branch: lp:~cboylan/boots/boots_presenter
Merge into: lp:boots
Diff against target: 66 lines (+6/-13)
2 files modified
src/boots/api/api.py (+3/-2)
src/boots/lib/ui/plain.py (+3/-11)
To merge this branch: bzr merge lp:~cboylan/boots/boots_presenter
Reviewer Review Type Date Requested Status
Max Goodhart Approve
Review via email: mp+18427@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Clark Boylan (cboylan) wrote :

This code contains a bug fix and some speedup fixes to the presenter and server.execute code.

Revision history for this message
Max Goodhart (chromakode) wrote :

Looks good. Nice work!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/boots/api/api.py'
2--- src/boots/api/api.py 2010-01-31 21:20:00 +0000
3+++ src/boots/api/api.py 2010-02-02 01:15:22 +0000
4@@ -76,8 +76,9 @@
5 while True:
6 chunk = cursor.fetchmany(256)
7 if chunk:
8- packet["result"] = chunk
9- yield packet
10+ new_packet = packet.copy()
11+ new_packet["result"] = chunk
12+ yield new_packet
13 else:
14 return
15
16
17=== modified file 'src/boots/lib/ui/plain.py'
18--- src/boots/lib/ui/plain.py 2010-02-01 12:17:40 +0000
19+++ src/boots/lib/ui/plain.py 2010-02-02 01:15:22 +0000
20@@ -47,15 +47,8 @@
21 self.prompt = prompt
22
23 def present(self, result):
24- def convert_none(x):
25- if x is None:
26- return "None"
27- else:
28- return x
29 def get_dashes(x):
30 return "-" * (x+2)
31- def get_strs(max, string):
32- return "{string:{width}}".format(**{"string": string, "width": max})
33 try:
34 if not self.current_widths:
35 self.query = result["__server_execute_sql_query"]
36@@ -63,7 +56,7 @@
37 self.current_widths = map(len, self.names)
38 self.buffer = []
39 for row in result["result"]:
40- new_row = map(convert_none, row)
41+ new_row = map(str, row)
42 widths = map(len, new_row)
43 self.current_widths = map(max, widths, self.current_widths)
44 self.buffer.append(new_row)
45@@ -71,19 +64,18 @@
46 if self.current_widths:
47 dashes = map(get_dashes, self.current_widths)
48 sep = "+" + "+".join(dashes) + "+\n"
49- names = map(get_strs, self.current_widths, self.names)
50+ names = map("{0:{1}}".format, self.names, self.current_widths)
51 column_names = "| " + " | ".join(names) + " |\n"
52 sys.stdout.write(sep)
53 sys.stdout.write(column_names)
54 sys.stdout.write(sep)
55 for row in self.buffer:
56- strs = "| " + " | ".join(map(get_strs, self.current_widths, row)) + " |\n"
57+ strs = "| " + " | ".join(map("{0:{1}}".format, row, self.current_widths)) + " |\n"
58 sys.stdout.write(strs)
59 sys.stdout.write(sep)
60 # Reset values for next result set.
61 self.current_widths = None
62 print(result)
63- sys.stdout.flush()
64 except:
65 # Reset values for next result set.
66 self.current_widths = None

Subscribers

People subscribed via source and target branches

to status/vote changes: