Skip to content

Commit 755e22d

Browse files
committed
iniinfo -parse ini commands in a better way
mdi commands with a comma in it (ie MSG, text) would not be interpeted properly
1 parent 5eed27a commit 755e22d

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

lib/python/common/iniinfo.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, ini=None):
1919
global LOG
2020
LOG = logger.getLogger(__name__)
2121
# Force the log level for this module only
22-
#LOG.setLevel(logger.DEBUG) # One of DEBUG, INFO, WARNING, ERROR, CRITICAL
22+
LOG.setLevel(logger.DEBUG) # One of DEBUG, INFO, WARNING, ERROR, CRITICAL
2323

2424
inipath = os.environ.get('INI_FILE_NAME', '/dev/null')
2525
self.LINUXCNC_IS_RUNNING = bool(inipath != '/dev/null')
@@ -571,7 +571,6 @@ def update(self):
571571
if self.parser.has_section('MDI_COMMAND_LIST'):
572572
try:
573573
for key in self.parser['MDI_COMMAND_LIST']:
574-
575574
# legacy way: list of repeat 'MDI_COMMAND=XXXX'
576575
# in this case order matters in the INI
577576
if key == 'MDI_COMMAND':
@@ -594,25 +593,50 @@ def update(self):
594593
self.MDI_COMMAND_LABEL_LIST.append(k)
595594
mdidatadict['label'] = k
596595
self.MDI_COMMAND_DICT[str(count)] = mdidatadict
597-
break
598596

599597
# new way: 'MDI_COMMAND_SSS = XXXX' (SSS being any string)
600598
# order of commands doesn't matter in the INI
599+
600+
# here are some samples, the last three are difficult
601+
# the third is invalid
602+
# MDI_COMMAND_MACRO1 = G53 G0 Z0;G53 G0 X0 Y0,Goto\nMachn\nZero
603+
# cmd: G53 G0 Z0;G53 G0 X0 Y0 label: Goto\nMachn\nZero
604+
605+
# MDI_COMMAND_MACRO2 = (MSG, macro 2);
606+
# cmd: (MSG, macro 2); label:
607+
608+
# MDI_COMMAND_MACRO3 = (MSG, macro 2)
609+
# cmd: (MSG label: macro 2)
610+
611+
# MDI_COMMAND_MACRO4 = (MSG, macro 2),test
612+
# cmd: (MSG, macro 2) label: test
613+
601614
else:
602615
self.MDI_COMMAND_LIST.append(None)
603616
self.MDI_COMMAND_LABEL_LIST.append(None)
604617
try:
605618
temp = self.INI.find("MDI_COMMAND_LIST",key)
606619
name = (key.replace('MDI_COMMAND_',''))
607620
mdidatadict = {}
608-
for num,k in enumerate(temp.split(',')):
609-
if num == 0:
610-
mdidatadict['cmd'] = k
611-
if len(temp.split(',')) <2:
612-
mdidatadict['label'] = None
613-
else:
614-
mdidatadict['label'] = k
621+
622+
# find the last colon in string or 0
623+
lastCmd = temp.rfind(';')
624+
#print('l ;:',lastCmd)
625+
if lastCmd == -1: lastCmd = 0
626+
627+
# find the last colon in string or use the string length
628+
lastComma = temp.rfind(',', lastCmd)
629+
#print('l comma:',lastComma,lastCmd)
630+
if lastComma == -1: lastComma = len(temp)
631+
632+
label = temp[lastComma+1:]
633+
cmd = temp[:lastComma]
634+
#print(temp,' cmd:',cmd,' label:',label)
635+
636+
mdidatadict['cmd'] = cmd
637+
mdidatadict['label'] = label
615638
self.MDI_COMMAND_DICT[name] = mdidatadict
639+
616640
except Exception as e:
617641
LOG.error('INI MDI command parse error:{}'.format(e))
618642
except Exception as e:

0 commit comments

Comments
 (0)