Skip to content
Snippets Groups Projects
Commit 4dc9082e authored by Marco Clemencic's avatar Marco Clemencic
Browse files

fixed handling of (multi line) strings and ';' in strings for .opts files

Fixes GAUDI-1179

See merge request !112
parents 9b6bb733 377ebf6d
No related branches found
No related tags found
No related merge requests found
from subprocess import Popen, PIPE
import os
def test():
'https://its.cern.ch/jira/browse/GAUDI-1179'
from os.path import dirname, join
from Gaudi.Configuration import importOptions, allConfigurables
opts = join(dirname(dirname(__file__)), 'pyjobopts', 'GAUDI-1179.opts')
importOptions(opts)
assert 'Dummy' in allConfigurables
assert allConfigurables['Dummy'].Value == 'a;b;c'
assert allConfigurables['Dummy'].MultiLineValue1 == '1;\n2;\n3\n4\n5'
assert allConfigurables['Dummy'].MultiLineValue2 == '\nhi\n'
Dummy.Value = "a;b;c";
Dummy.MultiLineValue1 = "1;
2;
3
4
5";
Dummy.MultiLineValue2 = "
hi
";
...@@ -161,6 +161,8 @@ class JobOptsParser: ...@@ -161,6 +161,8 @@ class JobOptsParser:
ifdef_skipping = False ifdef_skipping = False
ifdef_skipping_level = 0 ifdef_skipping_level = 0
in_string = False
f = open(_find_file(file)) f = open(_find_file(file))
l = f.readline() l = f.readline()
if l.startswith("#!"): if l.startswith("#!"):
...@@ -240,6 +242,32 @@ class JobOptsParser: ...@@ -240,6 +242,32 @@ class JobOptsParser:
raise ParserError("End Of File reached before end of multi-line comment") raise ParserError("End Of File reached before end of multi-line comment")
l += l1[m.end():] l += l1[m.end():]
# if we are in a multiline string, we add to the statement
# everything until the next '"'
if in_string:
string_end = l.find('"')
if string_end >= 0:
statement += l[:string_end+1]
l = l[string_end+1:]
in_string = False # the string ends here
else:
statement += l
l = ''
else: # check if we have a string
string_start = l.find('"')
if string_start >= 0:
string_end = l.find('"', string_start + 1)
if string_end >= 0:
# the string is opened and closed
statement += l[:string_end+1]
l = l[string_end+1:]
else:
# the string is only opened
statement += l
in_string = True
l = f.readline()
continue
if self.statement_sep in l: if self.statement_sep in l:
i = l.index(self.statement_sep) i = l.index(self.statement_sep)
statement += l[:i] statement += l[:i]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment