8 if (len(sys.argv) != 3):
9 print "two arguments needed: template config file and changes" 11 templateFile = open(sys.argv[1])
12 changesFile = open(sys.argv[2])
14 for line
in changesFile:
15 if (re.match(
r'^#', line)):
17 sectionMatch = re.match(
r'\[(.+)\]', line)
19 currentSection = sectionMatch.group(1)
20 entryMatch = re.match(
r'(.+) += +(.+)', line)
22 tuples.append((currentSection, entryMatch.group(1), (entryMatch.group(2)).split(
" ")))
24 nbParams = len(tuples)
27 lengths = [1]*nbParams
28 for i
in range(len(tuples)):
30 lengths[i] = (len(tuples[i][2]))
31 if (lengths[i] > 1000):
32 print "Error: Only 1000 values swept allowed" 34 nbOfConfigs *= lengths[i]
41 indexes = [0]*nbParams
43 func(nbParams, 0, indexes, lengths, tuples, entries);
50 fileFormat = re.match(
r'(.+)\.conf', sys.argv[1])
53 stem = fileFormat.group(1)
55 print "The template file must have extension .conf" 59 content = templateFile.readlines();
60 for i
in range(len(content)):
61 if (re.match(
r'^#', content[i])):
63 sectionMatch = re.match(
r'\[(.+)\]', content[i])
65 currentSection = sectionMatch.group(1)
66 entryMatch = re.match(
r'(.+) += +(.+)', content[i])
68 currentParam = entryMatch.group(1)
69 for j
in range(nbParams):
70 if (entry[j] !=
None):
71 if (currentSection == entry[j][0]):
72 if (entry[j][1] == currentParam):
73 content[i] = entry[j][1] +
" = " + entry[j][2] +
"\n" 75 outfilename += format(counter,
'04d') +
"__" 76 for j
in range(nbParams):
77 outfilename += entry[j][1]
79 temp = float(entry[j][2])
80 outfilename +=
"{0:05f}".format(temp)
85 outfilename +=
".sconf" 86 with open(outfilename,
'w')
as outFile:
87 outFile.writelines(content)
88 with open(
"list",
"a")
as configslist:
89 configslist.write(outfilename +
"\n")
97 def func(nbParams, p, indexes, lengths, tuples, entries):
99 for i
in range(max(1, lengths[p])):
100 if p == (nbParams-1):
101 entryTuples = [
None]*nbParams;
102 for var
in range(nbParams):
103 if (len(tuples) > var):
104 entryTuples[var] = (tuples[var][0], tuples[var][1], tuples[var][2][indexes[var]])
106 for j
in range(nbParams):
107 entry.append(entryTuples[j])
109 entries.append(entryTuples)
111 func(nbParams, p+1, indexes, lengths, tuples, entries);
114 if __name__ ==
'__main__':
def func(nbParams, p, indexes, lengths, tuples, entries)