changeset 337:2ce34ad4e520

begin Pycon talk
author catherine@Drou
date Tue, 16 Feb 2010 11:02:56 -0500
parents 8aa71e8f1064
children 92a15405ed8a
files docs/pycon2010/apple.jpg docs/pycon2010/pirate.py docs/pycon2010/pirate2.py docs/pycon2010/pirate3.py docs/pycon2010/pirate4.py docs/pycon2010/pirate5.py docs/pycon2010/pirate6.py docs/pycon2010/pycon2010.rst docs/pycon2010/sargon.jpg docs/pycon2010/urwid.png docs/pycon2010/web-2-0-logos.gif
diffstat 11 files changed, 223 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file docs/pycon2010/apple.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/pycon2010/pirate.py	Tue Feb 16 11:02:56 2010 -0500
@@ -0,0 +1,7 @@
+from cmd import Cmd
+
+class Pirate(Cmd):
+    pass
+
+pirate = Pirate()
+pirate.cmdloop()
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/pycon2010/pirate2.py	Tue Feb 16 11:02:56 2010 -0500
@@ -0,0 +1,16 @@
+from cmd import Cmd
+# using ``do_`` methods
+
+class Pirate(Cmd):
+    gold = 10
+    def do_loot(self, arg):
+        'Seize booty frrrom a passing ship.'
+        self.gold += 1
+        print 'Now we gots {0} doubloons'.format(self.gold)
+    def do_drink(self, arg):
+        'Drown your sorrrows in rrrum.'
+        self.gold -= 1
+        print 'Now we gots {0} doubloons'.format(self.gold)
+
+pirate = Pirate()
+pirate.cmdloop()
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/pycon2010/pirate3.py	Tue Feb 16 11:02:56 2010 -0500
@@ -0,0 +1,16 @@
+from cmd import Cmd
+# using a hook
+
+class Pirate(Cmd):
+    gold = 3
+    def do_loot(self, arg):
+        'Drown your sorrrows in rrrum.'        
+        self.gold += 1
+    def do_drink(self, arg):
+        'Drown your sorrrows in rrrum.'        
+        self.gold -= 1
+    def postcmd(self, stop, line):                         
+        print 'Now we gots {0} doubloons'.format(self.gold)
+
+pirate = Pirate()
+pirate.cmdloop()
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/pycon2010/pirate4.py	Tue Feb 16 11:02:56 2010 -0500
@@ -0,0 +1,23 @@
+from cmd import Cmd
+# using arguments
+
+class Pirate(Cmd):
+    gold = 3
+    def do_loot(self, arg):
+        'Drown your sorrrows in rrrum.'               
+        self.gold += 1
+    def do_drink(self, arg):
+        '''Drown your sorrrows in rrrum.
+        
+        drink [n] - drink [n] barrel[s] o' rum.'''  
+        try:
+            self.gold -= int(arg)
+        except:
+            if arg:
+                print '''What's "{0}"?  I'll take rrrum.'''.format(arg)
+            self.gold -= 1            
+    def postcmd(self, stop, line):
+        print 'Now we gots {0} doubloons'.format(self.gold)
+
+pirate = Pirate()
+pirate.cmdloop()
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/pycon2010/pirate5.py	Tue Feb 16 11:02:56 2010 -0500
@@ -0,0 +1,30 @@
+from cmd import Cmd
+# quitting
+
+class Pirate(Cmd):
+    gold = 3
+    def do_loot(self, arg):
+        'Drown your sorrrows in rrrum.'                
+        self.gold += 1
+    def do_drink(self, arg):
+        '''Drown your sorrrows in rrrum.
+        
+        drink [n] - drink [n] barrel[s] o' rum.'''          
+        try:
+            self.gold -= int(arg)
+        except:
+            if arg:
+                print '''What's "{0}"?  I'll take rrrum.'''.format(arg)
+            self.gold -= 1                  
+    def postcmd(self, stop, line):
+        print 'Now we gots {0} doubloons'.format(self.gold)
+        if self.gold < 0:
+            print "Off to debtorrr's prrrison.  Game overrr."
+            return True
+        return stop
+    def do_quit(self, arg):
+        print "Quiterrr!"
+        return True    
+
+pirate = Pirate()
+pirate.cmdloop()
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/pycon2010/pirate6.py	Tue Feb 16 11:02:56 2010 -0500
@@ -0,0 +1,33 @@
+from cmd2 import Cmd
+# prompts and defaults
+
+class Pirate(Cmd):
+    gold = 3
+    prompt = 'arrr> '
+    def default(self, line):
+        print 'What mean ye by "{0}"?'.format(line)
+    def do_loot(self, arg):
+        'Drown your sorrrows in rrrum.'                
+        self.gold += 1
+    def do_drink(self, arg):
+        '''Drown your sorrrows in rrrum.
+        
+        drink [n] - drink [n] barrel[s] o' rum.'''          
+        try:
+            self.gold -= int(arg)
+        except:
+            if arg:
+                print '''What's "{0}"?  I'll take rrrum.'''.format(arg)
+            self.gold -= 1            
+    def postcmd(self, stop, line):
+        print 'Now we gots {0} doubloons'.format(self.gold)
+        if self.gold < 0:
+            print "Off to debtorrr's prrrison.  Game overrr."
+            return True
+        return stop
+    def do_quit(self, arg):
+        print "Quiterrr!"
+        return True    
+
+pirate = Pirate()
+pirate.cmdloop()
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/pycon2010/pycon2010.rst	Tue Feb 16 11:02:56 2010 -0500
@@ -0,0 +1,98 @@
+py 3
+
+Web 2.0
+=======
+
+.. image:: web-2-0-logos.gif
+   :height: 300 px
+   
+But first...
+============
+
+.. image:: sargon.jpg
+   :height: 300 px
+   
+Sargon the Great founded the Akkadian Empire
+in the twenty-third century BC.
+
+In between
+==========
+
+.. image:: apple.jpg
+   :height: 300 px
+ 
+Unlike the Akkadian Empire, the CLI will never disappear.
+
+line-oriented command interpreter
+command-line interface
+text user interface
+terminal user interface
+console
+shell
+
+Defining
+========
+
+Prompt accepts free text input
+Outputs lines of text
+CLI environment persists
+
+Examples
+========
+
+Bash, Korn, zsh
+Python shell
+screen
+Zork
+ed
+SQL clients: psql, SQL*\Plus, mysql...
+
+!= Command Line Utilities
+=========================
+
+Accept single set of arguments at 
+invocation, execute, terminate
+
+dir
+grep
+ping
+
+sys.argv
+optparse
+
+!= Text User Interfaces
+=======================
+
+("console")
+
+Use entire (session) screen
+Not line-by-line
+
+.. image:: urwid.png
+   :height: 300px
+   
+curses
+urwid
+
+
+foo a b c ->
+self.do_foo('a b c')
+self.default('foo a b c')
+
+pirate.py
+=========
+
+::
+
+   from cmd import Cmd
+   
+   class Pirate(Cmd):
+       pass
+   
+   pirate = Pirate()
+   pirate.cmdloop()
+
+history: cursor
+ctrl-r
+help
+
Binary file docs/pycon2010/sargon.jpg has changed
Binary file docs/pycon2010/urwid.png has changed
Binary file docs/pycon2010/web-2-0-logos.gif has changed