Merge lp:~roadmr/checkbox/twirly into lp:checkbox

Proposed by Daniel Manrique
Status: Merged
Approved by: Brendan Donegan
Approved revision: 1772
Merged at revision: 1772
Proposed branch: lp:~roadmr/checkbox/twirly
Merge into: lp:checkbox
Diff against target: 115 lines (+25/-7)
2 files modified
checkbox_cli/cli_interface.py (+22/-7)
debian/changelog (+3/-0)
To merge this branch: bzr merge lp:~roadmr/checkbox/twirly
Reviewer Review Type Date Requested Status
Brendan Donegan (community) Approve
Daniel Manrique (community) Needs Resubmitting
Review via email: mp+129521@code.launchpad.net

Commit message

Fix bug 926104 by creating a spinning ascii twirler in the CLI to indicate that checkbox is doing something or waiting for input

Description of the change

A spinning ascii twirler to indicate that checkbox is doing something or waiting for input.

To test:

sudo -k; unset DISPLAY; PYTHONPATH=. bin/checkbox-cli -W data/whitelists/default.whitelist

To post a comment you must log in.
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

Awesome! I'm left scratching my head why the same approach gave me problems (maybe I used wrong escape characters or something). Two observations though:

- I think it's a lot of code for something so simple, you can look in https://code.launchpad.net/~brendan-donegan/checkbox/spinner_and_pep8_fixes for the way I attempted it (it's about 3-4 lines). I don't mind either way how it's done really though.

- It would be good to give cli_interface.py a ritual pep8/pyflakes clean before submitting. At least it should pass the lint script.

Marking as needs fixing, but only for the pep8 clean - it's totally up to you if you want to simplify the implementation of the spinner/twirly.

review: Needs Fixing
lp:~roadmr/checkbox/twirly updated
1771. By Daniel Manrique

pep8 fixes and a small simplification to the twirler code

Revision history for this message
Daniel Manrique (roadmr) wrote :

Thanks for your review!

I applied pep8 fixes and slightly simplified the twirly code. I stole your index updating method, but I did keep the twirly class as I thought it better to keep this a bit isolated from the rest of the code.

review: Needs Resubmitting
lp:~roadmr/checkbox/twirly updated
1772. By Daniel Manrique

Merged from trunk

Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

Perfect, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox_cli/cli_interface.py'
2--- checkbox_cli/cli_interface.py 2012-06-12 15:03:42 +0000
3+++ checkbox_cli/cli_interface.py 2012-10-14 01:15:25 +0000
4@@ -133,7 +133,8 @@
5 default = "*" if option in defaults else " "
6 self.put_line("%s %s: %s" % (default, key, option))
7
8- response = self.get(_("Please choose (%s): ") % ("/".join(self.keys)))
9+ response = self.get(_("Please choose (%s): ") %
10+ ("/".join(self.keys)))
11 if response >= 0:
12 return response
13
14@@ -151,7 +152,7 @@
15 string.digits + \
16 string.punctuation
17
18- keys = keys.replace(' ','')
19+ keys = keys.replace(' ', '')
20 keys = keys.replace('+', '')
21
22 for key in keys:
23@@ -202,6 +203,7 @@
24
25 keys = []
26 options = []
27+
28 def add_option(option, key=None):
29 """
30 Add option to list
31@@ -272,12 +274,24 @@
32 separator = ord("\n")
33
34
35+class Twirly(object):
36+ def __init__(self):
37+ self.index = 0
38+ self.twirlies = "-\\|/"
39+
40+ def next(self):
41+ next_twirly = self.twirlies[self.index]
42+ self.index = (self.index + 1) % len(self.twirlies)
43+ return next_twirly
44+
45+
46 class CLIProgressDialog(CLIDialog):
47 """Command line progress dialog wrapper."""
48
49 def __init__(self, text):
50 super(CLIProgressDialog, self).__init__(text)
51 self.progress_count = 0
52+ self.twirly = Twirly()
53
54 def set(self, progress=None):
55 self.progress_count = (self.progress_count + 1) % 5
56@@ -287,7 +301,9 @@
57 if progress != None:
58 self.put("\r%u%%" % (progress * 100))
59 else:
60- self.put(".")
61+ self.put("\b\b")
62+ self.put(self.twirly.next())
63+ self.put(" ")
64 sys.stdout.flush()
65
66
67@@ -365,7 +381,8 @@
68 for option in keys:
69 dialog.add_option(option)
70
71- dialog.add_option(_("Combine with character above to expand node"), "+")
72+ dialog.add_option(_("Combine with character above to expand node"),
73+ "+")
74 dialog.add_option(_("Space when finished"), " ")
75
76 do_expand = False
77@@ -395,14 +412,13 @@
78 # Expand tree
79 dialog.visible = False
80 if options[result]:
81- branch_results = results.get(result, {})
82+ branch_results = results.get(result, {})
83 self.show_tree(result, options[result], branch_results)
84 if branch_results and result not in results:
85 results[result] = branch_results
86
87 return results
88
89-
90 def show_report(self, text, results):
91 """
92 Show test case results in a tree hierarchy
93@@ -410,7 +426,6 @@
94 dialog = CLIReportDialog(text, results)
95 dialog.run()
96
97-
98 def show_test(self, test, runner):
99 options = list([ANSWER_TO_OPTION[a] for a in ALL_ANSWERS])
100 if "command" in test:
101
102=== modified file 'debian/changelog'
103--- debian/changelog 2012-10-12 21:43:34 +0000
104+++ debian/changelog 2012-10-14 01:15:25 +0000
105@@ -9,7 +9,10 @@
106 [Daniel Manrique]
107 * [FEATURE] checkbox/job.py: Fixed intltool warning about unnamed
108 parameters in string, applied pep8 fixes.
109+ * checkbox-cli progress indicator is now static, spinning around instead of
110+ filling the screen with dots. (LP: #926104)
111 * Increased version number after final Ubuntu Quantal release.
112+
113 [Marc Tardif]
114 * plugins/environment_info.py: Enabling environment to take precedence
115 over configuration files.

Subscribers

People subscribed via source and target branches