From 8719b84a95805d109e21c20f05a0164315e1b38a Mon Sep 17 00:00:00 2001 From: Vasilii Chernov Date: Wed, 2 Mar 2016 10:26:13 +0100 Subject: Move scripts handing code from py.c to Python wrap --- pywrap/pcilib.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 pywrap/pcilib.py (limited to 'pywrap/pcilib.py') diff --git a/pywrap/pcilib.py b/pywrap/pcilib.py new file mode 100644 index 0000000..7696524 --- /dev/null +++ b/pywrap/pcilib.py @@ -0,0 +1,38 @@ +from pcipywrap import * +import os +import sys + +class Pcilib(Pcipywrap): + def __init__(s, *args): + Pcipywrap.__init__(s, *args) + + #load scripts + scripts_dir = os.environ.get('PCILIB_SCRIPTS_DIR') + if scripts_dir: + scripts_dir_abs = os.path.abspath(scripts_dir) + if not scripts_dir_abs in sys.path: + sys.path.append(scripts_dir_abs) + + s.__scipts = dict() + for script in os.listdir(scripts_dir_abs): + if script.endswith('.py'): + script_module = os.path.splitext(script)[0] + __import__(script_module) + s.__scipts[script_module] = sys.modules[script_module] + + + def get_scripts_list(s): + scripts = [] + for script in s.__scipts: + curr_script = dict() + curr_script['name'] = script + if 'description' in dir(s.__scipts[script]): + curr_script['description'] = s.__scipts[script].description + scripts.append(curr_script) + return scripts + + + def run_script(s, name, input_value): + if not name in s.__scipts: + raise Exception('Script ' + name +' has not loaded') + return s.__scipts[name].run(s, input_value) -- cgit v1.2.3