Re: Dealing with config files what's the options

2005-02-26 Thread Jorgen Grahn
On Fri, 25 Feb 2005 21:54:16 -0500, Tom Willis <[EMAIL PROTECTED]> wrote:
> On Fri, 25 Feb 2005 15:02:04 -0700, Dave Brueck
> <[EMAIL PROTECTED]> wrote:
>> Jorgen Grahn wrote:
...
>> > How about writing them in Python?
...
> I actually thought of this, and I was kind of on the fence due to the
> intended audience.
>
> I don't think it's too much to ask that they are comfy with the
> concept of variables. I mean, if it was a shell script they'd be at
> the top of the file anyway.
> 
> Then again I'm some what hesitant to help them make the connection
> that I'm giving them the ability to indirectly edit the code. Kind of
> like opening pandoras box. Once the figure out they can open any file
> (*.py) with notepad, there will be utter anarchy and I'll get the call
> at 4am that somethings wrong with the production data.

There's two issues there.

One is about hiding knowledge from the users.  I'm against that; this isn't
the middle ages. If they shoot themselves in the foot, that is /their/
problem, not yours. You support /your/ code, not whatever they hack together.
And with 99.999% certainty, they won't touch it.

The other is about the config file messing up the environment for your main
program. Seems hard to do by mistake -- you'd have to write endless loops or
import modules and modify them, or someting. I seem to recall that you can
evaluate a piece of code in a separate environment/sandbox -- maybe that's
the way to go?

(Personally, I try to avoid designs which need config files. If I /did/ need
one I'd steal the design from some well-known Unix program, because that's
my primary target, and I'd prefer not to lock myself into Python -- I might
want to rewrite the thing in C, or Perl, or ...)

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with config files what's the options

2005-02-25 Thread Dave Brueck
Tom Willis wrote:
On Fri, 25 Feb 2005 15:02:04 -0700, Dave Brueck
How about writing them in Python?
Depending on who will be editing the config files, this can be a great approach.
[snip]
I actually thought of this, and I was kind of on the fence due to the
intended audience.
I don't think it's too much to ask that they are comfy with the
concept of variables. I mean, if it was a shell script they'd be at
the top of the file anyway.
Then again I'm some what hesitant to help them make the connection
that I'm giving them the ability to indirectly edit the code. Kind of
like opening pandoras box. Once the figure out they can open any file
(*.py) with notepad, there will be utter anarchy and I'll get the call
at 4am that somethings wrong with the production data.
If you're giving them an executable (i.e. py2exe'd), then you can just exclude 
config.py from the exe.

Either way, if you're not so worried about malicious breakage but ignorant 
breakage, then you could always name your config file something like 
'options.cfg' and then:

import new, sys
# Do this at app startup
sys.modules['config'] = new.module('config')
exec file('options.cfg').read() in config.__dict__
# All other modules do this
import config
conn = config.maxConnections
... etc ...
-Dave
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with config files what's the options

2005-02-25 Thread Tom Willis
On Fri, 25 Feb 2005 15:02:04 -0700, Dave Brueck
<[EMAIL PROTECTED]> wrote:
> Jorgen Grahn wrote:
> > On Tue, 22 Feb 2005 20:38:28 -0500, Tom Willis <[EMAIL PROTECTED]> wrote:
> >
> >>How are the expert pythoneers dealing with config files?
> >
> > ...
> >
> >>Any ideas?
> >
> >
> > How about writing them in Python?
> 
> Depending on who will be editing the config files, this can be a great 
> approach.
> 
> At the simplest level, a config.py file like this is so easy to use:
> 
> # Net settings
> timeoutSec = 5.3
> maxConnections = 3
> 
> # Other stuff
> foo = 'bar'
> 
> This type of a format is easy to use for just about anybody who has ever had 
> to
> use config files before. What's nice is that the code to use it is
> straightforward too:
> 
> import config
> conn = config.maxConnections
> ...
> 
> A few times I've tried to use accessor functions to ensure that the values are
> present or valid or whatever, but I stopped doing that because in practice 
> it's
> just not needed (again, for users who are familiar with the concept of config
> files).
> 
> A slightly more elaborate approach gives you full structure:
> 
> class Net:
>  maxConnections = 12
> 
> class System:
>  class Logging:
>  root = '/var/logs'
> 
> This prevents individual setting names from getting unwieldy, and the code 
> that
> uses it can be pretty readable too:
> 
> logRoot = config.System.Logging.root
> 
> or, if there are lots of retrievals to do:
> 
> Logging = config.System.Logging
> logRoot = Logging.root
> ... etc ...
> 
> Using classes asks a little bit more of the users (they can break it a little
> more easily), but again, in practice it really hasn't been a problem at all.
> 
> -Dave
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
I actually thought of this, and I was kind of on the fence due to the
intended audience.

I don't think it's too much to ask that they are comfy with the
concept of variables. I mean, if it was a shell script they'd be at
the top of the file anyway.

Then again I'm some what hesitant to help them make the connection
that I'm giving them the ability to indirectly edit the code. Kind of
like opening pandoras box. Once the figure out they can open any file
(*.py) with notepad, there will be utter anarchy and I'll get the call
at 4am that somethings wrong with the production data.



-- 
Thomas G. Willis
http://paperbackmusic.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with config files what's the options

2005-02-25 Thread Dave Brueck
Jorgen Grahn wrote:
On Tue, 22 Feb 2005 20:38:28 -0500, Tom Willis <[EMAIL PROTECTED]> wrote:
How are the expert pythoneers dealing with config files?
...
Any ideas?

How about writing them in Python?
Depending on who will be editing the config files, this can be a great 
approach.
At the simplest level, a config.py file like this is so easy to use:
# Net settings
timeoutSec = 5.3
maxConnections = 3
# Other stuff
foo = 'bar'
This type of a format is easy to use for just about anybody who has ever had to 
use config files before. What's nice is that the code to use it is 
straightforward too:

import config
conn = config.maxConnections
...
A few times I've tried to use accessor functions to ensure that the values are 
present or valid or whatever, but I stopped doing that because in practice it's 
just not needed (again, for users who are familiar with the concept of config 
files).

A slightly more elaborate approach gives you full structure:
class Net:
maxConnections = 12
class System:
class Logging:
root = '/var/logs'
This prevents individual setting names from getting unwieldy, and the code that 
uses it can be pretty readable too:

logRoot = config.System.Logging.root
or, if there are lots of retrievals to do:
Logging = config.System.Logging
logRoot = Logging.root
... etc ...
Using classes asks a little bit more of the users (they can break it a little 
more easily), but again, in practice it really hasn't been a problem at all.

-Dave
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with config files what's the options

2005-02-25 Thread Jorgen Grahn
On Tue, 22 Feb 2005 20:38:28 -0500, Tom Willis <[EMAIL PROTECTED]> wrote:
> How are the expert pythoneers dealing with config files?
...
> Any ideas?

How about writing them in Python?

I have no URL handy, but it would surprise me if there wasn't a lot written
about different techniques for doing this.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with config files what's the options

2005-02-23 Thread Tom Willis
On Wed, 23 Feb 2005 20:15:47 +, Phil Jackson
<[EMAIL PROTECTED]> wrote:
> Tom Willis <[EMAIL PROTECTED]> writes:
> 
> > How are the expert pythoneers dealing with config files?
> 
> You could use the cPickle module if you don't mind your config files
> being unreadable by humans. There is also the shlex module for more
> powerful config file needs:
> 
> http://docs.python.org/lib/module-shlex.html
> 
> While I'm replying to you, would you mind if I take the opportunity to
> ask you to stop top-posting?
> 
> Thanks,
> 
> Phil
> --
> http://mail.python.org/mailman/listinfo/python-list
> 




I guess. 

It's just so inconvenient in gmail. 

But anything for you. I'll try to try. :)


Thanks for the info.

-- 
Thomas G. Willis
http://paperbackmusic.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with config files what's the options

2005-02-23 Thread Phil Jackson
Tom Willis <[EMAIL PROTECTED]> writes:

> How are the expert pythoneers dealing with config files?

You could use the cPickle module if you don't mind your config files
being unreadable by humans. There is also the shlex module for more
powerful config file needs:

http://docs.python.org/lib/module-shlex.html

While I'm replying to you, would you mind if I take the opportunity to
ask you to stop top-posting?

Thanks,

Phil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with config files what's the options

2005-02-23 Thread Fuzzyman
Hello Tom,


Tom Willis wrote:
> How are the expert pythoneers dealing with config files?
>
> Is there anything similair to .net's config files or java's
.properties?
>

I'm not familiar with those config file formats - but ConfigObj
certainly makes handling config files easy. It uses the ini type layout
- which you're not so fond of, although it aloows lists for values as
well.

from configobj import ConfigObj
config = ConfigObj(filename)
value1 = config['section 1']['value 1']

See http://www.voidspace.org.uk/python/configobj.html

I'm interested in suggestions as to ways to take it forward. I've just
added unicode support (still experimental - wait for the next release)
and an interface for validation. Adding nested sections using
indentation will probably be the next major feature. (as well as
preserving user formatting when writing back files)

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

> A quick search on google didn't return anything that looked useful,
> and I almost would expect to see some module that would be for
dealing
> with config information.
>
> I can think of at least one way to do it, but I'm sure there are
> shortcomings I can't see yet, and I'd rather use something someone
> smarter than me has written.
>
> I see in the logging module that there's stuff to handle configs but
> seems kind of odd to have to import logging to get your config
> information
>
> Any ideas?
>
> have I used the word config enough in this message? :)
> 
> -- 
> Thomas G. Willis
> http://paperbackmusic.net

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with config files what's the options

2005-02-22 Thread Tom Willis
Thanks,

I'm not too keen on the ini layout. But it's good to know it's there.


On Wed, 23 Feb 2005 14:50:27 +1300, Tony Meyer <[EMAIL PROTECTED]> wrote:
> > How are the expert pythoneers dealing with config files?
> [...]
> 
> You can just "import ConfigParser", or look at the various alternatives:
> 
> 
> 
> =Tony.Meyer
> 
> 


-- 
Thomas G. Willis
http://paperbackmusic.net
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Dealing with config files what's the options

2005-02-22 Thread Tony Meyer
> How are the expert pythoneers dealing with config files?
[...]

You can just "import ConfigParser", or look at the various alternatives:



=Tony.Meyer

-- 
http://mail.python.org/mailman/listinfo/python-list