1 |
commit: c8e8855012e458322bacf094ac2e06ccac716cb0 |
2 |
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Oct 10 11:15:44 2015 +0000 |
4 |
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Oct 10 11:15:44 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=c8e88550 |
7 |
|
8 |
grs/Interpret.py: exec() is bad, get rid of it. |
9 |
|
10 |
grs/Interpret.py | 55 ++++++++++++++++++++++++++++++------------------------- |
11 |
1 file changed, 30 insertions(+), 25 deletions(-) |
12 |
|
13 |
diff --git a/grs/Interpret.py b/grs/Interpret.py |
14 |
index 12271d6..ea6d2e2 100644 |
15 |
--- a/grs/Interpret.py |
16 |
+++ b/grs/Interpret.py |
17 |
@@ -86,18 +86,23 @@ class Interpret(Daemon): |
18 |
time.sleep(2.0) |
19 |
|
20 |
|
21 |
- def semantic_action(_line, objs, num_objs, execstr): |
22 |
+ def semantic_action(_line, objs, nargs, func, *args): |
23 |
""" Execute the directive """ |
24 |
- if self.mock_run: |
25 |
- _lo.log(_line) |
26 |
- return |
27 |
- try: |
28 |
- if len(objs) < num_objs: |
29 |
- raise Exception('Number of objs for verb incorrect.') |
30 |
- exec(execstr) |
31 |
- except Exception as err: |
32 |
- _lo.log('Bad command: %s' % _line) |
33 |
- _lo.log('Exception throw: %s' % err) |
34 |
+ err = None |
35 |
+ if len(objs) == nargs: |
36 |
+ if self.mock_run: |
37 |
+ _lo.log(_line) |
38 |
+ return |
39 |
+ try: |
40 |
+ f(*args) |
41 |
+ except Exception as err: |
42 |
+ pass |
43 |
+ else: |
44 |
+ err = 'Number of parameters incorrect.' |
45 |
+ |
46 |
+ if err: |
47 |
+ _lo.log('Bad command: %s' % _line) |
48 |
+ _lo.log('Error message: %s' % err) |
49 |
_lo.log('SENDING SIGTERM\n') |
50 |
signalexit() |
51 |
|
52 |
@@ -213,44 +218,44 @@ class Interpret(Daemon): |
53 |
if verb == 'log': |
54 |
if objs[0] == 'stamp': |
55 |
objs[0] = '='*80 |
56 |
- semantic_action(_line, objs, 1, '_lo.log(\' \'.join(objs))') |
57 |
+ semantic_action(_line, objs, 1, _lo.log, ' '.join(objs)) |
58 |
elif verb == 'mount': |
59 |
- semantic_action(_line, objs, 0, '_md.mount_all()') |
60 |
+ semantic_action(_line, objs, 0, _md.mount_all) |
61 |
elif verb == 'unmount': |
62 |
- semantic_action(_line, objs, 0, '_md.umount_all()') |
63 |
+ semantic_action(_line, objs, 0, _md.umount_all) |
64 |
elif verb == 'populate': |
65 |
- semantic_action(_line, objs, 1, '_po.populate(cycle=int(objs[0]))') |
66 |
+ semantic_action(_line, objs, 1, _po.populate, int(objs[0])) |
67 |
elif verb == 'runscript': |
68 |
- semantic_action(_line, objs, 1, '_ru.runscript(objs[0])') |
69 |
+ semantic_action(_line, objs, 1, _ru.runscript, objs[0]) |
70 |
elif verb == 'pivot': |
71 |
- semantic_action(_line, objs, 1, '_pc.pivot(objs[0], _md)') |
72 |
+ semantic_action(_line, objs, 1, _pc.pivot, objs[0], _md) |
73 |
elif verb == 'kernel': |
74 |
- semantic_action(_line, objs, 0, '_ke.kernel()') |
75 |
+ semantic_action(_line, objs, 0, _ke.kernel) |
76 |
elif verb == 'tarit': |
77 |
# 'tarit' can either be just a verb, or a 'verb obj' pair. |
78 |
if len(objs): |
79 |
- semantic_action(_line, objs, 1, '_bi.tarit(objs[0])') |
80 |
+ semantic_action(_line, objs, 1, _bi.tarit, objs[0]) |
81 |
else: |
82 |
- semantic_action(_line, objs, 0, '_bi.tarit()') |
83 |
+ semantic_action(_line, objs, 0, _bi.tarit) |
84 |
medium_type = 'tarit' |
85 |
elif verb == 'isoit': |
86 |
# 'isoit' can either be just a verb, or a 'verb obj' pair. |
87 |
if len(objs): |
88 |
- semantic_action(_line, objs, 1, '_io.isoit(objs[1])') |
89 |
+ semantic_action(_line, objs, 1, _io.isoit, objs[0]) |
90 |
else: |
91 |
- semantic_action(_line, objs, 0, '_io.isoit()') |
92 |
+ semantic_action(_line, objs, 0, _io.isoit) |
93 |
medium_type = 'isoit' |
94 |
elif verb == 'hashit': |
95 |
if medium_type == 'tarit': |
96 |
- semantic_action(_line, objs, 0, '_bi.hashit()') |
97 |
+ semantic_action(_line, objs, 0, _bi.hashit) |
98 |
elif medium_type == 'isoit': |
99 |
- semantic_action(_line, objs, 0, '_io.hashit()') |
100 |
+ semantic_action(_line, objs, 0, _io.hashit) |
101 |
else: |
102 |
raise Exception('Unknown medium to hash.') |
103 |
else: |
104 |
_lo.log('Bad command: %s' % _line) |
105 |
_lo.log('Unknown verb: %s' % verb) |
106 |
- _lo.log('SENDING SIGTERM to pid = %d\n' % pid) |
107 |
+ _lo.log('SENDING SIGTERM\n') |
108 |
signalexit() |
109 |
|
110 |
stampit(progress) |