-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdiffcmd_utils.py
43 lines (33 loc) · 1.12 KB
/
diffcmd_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#
# General utility functions to handle Diffcalc commands
#
from gda.jython.commands.GeneralCommands import alias
try:
import gda
GDA = True
except ImportError:
GDA = False
def alias_commands(global_namespace_dict):
"""Alias commands left in global_namespace_dict by previous import from
diffcalc.
This is the equivalent of diffcmd/ipython/magic_commands() for use
when IPython is not available
"""
gnd = global_namespace_dict
global GLOBAL_NAMESPACE_DICT
GLOBAL_NAMESPACE_DICT = gnd
print "Aliasing commands"
### Alias commands in namespace ###
commands = gnd['hkl_commands_for_help']
commands += gnd['ub_commands_for_help']
if not GDA: # TODO: encapsulation issue: this should be done outside this function!
commands.append(gnd['pos'])
commands.append(gnd['scan'])
aliased_names = []
for f in commands:
# Skip section headers like 'Motion'
if not hasattr(f, '__call__'):
continue
alias(f.__name__)
aliased_names.append(f.__name__)
print "Aliased commands: " + ' '.join(aliased_names)