From aefbb2fe9345e855d67787bb38a76efd1227cef0 Mon Sep 17 00:00:00 2001 From: William McBrine Date: Fri, 9 Aug 2013 12:26:33 -0400 Subject: [PATCH] Allow for both select and checkbox entry types in settings. --- plugins/settings/buildhelp.py | 12 ++++++++++++ plugins/settings/help.txt | 10 +++++++++- plugins/settings/settings.py | 13 +++++++------ plugins/settings/templates/settings.tmpl | 13 ++++++++++--- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/plugins/settings/buildhelp.py b/plugins/settings/buildhelp.py index 56b2d39..95b5fec 100644 --- a/plugins/settings/buildhelp.py +++ b/plugins/settings/buildhelp.py @@ -6,6 +6,9 @@ SCRIPTDIR = os.path.dirname(__file__) help_list = {} title = '' settings_known = {} +mode = {} +options = {} +default = {} titlemode = True f = open(os.path.join(SCRIPTDIR, 'help.txt')) try: @@ -33,11 +36,20 @@ try: if section not in settings_known: settings_known[section] = [] settings_known[section].append(title) + elif value.lower() == 'mode': + mode[title] = data + elif value.lower() == 'options': + options[title] = data.split('/') else: help_list[title].append(line) + if value.lower() == 'default setting': + default[title] = data finally: f.close() ## Done building help list +plugins = [p for p in os.listdir(os.path.dirname(SCRIPTDIR)) + if not p.startswith(('__init__', 'togo', 'settings'))] +options['type'] = plugins def gethelp(): return help_list diff --git a/plugins/settings/help.txt b/plugins/settings/help.txt index 6e079ee..7f2918b 100644 --- a/plugins/settings/help.txt +++ b/plugins/settings/help.txt @@ -125,6 +125,7 @@ Available In: Server debug +Mode: checkbox Default Setting: False Valid Entries: True/False Required: No @@ -134,6 +135,7 @@ Available In: Server type +Mode: select Default Setting: None Valid Entries: video, music, photo, or any other valid plugin name. Required: Yes @@ -155,6 +157,7 @@ Available In: Shares force_alpha +Mode: checkbox Default Setting: False Valid Entries: True/False Required: No @@ -170,6 +173,7 @@ Available In: Shares force_ffmpeg +Mode: checkbox Default Setting: False Valid Entries: True/False Required: No @@ -184,6 +188,7 @@ Available In: Shares optres +Mode: checkbox Default Setting: False Valid Entries: True/False Required: No @@ -377,7 +382,7 @@ unless you wish to disable it. pyTivo defaults to True except when pyTivo uses acodec copy, in which case copyts is not needed, and a conflict could also occur if the source file has really corrupt sections. -Example Settings: True, False +Example Settings: True/False Available In: Tivos, HD_tivos, SD_tivos ffmpeg_pram @@ -504,6 +509,8 @@ Available In: Server zeroconf +Mode: select +Options: Auto/True/False Default Setting: Auto Valid Entries: True/False/Auto Required: No @@ -518,6 +525,7 @@ Available In: Server nosettings +Mode: checkbox Default Setting: False Valid Entries: True/False Required: No diff --git a/plugins/settings/settings.py b/plugins/settings/settings.py index 216ebee..a520609 100644 --- a/plugins/settings/settings.py +++ b/plugins/settings/settings.py @@ -74,11 +74,10 @@ class Settings(Plugin): shares_data.append((section, dict(config.config.items(section, raw=True)))) - plugins = [p for p in os.listdir(os.path.dirname(SCRIPTDIR)) - if not p.startswith(('__init__', 'togo', 'settings'))] t = Template(SETTINGS_TEMPLATE, filter=EncodeUnicode) - t.plugins = plugins + t.mode = buildhelp.mode + t.options = buildhelp.options t.container = handler.cname t.quote = quote t.server_data = dict(config.config.items('Server', raw=True)) @@ -100,10 +99,14 @@ class Settings(Plugin): def each_section(self, query, label, section): new_setting = new_value = ' ' + if config.config.has_section(section): + config.config.remove_section(section) + config.config.add_section(section) for key, value in query.items(): key = key.replace('opts.', '', 1) if key.startswith(label + '.'): _, option = key.split('.') + default = buildhelp.default.get(option, ' ') value = value[0] if not config.config.has_section(section): config.config.add_section(section) @@ -111,9 +114,7 @@ class Settings(Plugin): new_setting = value elif option == 'new__value': new_value = value - elif value == ' ': - config.config.remove_option(section, option) - else: + elif value not in (' ', default): config.config.set(section, option, value) if not(new_setting == ' ' and new_value == ' '): config.config.set(section, new_setting, new_value) diff --git a/plugins/settings/templates/settings.tmpl b/plugins/settings/templates/settings.tmpl index 4f1d48d..f614c0a 100644 --- a/plugins/settings/templates/settings.tmpl +++ b/plugins/settings/templates/settings.tmpl @@ -20,16 +20,23 @@ #else #set $value='' #end if - #if $key == 'type' + #if $mode.get($key, '') == 'select' + #elif $mode.get($key, '') == 'checkbox' + #else -- 2.11.4.GIT