-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_parser.py
More file actions
37 lines (30 loc) · 1.2 KB
/
command_parser.py
File metadata and controls
37 lines (30 loc) · 1.2 KB
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
import re
from plot_utils import PlotBundle
from error_utils import ColumnErrorBundle
def command_parse(command_list):
plot_columns = []
for dataset_tuple in command_list:
command, dataset, ncols = dataset_tuple
columns = command.split()
for i, char in enumerate(columns):
if '-' in char:
lims = char.split('-')
first = int(lims[0])
second = int(lims[1])
step = 1
if first > second:
step = -1
second -= 2
columns[i:i+1] = ' '.join(map(str,range(first, second+1, step))).split()
try:
index = columns.index('|')
columns.pop(index)
except ValueError:
index = len(columns)
if len(columns) < 2:
return ColumnErrorBundle(ierr=2)
for col in columns:
if int(col) > ncols:
return ColumnErrorBundle(column=col, dataset=dataset, ierr=1)
plot_columns += [PlotBundle(dataset, int(columns[-1]), int(col)) if i < index else PlotBundle(dataset, int(columns[-1]), int(col), True) for i, col in enumerate(columns[:-1])]
return plot_columns