Mailinglist Archive: opensuse-buildservice (250 mails)

< Previous Next >
Re: [opensuse-buildservice] [osc] question using osc in python
  • From: "Jan-Simon Möller" <dl9pf@xxxxxx>
  • Date: Tue, 7 Apr 2009 13:23:04 +0200
  • Message-id: <200904071323.04752.dl9pf@xxxxxx>
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()

<now inserting new definition to conf.config['api_host_options'])

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@xxxxxxxxxxxx
For additional commands, e-mail: opensuse-buildservice+help@xxxxxxxxxxxx

< Previous Next >