list scanner loop...?
Ignacio Vazquez-Abrams
ignacio at openservices.net
Tue Aug 28 15:56:12 EDT 2001
On Tue, 28 Aug 2001, tefol wrote:
> Hi there.
>
> Another newbie, armed with Learning Python. Setting myself a task of
> manipulating all the VirtualHost entries on a Linux Apache server....
Oh hell...
Not for being a newbie, for wanting to go anywhere near VirtualHost with a
program. I guess sending a newbie after that is probably best. You all seem to
think of such a thing as a "challenge". To any sane person such a thing would
be nuts ;)
> 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.
IIRC, if you use __default__:80, then you won't need a specific one at 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.
You need to go through each element of the list:
---
for i in lFile:
[do something to i]
[do something else]
...
---
i will contain each of the elements of the list one at a time in order.
> 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.
Don't write it to a file until you are completely, absolutely, 100% done. File
operations are SLOOOOOOW compared to in-memory tasks.
> 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
Something you can do is write code to tear apart the VirtualHost sections
line-by-line and store the directive and its options separately. I'm sure that
there are plenty of people who would find such a tool useful :)
--
Ignacio Vazquez-Abrams <ignacio at openservices.net>
More information about the Python-list
mailing list