368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
| for field in rx.keyval.findall(src):
meta[field[0].replace("-", "_").lower()] = field[1].strip()
meta["config"] = plugin_meta_config(meta.get("config") or "")
return PluginMeta(meta)
# Dict wrapper
# ‾‾‾‾‾‾‾‾‾‾‾‾
class PluginMeta(dict):
"""
Plugin meta data, as dictionary with alternative .property access.
Returned for each `plugin_meta()` result, and config: options.
Non-existent .fieldnames just resolve to `""`.
"""
def __getattr__(self, key):
""" Return [key] for .property access, else None """
return self.get(key, "")
def __hasattr__(self, key):
""" Return [key] for .property access, else None """
return key in self
# Unpack config: structures
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
def plugin_meta_config(src):
"""
Further breaks up the meta['config'] descriptor.
|
|
|
|
|
>
>
|
|
>
>
|
>
>
>
>
>
>
>
>
>
|
>
| 368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
| for field in rx.keyval.findall(src):
meta[field[0].replace("-", "_").lower()] = field[1].strip()
meta["config"] = plugin_meta_config(meta.get("config") or "")
return PluginMeta(meta)
# Dict/list wrappers
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
class PluginMeta(dict):
"""
Plugin meta data, as dictionary with alternative .property access.
Returned for each `plugin_meta()` result, and config: options.
Non-existent .fieldnames just resolve to `""`.
"""
def __getattr__(self, key, default=""):
""" Return [key] for .property access, else `""`. """
if key == "config":
default = OptionList()
return self.get(key, default)
def __setattr__(self, key, val):
""" Shouldn't really have this, but for parity. """
self[key] = val
class OptionList(list):
"""
List of config: options, with additional .name access (name= from option entry).
"""
def __getattr__(self, key):
""" Returns list entry with name= equaling .name access """
for opt in self:
if opt.name == key:
return opt
raise KeyError("No option name '%s' in config list" % key)
# Unpack config: structures
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
def plugin_meta_config(src):
"""
Further breaks up the meta['config'] descriptor.
|
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
| opt[field[0]] = (field[1] or field[2] or field[3] or "").strip()
# normalize type
opt["type"] = config_opt_type_map.get(opt["type"], opt["type"] or "str")
# preparse select:
if opt.get("select"):
opt["select"] = config_opt_parse_select(opt.get("select", ""))
config.append(opt)
return config
# split up `select: 1=on|2=more|3=title` or `select: foo|bar|lists`
def config_opt_parse_select(select):
""" unpack 1|2|3 or title=lists """
if re.search("([=:])", select):
return dict(rx.select_dict.findall(select))
#else:
|
|
>
| 439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
| opt[field[0]] = (field[1] or field[2] or field[3] or "").strip()
# normalize type
opt["type"] = config_opt_type_map.get(opt["type"], opt["type"] or "str")
# preparse select:
if opt.get("select"):
opt["select"] = config_opt_parse_select(opt.get("select", ""))
config.append(opt)
return OptionList(PluginMeta(opt) for opt in config)
# split up `select: 1=on|2=more|3=title` or `select: foo|bar|lists`
def config_opt_parse_select(select):
""" unpack 1|2|3 or title=lists """
if re.search("([=:])", select):
return dict(rx.select_dict.findall(select))
#else:
|