~hopem/charms/precise/glance/trunk

« back to all changes in this revision

Viewing changes to hooks/lib/openstack-common

  • Committer: Mark Mims
  • Date: 2013-03-12 19:35:01 UTC
  • mfrom: (30.2.1 glance)
  • Revision ID: mark.mims@canonical.com-20130312193501-zf4ng540qgiknos1
mergingĀ lp:~gandelman-a/charms/precise/glance/cfgparser

Show diffs side-by-side

added added

removed removed

Lines of Context:
314
314
  echo "$found"
315
315
  return 0
316
316
}
 
317
 
 
318
function cfg_set_or_update() {
 
319
  local key="$1"
 
320
  local value="$2"
 
321
  local file="$3"
 
322
  local section="$4"
 
323
  [[ -z "$section" ]] && section="DEFAULT"
 
324
  [[ -z $key ]] && juju-log "ERROR: cfg_set_or_update(): value $value missing key" \
 
325
        && exit 1
 
326
  [[ -z $value ]] && juju-log "ERROR: cfg_set_or_update(): key $key missing value" \
 
327
        && exit 1
 
328
  [[ ! -e $file ]] && juju-log "ERROR: cfg_set_or_update(): File not found $file" \
 
329
        && exit 1
 
330
 
 
331
  python -c "
 
332
import ConfigParser
 
333
config = ConfigParser.RawConfigParser()
 
334
config.read('$file')
 
335
if '$section' != 'DEFAULT' and not config.has_section('$section'):
 
336
    config.add_section('$section')
 
337
config.set('$section', '$key', '$value')
 
338
with open('$file', 'wb') as conf_out:
 
339
    config.write(conf_out)
 
340
"
 
341
  juju-log "Updated config $file, $key = $value in section $section."
 
342
}