Index: pluginconf.py ================================================================== --- pluginconf.py +++ pluginconf.py @@ -1,12 +1,15 @@ -# encoding: UTF-8 +# encoding: utf-8 # api: python # type: extract -# category: io +# category: config # title: Plugin configuration # description: Read meta data, pyz/package contents, module locating -# version: 0.7.1 +# version: 0.7.3 +# state: stable +# classifiers: documentation +# license: PD # priority: core # docs: https://fossil.include-once.org/pluginspec/ # url: http://fossil.include-once.org/streamtuner2/wiki/plugin+meta+data # config: - # @@ -112,15 +115,15 @@ # Injectables # ‾‾‾‾‾‾‾‾‾‾‾ log_ERR = lambda *x: None # File lookup relation for get_data(), should name a top-level package. -module_base = "config" +module_base = "config" # equivalent PluginBase(package=…) # Package/module names for module_list() and plugin_meta() lookups. # All associated paths will be scanned for module/plugin basenames. -plugin_base = ["channels"] +plugin_base = ["channels"] # equivalent to `searchpath` in PluginBase # Resource retrieval # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Fetches file content from install path or from within PYZ @@ -310,13 +313,13 @@ if re.search("([=:])", s): return dict(rx.select_dict.findall(s)) else: return dict([(v, v) for v in rx.select_list.findall(s)]) -# normalize type:names to `str`, `bool`, `int`, `select`, `dict` +# normalize type:names to `str`, `text`, `bool`, `int`, `select`, `dict` config_opt_type_map = dict( - text="str", string="str", boolean="bool", checkbox="bool", integer="int", number="int", + longstr="text", string="str", boolean="bool", checkbox="bool", integer="int", number="int", choice="select", options="select", table="dict", array="dict" ) # Comment extraction regexps @@ -340,12 +343,12 @@ (?: " ([^"]*) " | ' ([^']*) ' # "quoted" or 'singl' values | ([^,]*) # or unquoted literals ) """, re.X) - select_dict = re.compile("(\w+)\s*[=:>]+\s*([^=,|:]+)") - select_list = re.compile("\s*([^,|;]+)\s*") + select_dict = re.compile(r"(\w+)\s*[=:>]+\s*([^=,|:]+)") + select_list = re.compile(r"\s*([^,|;]+)\s*") # ArgumentParser options conversion # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ @@ -379,17 +382,17 @@ def argparse_map(opt): if not ("arg" in opt and opt["name"] and opt["type"]): return {} # Extract --flag names - args = opt["arg"].split() + re.findall("-+\w+", opt["name"]) + args = opt["arg"].split() + re.findall(r"-+\w+", opt["name"]) # Prepare mapping options - typing = re.findall("bool|str|\[\]|const|false|true", opt["type"]) - naming = re.findall("\[\]", opt["name"]) - name = re.findall("(?+|==*|-+>|:=+)\s*", s.strip()) for s in re.split("\s*[|;,]\s*", _value) ]) + elif _type in ("table", "list"): + val = [ re.split(r"\s*[,;]\s*", s.strip()) for s in re.split(r"\s*[|]\s*", _value) ] + elif _type == "dict": + val = dict([ re.split(r"\s*(?:=>+|==*|-+>|:=+)\s*", s.strip(), 1) for s in re.split(r"\s*[|;,]\s*", _value) ]) else: val = str(_value) conf_options[_name] = val # Initial plugin activation status