« November 2009
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
Today
XML

Neat blogs

Navigation

Editing

Powered by Roller Weblogger.

statcounter.com

clustrmaps.com

Locations of visitors to this page

technorati.com

20081020 Monday October 20, 2008
Another common task for Python

I'm in the midst of debugging a snoop implementation and I wanted to recompile with gcc and use gdb. I saved the output from the make command and basically used vi to put each .o file on a single line:

[th199096@jhereg snoop]> more files.make 
nfs4_xdr.o
snoop.o
snoop_aarp.o
snoop_adsp.o
snoop_aecho.o
snoop_apple.o

Note that I could strip off the '.o's manually, but typically I would leave them there. What I want to do is take the filename and use it twice in command. I.e.

% gcc -g -c -o nfs4_xdr.o nfs4_xdr.c

So I decided to use Python to learn a bit more about it:

[th199096@jhereg snoop]> more tran.py 
#!/usr/sfw/bin/python

l1 = []
print "#!/bin/sh -x"
print "# Make no changes here, machine generated!"
print "rm snoop *.o"

for line in open("files.make"):
        [name, ext] = line.split('.')
        print "gcc -g -DUSE_FOR_SNOOP -c -I/builds/th199096/snoop/proto/root_i386/usr/include" \
                " -I. -I/builds/th199096/snoop/usr/src/common/net/dhcp -o %s.o %s.c" % (name, name)
        l1.append(name)

print 'gcc -g -DTEXT_DOMAIN="SUNW_OST_OSCMD" -D_TS_ERRN -Bdirect -o snoop ',
for name in l1:
        print "%s.o" % (name),

print "-L/builds/th199096/snoop/proto/root_i386/lib -L/builds/th199096/snoop/proto/root_i386/usr/lib" \
        " -ldhcputil -ldlpi -lsocket -lnsl -ltsol"

One thing that jumped out was since I threw away the 'ext', I didn't have to worry abotu stripping off the '\n'. I also made use of the ',' on the end of the print statements to keep a line going.

I liked the ease of adding to the list of filenames. And in general, I found it easy to make a quick change and retest.

Could I have done this another way, say with the Makefile? Sure, but it wouldn't have been a learning experience. And off I go, the gdb prompt is calling me!


Originally posted on Kool Aid Served Daily
Copyright (C) 2008, Kool Aid Served Daily

Trackback URL: http://blogs.sun.com/tdh/entry/another_common_task_for_python
Comments:

good info about this problem

Posted by rapidshare search on April 05, 2009 at 03:36 PM CDT #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed