[opensuse-buildservice] [osc] question using osc in python
Hi!
If I create a new api definition in conf.config - how can I write it to disk ?
I start with:
from osc import conf, core
conf.get_config()
On 2009-04-07 08:15:47 +0200, Jan-Simon Möller wrote:
If I create a new api definition in conf.config - how can I write it to disk ?
I start with:
from osc import conf, core
conf.get_config()
conf.config['api_host_options']["http://foo.bar.org"]["http_headers"] = [] conf.config['api_host_options']["http://foo.bar.org"]["user"] = "spock" conf.config['api_host_options']["http://foo.bar.org"]["pass"] = "ncc1701d"
Probably I can't see the wood for the trees - how can i write stuff to .oscrc now ?
You have to do it via a OscConfigParser instance: cp = conf.get_configParser() cp.add_section('http://foo.bar.org') cp.set('http://foo.bar.org', 'user', 'foo') cp.set('http://foo.bar.org', 'password', 'bar') # fp is file like object, comments=True means that your comments in ~/.oscrc # be preserved cp.write(fp, comments=True) # finally rerun conf.get_config(*args) While writing this I realized that this procedure is quite ugly. So either we add an add_user(section, user, pass) method to the conf module or we might turn the whole config stuff into an object which does all the magic automatically (e.g. confobj['someoption'] = 'val1' stores it in the ~/.oscrc too). Marcus -- To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-buildservice+help@opensuse.org
Am Tuesday 07 April 2009 12:22:40 schrieb Marcus Hüwe:
On 2009-04-07 08:15:47 +0200, Jan-Simon Möller wrote:
If I create a new api definition in conf.config - how can I write it to disk ?
I start with:
from osc import conf, core
conf.get_config()
conf.config['api_host_options']["http://foo.bar.org"]["http_headers"] = [] conf.config['api_host_options']["http://foo.bar.org"]["user"] = "spock" conf.config['api_host_options']["http://foo.bar.org"]["pass"] = "ncc1701d"
Probably I can't see the wood for the trees - how can i write stuff to .oscrc now ?
You have to do it via a OscConfigParser instance:
cp = conf.get_configParser() cp.add_section('http://foo.bar.org') cp.set('http://foo.bar.org', 'user', 'foo') cp.set('http://foo.bar.org', 'password', 'bar')
# fp is file like object, comments=True means that your comments in ~/.oscrc # be preserved cp.write(fp, comments=True)
# finally rerun conf.get_config(*args)
While writing this I realized that this procedure is quite ugly. So either we add an add_user(section, user, pass) method to the conf module or we might turn the whole config stuff into an object which does all the magic automatically (e.g. confobj['someoption'] = 'val1' stores it in the ~/.oscrc too).
A simpler procedure would be much appreciated. The usage of ConfigParser will to it here atm. Best, Jan-Simon -- To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-buildservice+help@opensuse.org
participants (2)
-
Jan-Simon Möller
-
Marcus Hüwe