diff options
author | Vasilii Chernov <vchernov@inr.ru> | 2016-03-02 10:26:13 +0100 |
---|---|---|
committer | Vasilii Chernov <vchernov@inr.ru> | 2016-03-02 10:26:13 +0100 |
commit | 8719b84a95805d109e21c20f05a0164315e1b38a (patch) | |
tree | 2cfbb6ce8af7e9a4acd9e2e085bef8a212bc1701 /pywrap/pcilib.py | |
parent | 8eca0564a1dd6aac125086a244687b4813a1fd86 (diff) | |
download | pcitool-8719b84a95805d109e21c20f05a0164315e1b38a.tar.gz pcitool-8719b84a95805d109e21c20f05a0164315e1b38a.tar.bz2 pcitool-8719b84a95805d109e21c20f05a0164315e1b38a.tar.xz pcitool-8719b84a95805d109e21c20f05a0164315e1b38a.zip |
Move scripts handing code from py.c to Python wrap
Diffstat (limited to 'pywrap/pcilib.py')
-rw-r--r-- | pywrap/pcilib.py | 38 |
1 files changed, 38 insertions, 0 deletions
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) |