bzr branch
http://suren.me/webbzr/alps/pcitool
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
1 |
from pcipywrap import * |
2 |
import os |
|
3 |
import sys |
|
4 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
5 |
class pcilib(pcipywrap): |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
6 |
def __init__(s, *args): |
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
7 |
pcipywrap.__init__(s, *args) |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
8 |
|
9 |
#load scripts
|
|
10 |
scripts_dir = os.environ.get('PCILIB_SCRIPTS_DIR') |
|
11 |
if scripts_dir: |
|
12 |
scripts_dir_abs = os.path.abspath(scripts_dir) |
|
13 |
if not scripts_dir_abs in sys.path: |
|
14 |
sys.path.append(scripts_dir_abs) |
|
15 |
||
16 |
s.__scipts = dict() |
|
17 |
for script in os.listdir(scripts_dir_abs): |
|
18 |
if script.endswith('.py'): |
|
19 |
script_module = os.path.splitext(script)[0] |
|
20 |
__import__(script_module) |
|
21 |
s.__scipts[script_module] = sys.modules[script_module] |
|
22 |
||
23 |
||
24 |
def get_scripts_list(s): |
|
25 |
scripts = [] |
|
26 |
for script in s.__scipts: |
|
27 |
curr_script = dict() |
|
28 |
curr_script['name'] = script |
|
29 |
if 'description' in dir(s.__scipts[script]): |
|
30 |
curr_script['description'] = s.__scipts[script].description |
|
346.1.37
by Vasilii Chernov
1. Pcipywrap: add persistent locking wrappings |
31 |
if 'run' in dir(s.__scipts[script]): |
32 |
curr_script['valid'] = True |
|
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
33 |
scripts.append(curr_script) |
34 |
return scripts |
|
35 |
||
36 |
||
37 |
def run_script(s, name, input_value): |
|
38 |
if not name in s.__scipts: |
|
39 |
raise Exception('Script ' + name +' has not loaded') |
|
40 |
return s.__scipts[name].run(s, input_value) |