Ubuntu Pastebin

Paste from csmith at Tue, 10 Oct 2017 18:55:10 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--- bin/apport-cli	2016-03-31 08:13:38.000000000 -0600
+++ bin/apport-cli.new	2017-10-10 12:54:03.561619739 -0600
@@ -34,7 +34,7 @@
         self.buttons = []
         self.visible = False
 
-    def raw_input_char(self, prompt):
+    def raw_input_char(self, prompt, char_count=1):
         '''raw_input, but read only one character'''
 
         sys.stdout.write(prompt)
@@ -50,7 +50,7 @@
         termios.tcsetattr(file, termios.TCSANOW, attributes)
 
         try:
-            ch = str(sys.stdin.read(1))
+            ch = str(sys.stdin.read(char_count))
         finally:
             termios.tcsetattr(file, termios.TCSANOW, saved_attributes)
 
@@ -82,9 +82,19 @@
                 for index, button in enumerate(self.buttons):
                     print('  %s: %s' % (self.keys[index], button))
 
-                response = self.raw_input_char(_('Please choose (%s):') % ('/'.join(self.keys)))
+                char_count = 1
+                if len(self.keys) > 10:  # we need two characters
+                    char_count = 2
+                if len(self.keys) > 50: # Usability concerns
+                    raise RuntimeError(
+                        "Too many choices provided to the user (%s)"
+                        % '/'.join(self.keys))
+                response = self.raw_input_char(
+                    _('Please choose (%s):') % ('/'.join(self.keys)),
+                    char_count=char_count).strip()
+                import pdb; pdb.set_trace()
                 try:
-                    return self.keys.index(response[0].upper()) + 1
+                    return self.keys.index(response.upper()) + 1
                 except ValueError:
                     pass
         except KeyboardInterrupt:
@@ -143,15 +153,15 @@
                     hasattr(self.report[key], 'isspace') and \
                     not self.report._is_binary(self.report[key]) and \
                     keylen < max_show:
-                l = self.report[key]
+                s = self.report[key]
             elif keylen >= max_show:
-                l = _('(%i bytes)') % keylen
+                s = _('(%i bytes)') % keylen
             else:
-                l = _('(binary data)')
+                s = _('(binary data)')
 
-            if isinstance(l, bytes):
-                l = l.decode('UTF-8', errors='ignore')
-            details += l
+            if isinstance(s, bytes):
+                s = s.decode('UTF-8', errors='ignore')
+            details += s
             details += '\n\n'
 
         return details
@@ -365,6 +375,7 @@
 
         subprocess.call(command, shell=True)
 
+
 if __name__ == '__main__':
     app = CLIUserInterface()
     if not app.run_argv():
Download as text