#! /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 ############################################################ # get column names from sqlite database #import sqlite3 #home = os.environ['HOME'] #db = home + "/testdb" #conn = sqlite3.connect(db) #cursor = conn.cursor() #cursor.execute("select sql from sqlite_master") #row = cursor.fetchall()[0] #conn.commit() #conn.close() #lines = row[0].split('\n') #for line in lines: # if 'CREATE' in line: continue # if ')' in line: continue # field, bogus = line.split(" ",1) # print field #sys.exit() ############################################################ # program name program = os.path.basename(sys.argv[0]) ############################################################ # requires pysqlite (http://pysqlite.org) # #from pysqlite2 import dbapi2 as sqlite #dbfile = '/tmp/test.db' #db = sqlite.connect(dbfile) #cur = db.cursor() #cur.execute('CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)') #db.commit() #cur.execute('INSERT INTO n (id, f, l) VALUES(NULL, "john", "smith")') #db.commit() #cur.execute('SELECT * FROM n') #print cur.fetchall() #os.unlink(dbfile) ############################################################ # 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 ) ############################################################ # eof: tester.py vim: ts=2 sw=2 sts=2 et: