From 1c8c30cafcc623980fb6f0f02a7bd52940fb5d4b Mon Sep 17 00:00:00 2001 From: Stephan Raue Date: Fri, 22 Apr 2011 14:30:04 +0200 Subject: [PATCH] SABnzbd: fix ini_tool thanks to thansen, fix settingsdialog Signed-off-by: Stephan Raue --- .../SABnzbd/source/bin/ini_tool | 35 +++++++++++++------ .../SABnzbd/source/resources/settings.xml | 4 +-- .../downloadmanager/SABnzbd/source/start.sh | 3 +- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/packages/addons/downloadmanager/SABnzbd/source/bin/ini_tool b/packages/addons/downloadmanager/SABnzbd/source/bin/ini_tool index bf350d9f16..ab663574af 100755 --- a/packages/addons/downloadmanager/SABnzbd/source/bin/ini_tool +++ b/packages/addons/downloadmanager/SABnzbd/source/bin/ini_tool @@ -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 - config.write() + 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) \ No newline at end of file diff --git a/packages/addons/downloadmanager/SABnzbd/source/resources/settings.xml b/packages/addons/downloadmanager/SABnzbd/source/resources/settings.xml index 4200202909..8ee2bb0ab2 100644 --- a/packages/addons/downloadmanager/SABnzbd/source/resources/settings.xml +++ b/packages/addons/downloadmanager/SABnzbd/source/resources/settings.xml @@ -5,8 +5,8 @@ - - + + diff --git a/packages/addons/downloadmanager/SABnzbd/source/start.sh b/packages/addons/downloadmanager/SABnzbd/source/start.sh index 3ebe911e95..4d3a827875 100755 --- a/packages/addons/downloadmanager/SABnzbd/source/start.sh +++ b/packages/addons/downloadmanager/SABnzbd/source/start.sh @@ -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" }