annotate docs/pycon2010/pycon2010.rst @ 380:de2306847251

replacing temporaryfile with an object seems good
author cat@eee
date Mon, 22 Feb 2010 21:26:40 -0500
parents 32b9137577b8
children
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
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
7 :slides: http://pypi.python.org/pypi/cmd2
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
8
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
9 Web 2.0
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
10 =======
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
11
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
12 .. image:: web-2-0-logos.gif
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
13 :height: 350px
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
14
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
15 But first...
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
16 ============
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
17
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
18 .. image:: sargon.jpg
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
19 :height: 250px
344
catherine@Drou
parents: 337
diff changeset
20
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
21 .. image:: akkad.png
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
22 :height: 250px
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
23
344
catherine@Drou
parents: 337
diff changeset
24 Sargon the Great
catherine@Drou
parents: 337
diff changeset
25 Founder of Akkadian Empire
catherine@Drou
parents: 337
diff changeset
26
catherine@Drou
parents: 337
diff changeset
27 .. twenty-third century BC
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
28
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
29 In between
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
30 ==========
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
31
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
32 .. image:: apple.jpg
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
33 :height: 250px
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
34
344
catherine@Drou
parents: 337
diff changeset
35 Command-Line Interface
catherine@Drou
parents: 337
diff changeset
36 Unlike the Akkadian Empire,
catherine@Drou
parents: 337
diff changeset
37 the CLI will never die.
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
38
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
39 Defining CLI
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
40 ============
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
41
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
42 Also known as
344
catherine@Drou
parents: 337
diff changeset
43
catherine@Drou
parents: 337
diff changeset
44 - "Line-oriented command interpreter"
catherine@Drou
parents: 337
diff changeset
45 - "Command-line interface"
catherine@Drou
parents: 337
diff changeset
46 - "Shell"
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
47
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
48 1. Accepts free text input at prompt
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
49 2. Outputs lines of text
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
50 3. (repeat)
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
51
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
52 Examples
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
53 ========
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
54
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
55 .. class:: big
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
56
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
57 * Bash, Korn, zsh
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
58 * Python shell
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
59 * screen
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
60 * Zork
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
61 * SQL clients: psql, SQL*\Plus, mysql...
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
62 * ed
344
catherine@Drou
parents: 337
diff changeset
63
catherine@Drou
parents: 337
diff changeset
64 .. ``ed`` proves that CLI is sometimes the wrong answer.
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
65
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
66 != Command Line Utilities
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
67 =========================
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
68
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
69 .. class:: big
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
70
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
71 (``ls``, ``grep``, ``ping``, etc.)
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
72
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
73 1. Accept arguments at invocation
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
74 2. execute
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
75 3. terminate
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
76
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
77 Use ``sys.argv``, ``optparse``
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
78
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
79 !="Text User Interface"
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
80 =======================
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
81
344
catherine@Drou
parents: 337
diff changeset
82 * Use entire (session) screen
catherine@Drou
parents: 337
diff changeset
83 * I/O is *not* line-by-line
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
84 * See ``curses``, ``urwid``
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
85
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
86 .. image:: urwid.png
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
87 :height: 250px
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
88
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
89
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
90 Decide your priorities
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
91 ======================
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
92
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
93 .. image:: strategy.png
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
94 :height: 350px
344
catherine@Drou
parents: 337
diff changeset
95
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
96 A ``cmd`` app: pirate.py
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
97 ========================
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
98
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
99 ::
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
100
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
101 from cmd import Cmd
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
102
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
103 class Pirate(Cmd):
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
104 pass
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
105
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
106 pirate = Pirate()
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
107 pirate.cmdloop()
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
108
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
109 .. Nothing here... but history and help
344
catherine@Drou
parents: 337
diff changeset
110
catherine@Drou
parents: 337
diff changeset
111 .. ctrl-r for bash-style history
catherine@Drou
parents: 337
diff changeset
112
catherine@Drou
parents: 337
diff changeset
113 Fundamental prrrinciple
catherine@Drou
parents: 337
diff changeset
114 =======================
catherine@Drou
parents: 337
diff changeset
115
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
116 .. class:: huge
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
117
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
118 ``(Cmd) foo a b c``
344
catherine@Drou
parents: 337
diff changeset
119
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
120 becomes
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
121
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
122 ``self.do_foo('a b c')``
344
catherine@Drou
parents: 337
diff changeset
123
catherine@Drou
parents: 337
diff changeset
124 ``do_``-methods: pirate2.py
catherine@Drou
parents: 337
diff changeset
125 ===========================
catherine@Drou
parents: 337
diff changeset
126
catherine@Drou
parents: 337
diff changeset
127 ::
catherine@Drou
parents: 337
diff changeset
128
catherine@Drou
parents: 337
diff changeset
129 class Pirate(Cmd):
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
130 gold = 3
344
catherine@Drou
parents: 337
diff changeset
131 def do_loot(self, arg):
catherine@Drou
parents: 337
diff changeset
132 'Seize booty frrrom a passing ship.'
catherine@Drou
parents: 337
diff changeset
133 self.gold += 1
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
134 print('Now we gots {0} doubloons'
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
135 .format(self.gold))
344
catherine@Drou
parents: 337
diff changeset
136 def do_drink(self, arg):
catherine@Drou
parents: 337
diff changeset
137 'Drown your sorrrows in rrrum.'
catherine@Drou
parents: 337
diff changeset
138 self.gold -= 1
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
139 print('Now we gots {0} doubloons'
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
140 .format(self.gold))
344
catherine@Drou
parents: 337
diff changeset
141
catherine@Drou
parents: 337
diff changeset
142 .. do_methods; more help
catherine@Drou
parents: 337
diff changeset
143
catherine@Drou
parents: 337
diff changeset
144 Hooks
catherine@Drou
parents: 337
diff changeset
145 =====
catherine@Drou
parents: 337
diff changeset
146
363
2b2836b783be added hook pic
cat@eee
parents: 362
diff changeset
147 .. image:: hook.jpg
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
148 :height: 250px
344
catherine@Drou
parents: 337
diff changeset
149
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
150 ::
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
151
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
152 self.preloop()
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
153 self.postloop()
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
154 self.precmd(line)
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
155 self.postcmd(stop, line)
363
2b2836b783be added hook pic
cat@eee
parents: 362
diff changeset
156
344
catherine@Drou
parents: 337
diff changeset
157 Hooks: pirate3.py
catherine@Drou
parents: 337
diff changeset
158 =================
catherine@Drou
parents: 337
diff changeset
159
catherine@Drou
parents: 337
diff changeset
160 ::
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
161
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
162 def do_loot(self, arg):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
163 'Seize booty from a passing ship.'
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
164 self.gold += 1
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
165 def do_drink(self, arg):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
166 'Drown your sorrrows in rrrum.'
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
167 self.gold -= 1
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
168 def precmd(self, line):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
169 self.initial_gold = self.gold
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
170 return line
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
171 def postcmd(self, stop, line):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
172 if self.gold != self.initial_gold:
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
173 print('Now we gots {0} doubloons'
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
174 .format(self.gold))
344
catherine@Drou
parents: 337
diff changeset
175
catherine@Drou
parents: 337
diff changeset
176 Arguments: pirate4.py
catherine@Drou
parents: 337
diff changeset
177 =====================
catherine@Drou
parents: 337
diff changeset
178
catherine@Drou
parents: 337
diff changeset
179 ::
catherine@Drou
parents: 337
diff changeset
180
catherine@Drou
parents: 337
diff changeset
181 def do_drink(self, arg):
catherine@Drou
parents: 337
diff changeset
182 '''Drown your sorrrows in rrrum.
catherine@Drou
parents: 337
diff changeset
183
catherine@Drou
parents: 337
diff changeset
184 drink [n] - drink [n] barrel[s] o' rum.'''
catherine@Drou
parents: 337
diff changeset
185 try:
catherine@Drou
parents: 337
diff changeset
186 self.gold -= int(arg)
catherine@Drou
parents: 337
diff changeset
187 except:
catherine@Drou
parents: 337
diff changeset
188 if arg:
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
189 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
190 .format(arg))
344
catherine@Drou
parents: 337
diff changeset
191 self.gold -= 1
catherine@Drou
parents: 337
diff changeset
192
catherine@Drou
parents: 337
diff changeset
193 quitting: pirate5.py
catherine@Drou
parents: 337
diff changeset
194 ====================
catherine@Drou
parents: 337
diff changeset
195
catherine@Drou
parents: 337
diff changeset
196 ::
catherine@Drou
parents: 337
diff changeset
197
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
198 def postcmd(self, stop, line):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
199 if self.gold != self.initial_gold:
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
200 print('Now we gots {0} doubloons'
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
201 .format(self.gold))
344
catherine@Drou
parents: 337
diff changeset
202 if self.gold < 0:
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
203 print("Off to debtorrr's prison.")
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
204 stop = True
344
catherine@Drou
parents: 337
diff changeset
205 return stop
catherine@Drou
parents: 337
diff changeset
206 def do_quit(self, arg):
catherine@Drou
parents: 337
diff changeset
207 print("Quiterrr!")
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
208 return True
344
catherine@Drou
parents: 337
diff changeset
209
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
210 prompts, defaults: pirate6.py
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
211 =============================
344
catherine@Drou
parents: 337
diff changeset
212
catherine@Drou
parents: 337
diff changeset
213 ::
catherine@Drou
parents: 337
diff changeset
214
catherine@Drou
parents: 337
diff changeset
215 prompt = 'arrr> '
catherine@Drou
parents: 337
diff changeset
216 def default(self, line):
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
217 print('What mean ye by "{0}"?'
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
218 .format(line))
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
219
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
220 Other CLI packages
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
221 ==================
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
222
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
223 .. class:: big
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
224
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
225 * CmdLoop
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
226 * cly
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
227 * CMdO
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
228 * pycopia
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
229 * cmdlin
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
230 * cmd2
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
231
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
232 Demo
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
233 ====
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
234
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
235 .. class:: huge
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
236
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
237 Convert ``cmd`` app to ``cmd2``
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
238
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
239 cmd2
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
240 ====
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
241
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
242 .. image:: schematic.png
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
243 :height: 350px
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
244
373
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
245 As you wish, Guido
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
246 ==================
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
247
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
248 .. class:: huge
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
249
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
250 Python 3 compatible
373
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
251
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
252 (um, mostly)
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
253
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
254 Absolutely free
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
255 ===============
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
256
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
257 Script files
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
258
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
259 Commands at invocation
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
260
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
261 Output redirection
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
262
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
263 Python
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
264
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
265 Transcript testing
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
266
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
267 But wait, there's more
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
268 ======================
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
269
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
270 * Abbreviated commands
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
271 * Shell commands
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
272 * Quitting
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
273 * Timing
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
274 * Echo
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
275 * Debug
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
276
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
277 Minor changes: pirate7.py
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
278 =========================
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
279
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
280 ::
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
281
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
282 default_to_shell = True
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
283 multilineCommands = ['sing']
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
284 terminators = Cmd.terminators + ['...']
356
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
285 songcolor = 'blue'
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
286 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
287 Cmd.shortcuts.update({'~': 'sing'})
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
288 def do_sing(self, arg):
356
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
289 print(self.colorize(arg, self.songcolor))
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
290
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
291 Now how much would you pay?
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
292 ===========================
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
293
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
294 options / flags
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
295
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
296 Quiet (suppress feedback)
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
297
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
298 BASH-style ``select``
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
299
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
300 Parsing: terminators, suffixes
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
301
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
302 Options: pirate8.py
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
303 ===================
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
304
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
305 ::
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
306
375
6cc12ad6e616 options in pirate8.py slide
cat@eee
parents: 374
diff changeset
307 @options([make_option('--ho', type='int', default=2,
6cc12ad6e616 options in pirate8.py slide
cat@eee
parents: 374
diff changeset
308 help="How often to chant 'ho'"),
6cc12ad6e616 options in pirate8.py slide
cat@eee
parents: 374
diff changeset
309 make_option('-c', '--commas',
6cc12ad6e616 options in pirate8.py slide
cat@eee
parents: 374
diff changeset
310 action="store_true",
6cc12ad6e616 options in pirate8.py slide
cat@eee
parents: 374
diff changeset
311 help="Intersperse commas")])
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
312 def do_yo(self, arg, opts):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
313 chant = ['yo'] + ['ho'] * opts.ho
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
314 separator = ', ' if opts.commas else ' '
352
798c7f32a960 line spacing
catherine@Drou
parents: 351
diff changeset
315 chant = separator.join(chant)
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
316 print('{0} and a bottle of {1}'
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
317 .format(chant, arg))
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
318
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
319 Serious example: sqlpython
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
320 ==========================
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
321
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
322 .. class:: big
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
323
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
324 ``cmd``-based app by Luca Canali @ CERN
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
325
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
326 Replacement for Oracle SQL\*Plus
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
327
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
328 Now ``cmd2``-based; postgreSQL; MySQL
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
329
376
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
330 File reporter
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
331 =============
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
332
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
333 .. class:: huge
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
334
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
335 Gather info: Python
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
336
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
337 Store: postgresql
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
338
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
339 Report: html
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
340
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
341 fileutil.py
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
342 ===========
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
343
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
344 ::
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
345
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
346 import glob
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
347 import os.path
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
348
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
349 for fullfilename in glob.glob('/home/cat/proj/cmd2/*.py'):
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
350 (dirpath, fname) = os.path.split(fullfilename)
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
351 stats = os.stat(fullfilename)
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
352 binds['path'] = dirpath
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
353 binds['name'] = fname
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
354 binds['bytes'] = stats.st_size
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
355 cmd("""INSERT INTO cat.files (path, name, bytes)
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
356 VALUES (%(path)s, %(name)s, %(bytes)s)""")
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
357 quit()
32b9137577b8 avoiding 'str doesn't support the buffer api' exception
cat@eee
parents: 375
diff changeset
358
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
359 sqlpython features
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
360 ==================
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
361
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
362 .. class:: big
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
363
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
364 * from ``cmd2``: scripts, redirection,
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
365 py, etc.
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
366 * multiple connections
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
367 * UNIX: ls, cat, grep
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
368 * Special output
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
369
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
370
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
371 Thank you
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
372 =========
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
373
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
374 .. class:: big
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
375
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
376 http://pypi.python.org/pypi/cmd2
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
377
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
378 http://catherinedevlin.blogspot.com
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
379
374
89e38f922c25 font sizes up
cat@eee
parents: 373
diff changeset
380 http://catherinedevlin.pythoneers.com
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
381
363
2b2836b783be added hook pic
cat@eee
parents: 362
diff changeset
382