SABnzbd: fix ini_tool thanks to thansen, fix settingsdialog

Signed-off-by: Stephan Raue <stephan@openelec.tv>
This commit is contained in:
Stephan Raue 2011-04-22 14:30:04 +02:00
parent 16d499bcfb
commit 1c8c30cafc
3 changed files with 28 additions and 14 deletions

View File

@ -3,16 +3,17 @@
from configobj import ConfigObj
import sys
import os
import string
python_major = sys.version_info[0]
python_minor = sys.version_info[1]
prog="ini_tool"
prog="configobj_ini_tool"
description="""Read/Write config files.
Examples:
%(prog)s --file config.ini --action read --section "general" --option username
%(prog)s --file config.ini --action write --section "general" --option username --value foo""" % {'prog':prog}
%(prog)s --file config.ini --action read --option [section:]username
%(prog)s --file config.ini --action write --option [section:]username --value foo""" % {'prog':prog}
def option_required_error(option):
parser.print_usage()
@ -30,7 +31,6 @@ if python_major > 2 or (python_major == 2 and python_minor >= 7):
parser.add_argument('--file', help='file to read/write to/from', required=True)
parser.add_argument('--action', help='read|write', required=True)
parser.add_argument('--section', help='the config section', required=True)
parser.add_argument('--option', help='the option key', required=True)
parser.add_argument('--value', help='value to store in the given option (only for write action)')
@ -46,7 +46,6 @@ else:
parser.add_option('--file', help='file to read/write to/from')
parser.add_option('--action', help='read|write')
parser.add_option('--section', help='the config section')
parser.add_option('--option', help='the option key')
parser.add_option('--value', help='value to store in the given option (only for write action)')
@ -56,8 +55,6 @@ else:
option_required_error("--file")
if not options.action:
option_required_error("--action")
if not options.section:
option_required_error("--section")
if not options.option:
option_required_error("--option")
@ -72,11 +69,29 @@ if options.action == "read" and not os.path.isfile(options.file):
exit(2)
config = ConfigObj(options.file)
keys = string.split(options.option, ":")
key_len = len(keys)
current_section = config
if options.action == 'read':
print config[options.section][options.option]
i = 1
for key in keys:
if i == key_len:
print current_section[key]
exit(0)
else:
current_section = current_section[key]
i += 1
elif options.action == 'write':
config[options.section][options.option] = options.value
i = 1
for key in keys:
if i == key_len:
current_section[key] = options.value
elif key not in current_section:
current_section[key] = {}
current_section = current_section[key]
i += 1
config.write()
else:
exit(1)

View File

@ -5,8 +5,8 @@
<category label="1000">
<setting label="1010" type="lsep"/>
<setting type="sep" />
<setting id="SABNZBD_USER" type="text" label="1022" default="openelec" enable="eq(-1,true)"/>
<setting id="SABNZBD_PWD" type="text" label="1023" default="openelec" enable="eq(-2,true)"/>
<setting id="SABNZBD_USER" type="text" label="1022" default="openelec"/>
<setting id="SABNZBD_PWD" type="text" label="1023" default="openelec"/>
<setting label="2010" type="lsep"/>
<setting type="sep" />

View File

@ -37,8 +37,7 @@ SABNZBD_WEBCOLOR2="gold"
write_ini() {
python bin/ini_tool --action=write \
--file=$SABNZBD_HOME/sabnzbd.ini \
--section="$1" \
--option="$2" \
--option="$1:$2" \
--value="$3"
}