annotate docs/pycon2010/pycon2010.rst @ 357:ce4448ca4088

leave office for pycon...
author catherine@dellzilla
date Wed, 17 Feb 2010 17:18:26 -0500
parents d275d3beceff
children 18e8487be095
rev   line source
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
1 ================================================
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
2 Easy command-line interpreters with cmd and cmd2
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
3 ================================================
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
4
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
5 :author: Catherine Devlin
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
6 :date: 2010-02-20
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
7
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
8 Quit scribbling
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
9 ===============
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
10
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
11 Slides are *already* posted at
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
12 catherinedevlin.pythoneers.com
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
13
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
14 Web 2.0
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
15 =======
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
16
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
17 .. image:: web-2-0-logos.gif
344
catherine@Drou
parents: 337
diff changeset
18 :height: 300px
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
19
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
20 But first...
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
21 ============
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
22
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
23 .. image:: sargon.jpg
344
catherine@Drou
parents: 337
diff changeset
24 :height: 300px
catherine@Drou
parents: 337
diff changeset
25
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
26 .. image:: akkad.png
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
27 :height: 300px
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
28
344
catherine@Drou
parents: 337
diff changeset
29 Sargon the Great
catherine@Drou
parents: 337
diff changeset
30 Founder of Akkadian Empire
catherine@Drou
parents: 337
diff changeset
31
catherine@Drou
parents: 337
diff changeset
32 .. twenty-third century BC
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
33
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
34 In between
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
35 ==========
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
36
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
37 .. image:: apple.jpg
344
catherine@Drou
parents: 337
diff changeset
38 :height: 300px
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
39
344
catherine@Drou
parents: 337
diff changeset
40 Command-Line Interface
catherine@Drou
parents: 337
diff changeset
41 Unlike the Akkadian Empire,
catherine@Drou
parents: 337
diff changeset
42 the CLI will never die.
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
43
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
44 Defining CLI
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
45 ============
344
catherine@Drou
parents: 337
diff changeset
46
catherine@Drou
parents: 337
diff changeset
47 - "Line-oriented command interpreter"
catherine@Drou
parents: 337
diff changeset
48 - "Command-line interface"
catherine@Drou
parents: 337
diff changeset
49 - "Shell"
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
50
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
51 1. Accepts free text input at prompt
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
52 2. Outputs lines of text
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
53 3. (repeat)
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
54
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
55 Examples
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
56 ========
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
57
344
catherine@Drou
parents: 337
diff changeset
58 * Bash, Korn, zsh
catherine@Drou
parents: 337
diff changeset
59 * Python shell
catherine@Drou
parents: 337
diff changeset
60 * screen
catherine@Drou
parents: 337
diff changeset
61 * Zork
catherine@Drou
parents: 337
diff changeset
62 * SQL clients: psql, SQL*\Plus, mysql...
catherine@Drou
parents: 337
diff changeset
63 * ed
catherine@Drou
parents: 337
diff changeset
64
catherine@Drou
parents: 337
diff changeset
65 .. ``ed`` proves that CLI is sometimes the wrong answer.
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
66
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
67 != Command Line Utilities
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
68 =========================
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
69
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
70 1. Accepts arguments at invocation
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
71 2. executes
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
72 3. terminates
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
73
344
catherine@Drou
parents: 337
diff changeset
74 Examples
catherine@Drou
parents: 337
diff changeset
75 --------
catherine@Drou
parents: 337
diff changeset
76 * ls
catherine@Drou
parents: 337
diff changeset
77 * grep
catherine@Drou
parents: 337
diff changeset
78 * ping
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
79
344
catherine@Drou
parents: 337
diff changeset
80 Use ``sys.argv``, ``optparse``
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
81
344
catherine@Drou
parents: 337
diff changeset
82 != "Text User Interfaces", "Consoles"
catherine@Drou
parents: 337
diff changeset
83 =====================================
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
84
344
catherine@Drou
parents: 337
diff changeset
85 * Use entire (session) screen
catherine@Drou
parents: 337
diff changeset
86 * I/O is *not* line-by-line
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
87
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
88 .. image:: urwid.png
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
89 :height: 300px
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
90
344
catherine@Drou
parents: 337
diff changeset
91 Use ``curses``, ``urwid``
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
92
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
93 Priorities
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
94 ==========
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
95
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
96 .. image:: strategy.png
344
catherine@Drou
parents: 337
diff changeset
97 :height: 300px
catherine@Drou
parents: 337
diff changeset
98
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
99 A ``cmd`` app: pirate.py
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
100 ========================
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
101
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
102 ::
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
103
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
104 from cmd import Cmd
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
105
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
106 class Pirate(Cmd):
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
107 pass
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
108
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
109 pirate = Pirate()
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
110 pirate.cmdloop()
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
111
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
112 .. Nothing here... but history and help
344
catherine@Drou
parents: 337
diff changeset
113
catherine@Drou
parents: 337
diff changeset
114 .. ctrl-r for bash-style history
catherine@Drou
parents: 337
diff changeset
115
catherine@Drou
parents: 337
diff changeset
116 Fundamental prrrinciple
catherine@Drou
parents: 337
diff changeset
117 =======================
catherine@Drou
parents: 337
diff changeset
118
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
119 .. class:: huge
344
catherine@Drou
parents: 337
diff changeset
120
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
121 ::
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
122
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
123 (Cmd) foo a b c
344
catherine@Drou
parents: 337
diff changeset
124
catherine@Drou
parents: 337
diff changeset
125 ``self.do_foo('a b c')``
catherine@Drou
parents: 337
diff changeset
126
catherine@Drou
parents: 337
diff changeset
127 ``do_``-methods: pirate2.py
catherine@Drou
parents: 337
diff changeset
128 ===========================
catherine@Drou
parents: 337
diff changeset
129
catherine@Drou
parents: 337
diff changeset
130 ::
catherine@Drou
parents: 337
diff changeset
131
catherine@Drou
parents: 337
diff changeset
132 class Pirate(Cmd):
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
133 gold = 3
344
catherine@Drou
parents: 337
diff changeset
134 def do_loot(self, arg):
catherine@Drou
parents: 337
diff changeset
135 'Seize booty frrrom a passing ship.'
catherine@Drou
parents: 337
diff changeset
136 self.gold += 1
catherine@Drou
parents: 337
diff changeset
137 print('Now we gots {0} doubloons'.format(self.gold))
catherine@Drou
parents: 337
diff changeset
138 def do_drink(self, arg):
catherine@Drou
parents: 337
diff changeset
139 'Drown your sorrrows in rrrum.'
catherine@Drou
parents: 337
diff changeset
140 self.gold -= 1
catherine@Drou
parents: 337
diff changeset
141 print('Now we gots {0} doubloons'.format(self.gold))
catherine@Drou
parents: 337
diff changeset
142
catherine@Drou
parents: 337
diff changeset
143 .. do_methods; more help
catherine@Drou
parents: 337
diff changeset
144
catherine@Drou
parents: 337
diff changeset
145 Hooks
catherine@Drou
parents: 337
diff changeset
146 =====
catherine@Drou
parents: 337
diff changeset
147
catherine@Drou
parents: 337
diff changeset
148 .. image:: hook.jpeg
catherine@Drou
parents: 337
diff changeset
149 :height: 300px
catherine@Drou
parents: 337
diff changeset
150
catherine@Drou
parents: 337
diff changeset
151 Hooks: pirate3.py
catherine@Drou
parents: 337
diff changeset
152 =================
catherine@Drou
parents: 337
diff changeset
153
catherine@Drou
parents: 337
diff changeset
154 ::
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
155
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
156 def do_loot(self, arg):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
157 'Seize booty from a passing ship.'
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
158 self.gold += 1
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
159 def do_drink(self, arg):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
160 'Drown your sorrrows in rrrum.'
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
161 self.gold -= 1
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
162 def precmd(self, line):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
163 self.initial_gold = self.gold
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
164 return line
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
165 def postcmd(self, stop, line):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
166 if self.gold != self.initial_gold:
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
167 print('Now we gots {0} doubloons'.format(self.gold))
344
catherine@Drou
parents: 337
diff changeset
168
catherine@Drou
parents: 337
diff changeset
169 Arguments: pirate4.py
catherine@Drou
parents: 337
diff changeset
170 =====================
catherine@Drou
parents: 337
diff changeset
171
catherine@Drou
parents: 337
diff changeset
172 ::
catherine@Drou
parents: 337
diff changeset
173
catherine@Drou
parents: 337
diff changeset
174 def do_drink(self, arg):
catherine@Drou
parents: 337
diff changeset
175 '''Drown your sorrrows in rrrum.
catherine@Drou
parents: 337
diff changeset
176
catherine@Drou
parents: 337
diff changeset
177 drink [n] - drink [n] barrel[s] o' rum.'''
catherine@Drou
parents: 337
diff changeset
178 try:
catherine@Drou
parents: 337
diff changeset
179 self.gold -= int(arg)
catherine@Drou
parents: 337
diff changeset
180 except:
catherine@Drou
parents: 337
diff changeset
181 if arg:
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
182 print('''What's "{0}"? I'll take rrrum.'''
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
183 .format(arg))
344
catherine@Drou
parents: 337
diff changeset
184 self.gold -= 1
catherine@Drou
parents: 337
diff changeset
185
catherine@Drou
parents: 337
diff changeset
186 quitting: pirate5.py
catherine@Drou
parents: 337
diff changeset
187 ====================
catherine@Drou
parents: 337
diff changeset
188
catherine@Drou
parents: 337
diff changeset
189 ::
catherine@Drou
parents: 337
diff changeset
190
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
191 def postcmd(self, stop, line):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
192 if self.gold != self.initial_gold:
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
193 print('Now we gots {0} doubloons'.format(self.gold))
344
catherine@Drou
parents: 337
diff changeset
194 if self.gold < 0:
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
195 print("Off to debtorrr's prison. Game overrr.")
344
catherine@Drou
parents: 337
diff changeset
196 return True
catherine@Drou
parents: 337
diff changeset
197 return stop
catherine@Drou
parents: 337
diff changeset
198 def do_quit(self, arg):
catherine@Drou
parents: 337
diff changeset
199 print("Quiterrr!")
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
200 return True
344
catherine@Drou
parents: 337
diff changeset
201
catherine@Drou
parents: 337
diff changeset
202 prompts and defaults: pirate6.py
catherine@Drou
parents: 337
diff changeset
203 ================================
catherine@Drou
parents: 337
diff changeset
204
catherine@Drou
parents: 337
diff changeset
205 ::
catherine@Drou
parents: 337
diff changeset
206
catherine@Drou
parents: 337
diff changeset
207 prompt = 'arrr> '
catherine@Drou
parents: 337
diff changeset
208 def default(self, line):
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
209 print('What mean ye by "{0}"?'
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
210 .format(line))
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
211
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
212 cmd2
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
213 ====
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
214
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
215 .. image:: schematic.png
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
216 :height: 300px
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
217
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
218 Absolutely free
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
219 ===============
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
220
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
221 * Script files
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
222 * Commands at invocation
346
49dd1ce6cfd6 quitting after invocation commands
catherine@Drou
parents: 345
diff changeset
223 * Output redirection
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
224 * Python
346
49dd1ce6cfd6 quitting after invocation commands
catherine@Drou
parents: 345
diff changeset
225 * Transcript-based testing
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
226
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
227 But wait, there's more
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
228 ======================
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
229
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
230 * Abbreviated commands
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
231 * Shell commands
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
232 * Quitting
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
233 * Timing
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
234 * Echo
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
235 * Debug
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
236
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
237 For a few keystrokes more...
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
238 ============================
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
239
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
240 * Default to shell
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
241 * Color output
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
242 * Shortcuts
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
243 * Multiline commands
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
244 * Environment variables
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
245
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
246 Minor changes: pirate7.py
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
247 =========================
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
248
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
249 ::
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
250
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
251 default_to_shell = True
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
252 multilineCommands = ['sing']
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
253 terminators = Cmd.terminators + ['...']
356
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
254 songcolor = 'blue'
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
255 settable = Cmd.settable + 'songcolor Color to ``sing`` in (red/blue/green/cyan/magenta, bold, underline)'
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
256 Cmd.shortcuts.update({'~': 'sing'})
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
257 def do_sing(self, arg):
356
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
258 print(self.colorize(arg, self.songcolor))
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
259
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
260 Now how much would you pay?
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
261 ===========================
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
262
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
263 * options / flags
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
264 * Quiet (suppress feedback)
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
265 * BASH-style ``select``
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
266 * Parsing: terminators, suffixes
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
267
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
268 Options: pirate8.py
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
269 ===================
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
270
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
271 ::
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
272
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
273 @options([make_option('--ho', type='int', help="How often to chant 'ho'", default=2),
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
274 make_option('-c', '--commas', action="store_true", help="Interspers commas")])
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
275 def do_yo(self, arg, opts):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
276 chant = ['yo'] + ['ho'] * opts.ho
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
277 if opts.commas:
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
278 separator = ', '
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
279 else:
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
280 separator = ' '
352
798c7f32a960 line spacing
catherine@Drou
parents: 351
diff changeset
281 chant = separator.join(chant)
798c7f32a960 line spacing
catherine@Drou
parents: 351
diff changeset
282 print('{0} and a bottle of {1}'.format(chant, arg))
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
283
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
284 sqlpython
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
285 =========
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
286
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
287 Created by Luca Canali @ CERN
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
288
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
289 ``cmd``-based Replacement for Oracle SQL/*Plus
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
290
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
291
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
292
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
293
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
294