ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
Re: [Tutor] Config file parsing
by Kent Johnson other posts by this author
Apr 20 2006 9:43AM messages near this date
[Tutor] Config file parsing | [Tutor] Tutor FAQ?
Tino Dai wrote:
>  Hi Everybody,
>  
>       Before I start reinventing the wheel, is there any code out there 
>  for parsing configuration filesn in paragraph format. I am creating a 
>  multi-process monitor that will read in a configuration file that will 

If you have control over the config file format you can use ConfigParser 
in the standard lib. It reads .ini style files so you would write
[apache]
process=/usr/bin/httpd
...etc

You could also use one of the add-on config file readers which have more 
features, for example
http://voidspace.org.uk/python/modules.shtml#configobj

Another option is to make your config file be a Python module that you 
just import. What you wrote is pretty close to dictionary syntax. You 
could use this:
config = dict(
   apache = dict(
     process = '/usr/bin/httpd',
     # etc
   )
)

The syntax is not quite as user friendly but reading it is as easy as 
'import config'

Kent
>  contain the processes that they will monitor also what to do when they 
>  get get an alert. Below is an example of what I envision the configure 
>  file to look like
>  
>  apache {
>     process=/usr/bin/httpd
>     processNum = 8
>     whenDown = "Apache is totally down"
>     whenDegraded = "Apache has degraded (one or more processes has gone away"
>     whenUp = "Apache is up"
>     severityDown=1
>     severityDegraded=3
>     severityUp=5
>     .... etc ....
>  }
>  
>  Thanks in advance,
>  Tino
>  
>  
>  
>  ------------------------------------------------------------------------
>  
>  _______________________________________________
>  Tutor maillist  -  Tutor@[...].org
>  http://mail.python.org/mailman/listinfo/tutor


_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Tino Dai
Kent Johnson

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved