Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example runs in docstring comment.
- Loading branch information
Showing
2 changed files
with
20 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters