Mercurial > python-cmd2
comparison docs/pycon2010/pycon2010.rst @ 344:4300ef912f4a
graph'
author | catherine@Drou |
---|---|
date | Tue, 16 Feb 2010 14:05:25 -0500 |
parents | 2ce34ad4e520 |
children | 6fe1e75e3a67 |
comparison
equal
deleted
inserted
replaced
343:787573d350c5 | 344:4300ef912f4a |
---|---|
1 py 3 | 1 ===== |
2 Title | |
3 ===== | |
2 | 4 |
3 Web 2.0 | 5 Web 2.0 |
4 ======= | 6 ======= |
5 | 7 |
6 .. image:: web-2-0-logos.gif | 8 .. image:: web-2-0-logos.gif |
7 :height: 300 px | 9 :height: 300px |
8 | 10 |
9 But first... | 11 But first... |
10 ============ | 12 ============ |
11 | 13 |
12 .. image:: sargon.jpg | 14 .. image:: sargon.jpg |
13 :height: 300 px | 15 :height: 300px |
14 | 16 |
15 Sargon the Great founded the Akkadian Empire | 17 Sargon the Great |
16 in the twenty-third century BC. | 18 Founder of Akkadian Empire |
19 | |
20 .. twenty-third century BC | |
17 | 21 |
18 In between | 22 In between |
19 ========== | 23 ========== |
20 | 24 |
21 .. image:: apple.jpg | 25 .. image:: apple.jpg |
22 :height: 300 px | 26 :height: 300px |
23 | 27 |
24 Unlike the Akkadian Empire, the CLI will never disappear. | 28 Command-Line Interface |
25 | 29 Unlike the Akkadian Empire, |
26 line-oriented command interpreter | 30 the CLI will never die. |
27 command-line interface | |
28 text user interface | |
29 terminal user interface | |
30 console | |
31 shell | |
32 | 31 |
33 Defining | 32 Defining |
34 ======== | 33 ======== |
34 | |
35 - "Line-oriented command interpreter" | |
36 - "Command-line interface" | |
37 - "Shell" | |
35 | 38 |
36 Prompt accepts free text input | 39 * Accepts free text input at prompt |
37 Outputs lines of text | 40 * Outputs lines of text |
38 CLI environment persists | 41 * Persistent CLI environment |
39 | 42 |
40 Examples | 43 Examples |
41 ======== | 44 ======== |
42 | 45 |
43 Bash, Korn, zsh | 46 * Bash, Korn, zsh |
44 Python shell | 47 * Python shell |
45 screen | 48 * screen |
46 Zork | 49 * Zork |
47 ed | 50 * SQL clients: psql, SQL*\Plus, mysql... |
48 SQL clients: psql, SQL*\Plus, mysql... | 51 * ed |
52 | |
53 .. ``ed`` proves that CLI is sometimes the wrong answer. | |
49 | 54 |
50 != Command Line Utilities | 55 != Command Line Utilities |
51 ========================= | 56 ========================= |
52 | 57 |
53 Accept single set of arguments at | 58 * Accept arguments at invocation |
54 invocation, execute, terminate | 59 * execution |
60 * terminate | |
55 | 61 |
56 dir | 62 Examples |
57 grep | 63 -------- |
58 ping | 64 * ls |
65 * grep | |
66 * ping | |
59 | 67 |
60 sys.argv | 68 Use ``sys.argv``, ``optparse`` |
61 optparse | |
62 | 69 |
63 != Text User Interfaces | 70 != "Text User Interfaces", "Consoles" |
64 ======================= | 71 ===================================== |
65 | 72 |
66 ("console") | 73 * Use entire (session) screen |
67 | 74 * I/O is *not* line-by-line |
68 Use entire (session) screen | |
69 Not line-by-line | |
70 | 75 |
71 .. image:: urwid.png | 76 .. image:: urwid.png |
72 :height: 300px | 77 :height: 300px |
73 | 78 |
74 curses | 79 Use ``curses``, ``urwid`` |
75 urwid | |
76 | 80 |
81 Tradeoff | |
82 ======== | |
77 | 83 |
78 foo a b c -> | 84 .. image:: ease.png |
79 self.do_foo('a b c') | 85 :height: 300px |
80 self.default('foo a b c') | 86 |
81 | |
82 pirate.py | 87 pirate.py |
83 ========= | 88 ========= |
84 | 89 |
85 :: | 90 :: |
86 | 91 |
90 pass | 95 pass |
91 | 96 |
92 pirate = Pirate() | 97 pirate = Pirate() |
93 pirate.cmdloop() | 98 pirate.cmdloop() |
94 | 99 |
95 history: cursor | 100 Nothing here... but history and help |
96 ctrl-r | |
97 help | |
98 | 101 |
102 .. ctrl-r for bash-style history | |
103 | |
104 Fundamental prrrinciple | |
105 ======================= | |
106 | |
107 .. class: huge | |
108 | |
109 ``foo a b c`` -> | |
110 | |
111 ``self.do_foo('a b c')`` | |
112 | |
113 ``do_``-methods: pirate2.py | |
114 =========================== | |
115 | |
116 :: | |
117 | |
118 class Pirate(Cmd): | |
119 gold = 10 | |
120 def do_loot(self, arg): | |
121 'Seize booty frrrom a passing ship.' | |
122 self.gold += 1 | |
123 print('Now we gots {0} doubloons'.format(self.gold)) | |
124 def do_drink(self, arg): | |
125 'Drown your sorrrows in rrrum.' | |
126 self.gold -= 1 | |
127 print('Now we gots {0} doubloons'.format(self.gold)) | |
128 | |
129 .. do_methods; more help | |
130 | |
131 Hooks | |
132 ===== | |
133 | |
134 .. image:: hook.jpeg | |
135 :height: 300px | |
136 | |
137 Hooks: pirate3.py | |
138 ================= | |
139 | |
140 :: | |
141 | |
142 class Pirate(Cmd): | |
143 gold = 3 | |
144 def do_loot(self, arg): | |
145 'Drown your sorrrows in rrrum.' | |
146 self.gold += 1 | |
147 def do_drink(self, arg): | |
148 'Drown your sorrrows in rrrum.' | |
149 self.gold -= 1 | |
150 def postcmd(self, stop, line): | |
151 print('Now we gots {0} doubloons'.format(self.gold)) | |
152 | |
153 Arguments: pirate4.py | |
154 ===================== | |
155 | |
156 :: | |
157 | |
158 def do_drink(self, arg): | |
159 '''Drown your sorrrows in rrrum. | |
160 | |
161 drink [n] - drink [n] barrel[s] o' rum.''' | |
162 try: | |
163 self.gold -= int(arg) | |
164 except: | |
165 if arg: | |
166 print('''What's "{0}"? I'll take rrrum.'''.format(arg)) | |
167 self.gold -= 1 | |
168 | |
169 quitting: pirate5.py | |
170 ==================== | |
171 | |
172 :: | |
173 | |
174 def postcmd(self, stop, line): | |
175 print('Now we gots {0} doubloons'.format(self.gold)) | |
176 if self.gold < 0: | |
177 print("Off to debtorrr's prrrison. Game overrr.") | |
178 return True | |
179 return stop | |
180 def do_quit(self, arg): | |
181 print("Quiterrr!") | |
182 return True | |
183 | |
184 prompts and defaults: pirate6.py | |
185 ================================ | |
186 | |
187 :: | |
188 | |
189 prompt = 'arrr> ' | |
190 def default(self, line): | |
191 print('What mean ye by "{0}"?'.format(line)) |