#! /usr/bin/python
'''
tester.py - test stuff in python
author : dave w capella http://grox.net/mailme
date : Sat Feb 9 02:54:28 PST 2008
'''
import os, sys, string, re, time, mimetypes
# how to add to the module search path
# import my library of functions
#
sys.path.append( os.path.join(os.environ['HOME'], 'bin') )
from dwc import *
# easy way to generate usage info
print __doc__ % globals()
# duh. don't ask.
print "len(sys.argv): %d" % ( len(sys.argv) )
############################################################
# like wget
#
import urllib
url = 'http://grox.net/ip'
#fd = urllib.urlopen( string.join((url,query),"?") )
fd = urllib.urlopen(url)
print 'grox.net/ip: ', fd.read()
fd.close()
############################################################
# db file w/multi-line records separated by '%' like fortune eg:
# %
# spam
# %
#
# eggs
# %
# %
# parrot
#
fd = open('tst')
lines = fd.read()
fd.close()
items = lines.split('\n%\n')
print 'items: ', len(items)
#s = 'item#4: ' + items[3]
# print generates trailing newline. alternative:
#sys.stdout.write(s)
#print string.strip(items[3])
print items[3]
############################################################
# print the environment variables
#
for k,v in os.environ.items():
print "%s:\t%s" % (k,v)
# test for a symbolic link
#
if os.path.islink("tst1"):
print "tst1 is a symlink"
else:
print "tst1 is NOT a symlink"
# how was i called?
# replace this program with another
# use search path and current environment
#
prog = sys.argv[0]
if prog == "tester.py":
os.execvpe("tester.sh",sys.argv[1:],os.environ)
# where am i?
# get the name of the current directory
#
thisdir = os.path.realpath( os.curdir )