annotate docs/pycon2010/pycon2010.rst @ 344:4300ef912f4a

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