list scanner loop...?

tefol tefol at This.Is.Not.An.Address
Tue Aug 28 15:17:14 EDT 2001


Hi there.

Another newbie, armed with Learning Python.  Setting myself a task of 
manipulating all the VirtualHost entries on a Linux Apache server....

The first thing I wanted to do was to clean up the number of newlines 
between eachvirthost entry...    Which then allowed me to make a list of 
VirtualHost entries...

Just because it was easy I decided to sort them,  though this will lead to 
another challenge later when I try to put a specific entry abck to the top 
of the list.

Next, and this was the main purpose of the project in the first place, I 
need to check through each VirtualHost to see if they are logging, and then 
if they aren't insert a TransferLog and ErrorLog entry into their 
VirtualHost.

This is where I get into a spot of bother.  I need to do something similart 
to creating a file scanner loop,  but instead of a file I need to use this 
list.   I just don't see how.

Is it possible?   If I write the list out to a file, then do a file scanner 
loop all the \n in each list entry will make everything screwy.


The code I have below works great,  I just can't see where to take it next 
to accomplish what I need.   Any advice, comments, even style guide would 
be greatly appreciated. 

Tefol


***

import string,re

Hosts = open(r'd:\proj\python\virts\virts.conf', 'r')
sVirts = Hosts.read()

sFile = re.sub('VirtualHost>\n*<VirtualHost ', 
'VirtualHost>\n\n<VirtualHost ', sVirts)
lFile = string.split(sFile, '\n\n')
lFile.sort()



output = open(r'd:\proj\python\virts\list.txt', 'w')

output.writelines(lFile)

output.close()

INL =  open(r'd:\proj\python\virts\list.txt', 'r') #Insert New Line
sINL = INL.read()

sSNL = re.sub('VirtualHost><VirtualHost ', 'VirtualHost>\n\n<VirtualHost ', 
sINL) #Substitute New Line

output = open(r'd:\proj\python\virts\file.txt', 'w')

output.write(sSNL)

output.close()



More information about the Python-list mailing list