Skip to content

Commit

Permalink
Added example runs in docstring comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed May 19, 2010
1 parent f61f38d commit 634eb3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
16 changes: 12 additions & 4 deletions examples/simple_annotate_date.py
@@ -1,15 +1,23 @@
""" """
Simply call "ls -a", no special stuff. Annotate each line coming in with the current date.
Example runs:
python simple_annotate_date.py find .
python simple_annotate_date.py cat (and start typing in stdin)
python simple_annotate_date.py grep 'foobar' *
""" """
import sys import sys
import datetime import datetime
import drainers import drainers


def annotate(line, is_err): def annotate(line, is_err):
sys.stdout.write('[%s] ' % datetime.datetime.now())
if is_err: if is_err:
sys.stdout.write('ERROR: ') stream = sys.stderr
sys.stdout.write(line) else:
stream = sys.stdout
stream.write('[%s] ' % datetime.datetime.now())
stream.write('ERROR: ')
stream.write(line)


d = drainers.Drainer(sys.argv[1:], read_event_cb=annotate) d = drainers.Drainer(sys.argv[1:], read_event_cb=annotate)
d.start() d.start()
10 changes: 8 additions & 2 deletions examples/simple_find.py
@@ -1,6 +1,12 @@
""" """
Simple finder. Search for a file called "foobar" for a maximum of 10 Simple finder. Search for the file given in sys.argv[1] for a maximum of
seconds, then abort. Present results of found files and errors. 10 seconds, then abort. Present results of found files and errors.
For the best demonstration effect, make the find run long (for example,
run the script from /).
Example runs:
python simple_find.py <somefile>
""" """
import sys import sys
import drainers import drainers
Expand Down

0 comments on commit 634eb3a

Please sign in to comment.