Commit be9c6510 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by operator for beamline

Include preprocessor line directives around the inserted Exceptions SIP code

parent 995da2b5
......@@ -27,17 +27,27 @@ import shutil
logger = logging.getLogger(__file__)
raise_linenr = None
raise_exc = []
def checksipexc(ifname, inplace=False):
global raise_exc
global raise_linenr, raise_exc
lfname = ifname
sip_fname = '../../../common/sip/Exceptions.sip'
if lfname.startswith('/'):
sip_fname = os.path.realpath(sip_fname)
else:
lfname = os.path.join(os.curdir, lname)
if not raise_exc:
bfile = open('../../../common/sip/Exceptions.sip')
bfile = open(sip_fname)
in_raise_code = False
for l in bfile.readlines():
for i, l in enumerate(bfile.readlines()):
l = l.strip()
if l == '%RaiseCode':
in_raise_code = True
raise_linenr = i + 2
elif l == '%End':
in_raise_code = False
elif in_raise_code:
......@@ -59,6 +69,7 @@ def checksipexc(ifname, inplace=False):
state = Out
block = 0
linenr = 0
olinenr = 1
modified = False
ellipsis = '...'
......@@ -67,7 +78,7 @@ def checksipexc(ifname, inplace=False):
for line in ifile.readlines():
linenr += 1
new_state = state
l = line.strip()
......@@ -90,6 +101,7 @@ def checksipexc(ifname, inplace=False):
if InDefHandler not in [state, new_state] or had_exc_handler:
ofile.write(line.encode())
olinenr += line.count('\n')
else:
def_handler_code.append(line)
if new_state == Out:
......@@ -101,10 +113,15 @@ def checksipexc(ifname, inplace=False):
tok = handler_line.split(raise_unknown)
sep = '\n' + tok[0]
exc_line = sep.join(raise_exc)
handler_line = exc_line.join(tok)
sip_head = '#line %d "%s"\n' % (raise_linenr, sip_fname)
new_olinenr = olinenr + len(raise_exc) + 2
sip_tail = '#line %d "%s"\n\n' % (new_olinenr, lfname)
handler_line = sip_head + exc_line.join(tok) + sip_tail
ofile.write(handler_line.encode())
olinenr += handler_line.count('\n')
for handler_line in def_handler_code:
ofile.write(handler_line.encode())
olinenr += handler_line.count('\n')
modified = True
if new_state != state:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment