File tree Expand file tree Collapse file tree 2 files changed +24
-9
lines changed Expand file tree Collapse file tree 2 files changed +24
-9
lines changed Original file line number Diff line number Diff line change 1
1
from labgrid .driver import BareboxDriver
2
-
2
+ from labgridhelper . dict import split_to_dict
3
3
4
4
def get_commands (command ):
5
5
"""Returns the available commands of a running Barebox bootloader
@@ -26,11 +26,4 @@ def get_globals(command):
26
26
"""
27
27
assert isinstance (command , BareboxDriver )
28
28
out = command .run_check ("global" )
29
- out = map (lambda x : x [2 :], out )
30
- global_variables = {}
31
- for line in out :
32
- sep = line .index (":" )
33
- key = line [:sep ]
34
- value = line [sep + 2 :]
35
- global_variables [key ] = value
36
- return global_variables
29
+ return split_to_dict (out , delimiter = ":" , strip_chars = "* " )
Original file line number Diff line number Diff line change
1
+ def split_to_dict (command_output , delimiter = "=" , strip_chars = "" ):
2
+ '''
3
+ returns a dictionary that splits the content of the command_output.
4
+ The key is the part before and the value is the part after the first
5
+ delimiter. Optional chars can be specified to be stript from key and
6
+ value.
7
+ Args:
8
+ command_output: output to split into dict
9
+ delimiter: character that seperates key and value
10
+ strip_chars: characters to strip from key and value
11
+ Returns:
12
+ output_dict: dictionary that contains the pairs of key and value
13
+ '''
14
+ output_dict = {}
15
+ for line in command_output :
16
+ try :
17
+ if delimiter in line : # lines without a delimiter are ignored
18
+ (key , value ) = line .split (delimiter , 1 )
19
+ output_dict [key .strip (strip_chars )] = value .strip (strip_chars )
20
+ except ValueError :
21
+ pass
22
+ return output_dict
You can’t perform that action at this time.
0 commit comments