summaryrefslogtreecommitdiff
path: root/docs/pycon2010
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2016-12-09 16:54:10 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2016-12-09 16:54:10 -0500
commit06331d3ab75feb807dc48d824cbd54898a6b6cdd (patch)
tree24034e3f0ff7cd94239d575fe046acc550e7a49f /docs/pycon2010
parentb9658cff197beff5a00632a68ecf85838879835e (diff)
downloadcmd2-git-06331d3ab75feb807dc48d824cbd54898a6b6cdd.tar.gz
First stage of refactoring to support full simultaneous Python 2 and 3 compatibility via use of the six module.
Diffstat (limited to 'docs/pycon2010')
-rw-r--r--docs/pycon2010/fileutil.py12
-rw-r--r--docs/pycon2010/graph.py41
-rw-r--r--docs/pycon2010/pirate.py3
-rw-r--r--docs/pycon2010/pirate2.py1
-rw-r--r--docs/pycon2010/pirate3.py5
-rw-r--r--docs/pycon2010/pirate4.py11
-rw-r--r--docs/pycon2010/pirate5.py11
-rw-r--r--docs/pycon2010/pirate6.py11
-rw-r--r--docs/pycon2010/pirate7.py11
-rw-r--r--docs/pycon2010/pirate8.py13
-rw-r--r--docs/pycon2010/pycon2010.rst64
-rw-r--r--docs/pycon2010/schematic.py32
12 files changed, 69 insertions, 146 deletions
diff --git a/docs/pycon2010/fileutil.py b/docs/pycon2010/fileutil.py
deleted file mode 100644
index 5e754b5a..00000000
--- a/docs/pycon2010/fileutil.py
+++ /dev/null
@@ -1,12 +0,0 @@
-import glob
-import os.path
-
-for fullfilename in glob.glob('/home/cat/proj/cmd2/*.py'):
- (dirpath, fname) = os.path.split(fullfilename)
- stats = os.stat(fullfilename)
- binds['path'] = dirpath
- binds['name'] = fname
- binds['bytes'] = stats.st_size
- cmd("""INSERT INTO cat.files (path, name, bytes)
- VALUES (%(path)s, %(name)s, %(bytes)s)""")
-quit()
diff --git a/docs/pycon2010/graph.py b/docs/pycon2010/graph.py
deleted file mode 100644
index 96ffde72..00000000
--- a/docs/pycon2010/graph.py
+++ /dev/null
@@ -1,41 +0,0 @@
-from turtle import *
-pu()
-goto(-400,-400)
-
-def label(txt):
- write(txt, font=('Arial', 20, 'italic'))
-hideturtle()
-width(6)
-
-def line(len, _label):
- start = pos()
- pd()
- forward(len)
- pu()
- forward(30)
- pd()
- label(_label)
- pu()
- goto(start)
-
-def tech(x, y, _label):
- pu()
- goto(x, y)
- pd()
- write(_label, font=('Arial', 40, 'bold'))
- pu()
-
-line(600, "Easy to write")
-left(90)
-line(600, "Easy to use")
-
-tech(-360, 160, 'GUI')
-tech(-390, 100, 'AJAX')
-tech(-300, -10, 'webapp')
-tech(190, -380, 'CLU')
-tech(60, -320, 'TUI')
-tech(100, -210, 'cmd')
-tech(80, -80, 'cmd2')
-
-while True:
- pass \ No newline at end of file
diff --git a/docs/pycon2010/pirate.py b/docs/pycon2010/pirate.py
index 98db50ea..48afe629 100644
--- a/docs/pycon2010/pirate.py
+++ b/docs/pycon2010/pirate.py
@@ -1,7 +1,8 @@
+# coding=utf-8
from cmd import Cmd
class Pirate(Cmd):
pass
pirate = Pirate()
-pirate.cmdloop() \ No newline at end of file
+pirate.cmdloop()
diff --git a/docs/pycon2010/pirate2.py b/docs/pycon2010/pirate2.py
index e2c49609..c1852f03 100644
--- a/docs/pycon2010/pirate2.py
+++ b/docs/pycon2010/pirate2.py
@@ -1,3 +1,4 @@
+# coding=utf-8
from cmd import Cmd
# using ``do_`` methods
diff --git a/docs/pycon2010/pirate3.py b/docs/pycon2010/pirate3.py
index 7977a8dc..61eb2d4e 100644
--- a/docs/pycon2010/pirate3.py
+++ b/docs/pycon2010/pirate3.py
@@ -1,3 +1,4 @@
+# coding=utf-8
from cmd import Cmd
# using hook
@@ -7,12 +8,12 @@ class Pirate(Cmd):
'Seize booty from a passing ship.'
self.gold += 1
def do_drink(self, arg):
- 'Drown your sorrrows in rrrum.'
+ 'Drown your sorrrows in rrrum.'
self.gold -= 1
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
diff --git a/docs/pycon2010/pirate4.py b/docs/pycon2010/pirate4.py
index 5de9c212..29de7301 100644
--- a/docs/pycon2010/pirate4.py
+++ b/docs/pycon2010/pirate4.py
@@ -1,3 +1,4 @@
+# coding=utf-8
from cmd import Cmd
# using arguments
@@ -8,20 +9,20 @@ class Pirate(Cmd):
self.gold += 1
def do_drink(self, arg):
'''Drown your sorrrows in rrrum.
-
- drink [n] - drink [n] barrel[s] o' rum.'''
+
+ 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
+ self.gold -= 1
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'.format(self.gold))
pirate = Pirate()
-pirate.cmdloop() \ No newline at end of file
+pirate.cmdloop()
diff --git a/docs/pycon2010/pirate5.py b/docs/pycon2010/pirate5.py
index 7add4635..f6125f57 100644
--- a/docs/pycon2010/pirate5.py
+++ b/docs/pycon2010/pirate5.py
@@ -1,3 +1,4 @@
+# coding=utf-8
from cmd import Cmd
# quitting
@@ -8,18 +9,18 @@ class Pirate(Cmd):
self.gold += 1
def do_drink(self, arg):
'''Drown your sorrrows in rrrum.
-
- drink [n] - drink [n] barrel[s] o' rum.'''
+
+ 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
+ self.gold -= 1
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
@@ -29,7 +30,7 @@ class Pirate(Cmd):
return stop
def do_quit(self, arg):
print("Quiterrr!")
- return True
+ return True
pirate = Pirate()
pirate.cmdloop()
diff --git a/docs/pycon2010/pirate6.py b/docs/pycon2010/pirate6.py
index 4a03fed4..dbb18ce9 100644
--- a/docs/pycon2010/pirate6.py
+++ b/docs/pycon2010/pirate6.py
@@ -1,3 +1,4 @@
+# coding=utf-8
from cmd2 import Cmd
# prompts and defaults
@@ -12,18 +13,18 @@ class Pirate(Cmd):
self.gold += 1
def do_drink(self, arg):
'''Drown your sorrrows in rrrum.
-
- drink [n] - drink [n] barrel[s] o' rum.'''
+
+ 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
+ self.gold -= 1
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
@@ -33,7 +34,7 @@ class Pirate(Cmd):
return stop
def do_quit(self, arg):
print("Quiterrr!")
- return True
+ return True
pirate = Pirate()
pirate.cmdloop()
diff --git a/docs/pycon2010/pirate7.py b/docs/pycon2010/pirate7.py
index 25ff5822..32f4954d 100644
--- a/docs/pycon2010/pirate7.py
+++ b/docs/pycon2010/pirate7.py
@@ -1,3 +1,4 @@
+# coding=utf-8
from cmd2 import Cmd
# prompts and defaults
@@ -11,18 +12,18 @@ class Pirate(Cmd):
self.gold += 1
def do_drink(self, arg):
'''Drown your sorrrows in rrrum.
-
- drink [n] - drink [n] barrel[s] o' rum.'''
+
+ 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
+ self.gold -= 1
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
@@ -32,7 +33,7 @@ class Pirate(Cmd):
return stop
def do_quit(self, arg):
print("Quiterrr!")
- return True
+ return True
default_to_shell = True
multilineCommands = ['sing']
terminators = Cmd.terminators + ['...']
diff --git a/docs/pycon2010/pirate8.py b/docs/pycon2010/pirate8.py
index 3e80b241..c80d41f4 100644
--- a/docs/pycon2010/pirate8.py
+++ b/docs/pycon2010/pirate8.py
@@ -1,3 +1,4 @@
+# coding=utf-8
from cmd2 import Cmd, options, make_option
# prompts and defaults
@@ -11,18 +12,18 @@ class Pirate(Cmd):
self.gold += 1
def do_drink(self, arg):
'''Drown your sorrrows in rrrum.
-
- drink [n] - drink [n] barrel[s] o' rum.'''
+
+ 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
+ self.gold -= 1
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
@@ -32,7 +33,7 @@ class Pirate(Cmd):
return stop
def do_quit(self, arg):
print("Quiterrr!")
- return True
+ return True
default_to_shell = True
multilineCommands = ['sing']
terminators = Cmd.terminators + ['...']
@@ -44,7 +45,7 @@ class Pirate(Cmd):
@options([make_option('--ho', type='int', default=2,
help="How often to chant 'ho'"),
make_option('-c', '--commas',
- action="store_true",
+ action="store_true",
help="Intersperse commas")])
def do_yo(self, arg, opts):
chant = ['yo'] + ['ho'] * opts.ho
diff --git a/docs/pycon2010/pycon2010.rst b/docs/pycon2010/pycon2010.rst
index 0b3b7a46..6c3af676 100644
--- a/docs/pycon2010/pycon2010.rst
+++ b/docs/pycon2010/pycon2010.rst
@@ -11,7 +11,7 @@ Web 2.0
.. image:: web-2-0-logos.gif
:height: 350px
-
+
But first...
============
@@ -20,10 +20,10 @@ But first...
.. image:: akkad.png
:height: 250px
-
+
Sargon the Great
Founder of Akkadian Empire
-
+
.. twenty-third century BC
In between
@@ -31,16 +31,16 @@ In between
.. image:: apple.jpg
:height: 250px
-
+
Command-Line Interface
- Unlike the Akkadian Empire,
+ Unlike the Akkadian Empire,
the CLI will never die.
Defining CLI
============
Also known as
-
+
- "Line-oriented command interpreter"
- "Command-line interface"
- "Shell"
@@ -85,24 +85,24 @@ Examples
.. image:: urwid.png
:height: 250px
-
+
Decide your priorities
======================
.. image:: strategy.png
:height: 350px
-
+
A ``cmd`` app: pirate.py
========================
::
from cmd import Cmd
-
+
class Pirate(Cmd):
pass
-
+
pirate = Pirate()
pirate.cmdloop()
@@ -114,9 +114,9 @@ Fundamental prrrinciple
=======================
.. class:: huge
-
- ``(Cmd) foo a b c``
-
+
+ ``(Cmd) foo a b c``
+
becomes
``self.do_foo('a b c')``
@@ -139,7 +139,7 @@ Fundamental prrrinciple
print('Now we gots {0} doubloons'
.format(self.gold))
-.. do_methods; more help
+.. do_methods; more help
Hooks
=====
@@ -163,16 +163,16 @@ Hooks: pirate3.py
'Seize booty from a passing ship.'
self.gold += 1
def do_drink(self, arg):
- 'Drown your sorrrows in rrrum.'
+ 'Drown your sorrrows in rrrum.'
self.gold -= 1
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
-
+
Arguments: pirate4.py
=====================
@@ -180,22 +180,22 @@ Arguments: pirate4.py
def do_drink(self, arg):
'''Drown your sorrrows in rrrum.
-
- drink [n] - drink [n] barrel[s] o' rum.'''
+
+ 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
-
+ self.gold -= 1
+
quitting: pirate5.py
====================
::
- def postcmd(self, stop, line):
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
@@ -205,7 +205,7 @@ quitting: pirate5.py
return stop
def do_quit(self, arg):
print("Quiterrr!")
- return True
+ return True
prompts, defaults: pirate6.py
=============================
@@ -227,7 +227,7 @@ Other CLI packages
* CMdO
* pycopia
* cmdlin
- * cmd2
+ * cmd2
Demo
====
@@ -258,7 +258,7 @@ Script files
Commands at invocation
-Output redirection
+Output redirection
Python
@@ -273,9 +273,9 @@ But wait, there's more
* Timing
* Echo
* Debug
-
+
Minor changes: pirate7.py
-=========================
+=========================
::
@@ -287,18 +287,18 @@ Minor changes: pirate7.py
Cmd.shortcuts.update({'~': 'sing'})
def do_sing(self, arg):
print(self.colorize(arg, self.songcolor))
-
+
Now how much would you pay?
===========================
options / flags
-Quiet (suppress feedback)
+Quiet (suppress feedback)
BASH-style ``select``
Parsing: terminators, suffixes
-
+
Options: pirate8.py
===================
@@ -307,13 +307,13 @@ Options: pirate8.py
@options([make_option('--ho', type='int', default=2,
help="How often to chant 'ho'"),
make_option('-c', '--commas',
- action="store_true",
+ action="store_true",
help="Intersperse commas")])
def do_yo(self, arg, opts):
chant = ['yo'] + ['ho'] * opts.ho
separator = ', ' if opts.commas else ' '
chant = separator.join(chant)
- print('{0} and a bottle of {1}'
+ print('{0} and a bottle of {1}'
.format(chant, arg))
Serious example: sqlpython
diff --git a/docs/pycon2010/schematic.py b/docs/pycon2010/schematic.py
deleted file mode 100644
index 80774859..00000000
--- a/docs/pycon2010/schematic.py
+++ /dev/null
@@ -1,32 +0,0 @@
-from turtle import *
-hideturtle()
-width(6)
-pensize = 10
-pu()
-goto(0,-400)
-
-def rectangle(x, y, _label):
- pu()
- seth(0)
- backward(x / 2)
- fontsize = 40
- pd()
- for i in range(2):
- forward(x)
- left(90)
- forward(y)
- left(90)
- pu()
- forward(x / 2)
- left(90)
- forward(y / 2 - fontsize)
- pd()
- write(_label, align='center', font=('Arial', fontsize, 'bold'))
-
-rectangle(800, 80, 'cmd')
-pu()
-forward(80)
-rectangle(200, 400, 'cmd2')
-
-while True:
- pass