389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409 | # Extremely crude version for Python and streamtuner2 plugin usage.
# But can fetch from different sources:
# · fn= to read from literal files, out of a .pyzip package
# · src= to extract from pre-read script code
# · module= utilizes pkgutil to read
# · frame= automatically extract comment header from caller
#
def plugin_meta(fn=None, src=None, module=None, frame=1, plugin_base="channels"):
# try via pkgutil first
if module:
fn = module
try: src = pkgutil.get_data(plugin_base, fn+".py")
except: pass # Notice in plugin_meta_extract() is sufficient
# get source directly from caller
elif not src and not fn:
module = inspect.getmodule(sys._getframe(frame))
fn = inspect.getsourcefile(module)
src = inspect.getcomments(module)
|
>
|
>
>
|
>
>
|
| 389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414 | # Extremely crude version for Python and streamtuner2 plugin usage.
# But can fetch from different sources:
# · fn= to read from literal files, out of a .pyzip package
# · src= to extract from pre-read script code
# · module= utilizes pkgutil to read
# · frame= automatically extract comment header from caller
#
plugin_base = ("channels", "plugins")
def plugin_meta(fn=None, src=None, module=None, frame=1):
# try via pkgutil first
if module:
fn = module
for base in plugin_base:
try:
src = pkgutil.get_data(base, fn+".py")
if src: break
except:
continue # plugin_meta_extract() will print a notice later
# get source directly from caller
elif not src and not fn:
module = inspect.getmodule(sys._getframe(frame))
fn = inspect.getsourcefile(module)
src = inspect.getcomments(module)
|