# HG changeset patch # User catherine@Drou # Date 1266336176 18000 # Node ID 2ce34ad4e520516de59de39ff4dae340f24310ce # Parent 8aa71e8f1064be8cb378d88bcfaaa6a85995d8d7 begin Pycon talk diff -r 8aa71e8f1064 -r 2ce34ad4e520 docs/pycon2010/apple.jpg Binary file docs/pycon2010/apple.jpg has changed diff -r 8aa71e8f1064 -r 2ce34ad4e520 docs/pycon2010/pirate.py --- /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 diff -r 8aa71e8f1064 -r 2ce34ad4e520 docs/pycon2010/pirate2.py --- /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 diff -r 8aa71e8f1064 -r 2ce34ad4e520 docs/pycon2010/pirate3.py --- /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 diff -r 8aa71e8f1064 -r 2ce34ad4e520 docs/pycon2010/pirate4.py --- /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 diff -r 8aa71e8f1064 -r 2ce34ad4e520 docs/pycon2010/pirate5.py --- /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 diff -r 8aa71e8f1064 -r 2ce34ad4e520 docs/pycon2010/pirate6.py --- /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 diff -r 8aa71e8f1064 -r 2ce34ad4e520 docs/pycon2010/pycon2010.rst --- /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 + diff -r 8aa71e8f1064 -r 2ce34ad4e520 docs/pycon2010/sargon.jpg Binary file docs/pycon2010/sargon.jpg has changed diff -r 8aa71e8f1064 -r 2ce34ad4e520 docs/pycon2010/urwid.png Binary file docs/pycon2010/urwid.png has changed diff -r 8aa71e8f1064 -r 2ce34ad4e520 docs/pycon2010/web-2-0-logos.gif Binary file docs/pycon2010/web-2-0-logos.gif has changed