Linux Gazette
...making Linux just a little more fun!
May 2005 (#114):
* [1]The Mailbag
* [2]The Answer Gang
* [3]News Bytes, by Michael Conry
* [4]Python for scientific use. Part I: Data Visualization, by Anders
Andreasen
* [5]A Tale of Three Conferences, by Howard Dyckoff
* [6]Secure Knoppix on CD-ROM for Disaster Recovery, by Edgar Howell
* [7]Shelling your Linux box with Festival, by Maxin B. John
* [8]Right To Your Own Devices, by Kapil Hari Paranjape
* [9]Lock It Down With Arno's iptables-firewall, by S. Keeling
* [10]Introduction to Shell Scripting, part 4, by Ben Okopnik
* [11]Measure CPU Fan Speed with an RTAI/LXRT Stroboscope!, by Pramode
C.E.
* [12]HelpDex, by Shane Collinge
* [13]Qubism, by Jon "Sir Flakey" Harsem
* [14]PmWiki - Wiki the Painless Way, by Raj Shekhar
* [15]The Foolish Things We Do With Our Computers, by Ben Okopnik
* [16]The Linux Launderette
The Mailbag
_________________________________________________________________
HELP WANTED : Article Ideas
Submit comments about articles, or articles themselves (after reading
[17]our guidelines) to [18]The Editors of Linux Gazette, and technical
answers and tips about Linux to [19]The Answer Gang.
_________________________________________________________________
* [20]Python, tail -f, pyurlview, non-blocking I/O
* [21]Which flavour?!
____________________________________________________
Python, tail -f, pyurlview, non-blocking I/O
Mon, 28 Mar 2005 05:03:50 +0100
Thomas Adam ([22]thomas from edulinux.homeunix.org)
Hello,
I'm hoping this will drum up some replies. I'm tumbling head-first into the
world of python and ncurses for this, and know very little about both.
To cut a long (and rather boring) story short, I run [23]irssi in a screen
session on my poor P166 server. X11-forwarding is not an option as I don't
have nor want X11 installed, and it's damn slow even if I did. But one
useful feature is using one of the many scripts off of irssi's website, I
can get irssi to scrape urls into a text file. "Wooooo, I hear you say".
Well, it is nice. And thanks to network transparency, I am able to tail that
logfile via shfs (ssh filesystem, essentially). So then I got to thinking.
What's an easy way of displaying the URLs in the file? I remembered a
program that ships (often) with mutt -- "urlview". It scans a file for a
regexp for URLs and presents a means of selecting them and launching them.
Brilliant. Except... it expects a file -- piping to stdin blocks.
Bah! I don't want to hack the source-code, unblocked I/O in C is a headache.
So I stumbled across pyurlview [1] a replacement written in Python. It's
"ok" and is in a language I can read.
What I'm wanting to do is emulate this:
tail -f ./some_file | pyurlview
Now that doesn't work as-is. So I thought about it a bit, and came up with
this little bit of python code (which I hope is the correct "way" to do it):
#! /usr/bin/env python
import os,sys
while 1:
#sys.stdin.fileno()
s = sys.stdin.readline()
print "Got", s
Which seems to work when one does:
tail -f ./foo | testfile.py
So I thought I'd try and incorporate that idea into the pyurlview script [1]
I tried all I might, to no avail. The closest I got was here [2] but that's
mangling everything and isn't functioning like in the example I correctly
showed above.
So if someone can see the error in logic, do say. Or does anyone know of an
existing program that will do what I want? I can use any form of scripting
language to do it (awk, ruby, etc) already -- but it's more the curses and
non-blocking I/O I'm interested about. Plus, I'd rather not reinvent the
wheel, hence battling it out with python. maybe I could use 'multitail' but
it's UI sucks for what I am wanting.
Thanks In Advance,
-- Thomas Adam
=1= |