File: generate_testfiles.py

package info (click to toggle)
eprover 2.6%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 21,288 kB
  • sloc: ansic: 331,111; csh: 12,026; python: 10,178; awk: 5,825; makefile: 461; sh: 389
file content (117 lines) | stat: -rwxr-xr-x 2,635 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python2.7
# ----------------------------------
#
# generate_testfiles.py
#
# Usage: generate_testfiles.py <selector> <optionfile> <basefile>
#
# New generation script for test runs. Create all variants of basefile
# that match  selector in option file.
#
# Format for optionfile is:
#
# <comment>|<rule>*
# <comment> = "# .*\n"
# <rule> = <selector> <suffix> <options> "\n"
#
# where <selector> and <suffix> are arbitrary strings (but suffix
# should avoid troublesome characters) and <options> is a list of
# options to be appended to the options line.
#

import sys
import os
import re
import string


argc = len(sys.argv)
if argc!=4:
    raise RuntimeError, "Usage: generate_testfiles.py <selector> <optionfile> <basefile>"

white_space     = re.compile('\s+')
trail_space     = re.compile('\s*$')
lead_space      = re.compile('^\s*')
empty_line      = re.compile('^\s*$')
todo            = {}

select = re.compile(sys.argv[1])

p=open(sys.argv[2],'r')

l=p.readline()
while l:
    if l[0]=="#" or empty_line.match(l):
        l=p.readline()
        continue

    res = lead_space.sub("", l)
    res = trail_space.sub("", res)
    parts = white_space.split(res,2)
    if len(parts)!=3:
        raise RuntimeError, "Invalid syntax: '"+l+"'"
    if select.search(parts[0]):
        todo[parts[1]]=parts[2]    
    l=p.readline()

p.close()

p = open(sys.argv[3],'r')

execu = re.compile('^Executable: ')
logs  = re.compile('^Logfile: ')
probs = re.compile('^Problemdir: ')
args  = re.compile('^Arguments: ')
timel = re.compile('^Time limit: ')
incl  = re.compile('^Include: ')

rest  = ""
inc   = ""

l=p.readline()
while l:
    if execu.search(l):
        exe = l
    elif logs.search(l):
        log = l
    elif probs.search(l):
        prob = l
    elif args.search(l):
        arg = l
    elif timel.search(l):
        time = l
    elif incl.search(l):
        inc = inc+l
    else:
        rest = rest+l
        
    l=p.readline()

p.close()



arg = trail_space.sub("", arg)
log = trail_space.sub("", log)

logdesc = re.compile('^Logfile: +(/.+)*/protokoll_.+[0-9][0-9][0-9]$')

if not logdesc.search(log):
    raise RuntimeError, "Logfile name malformed!"

for i in todo.keys():
    newspecfile = sys.argv[3]+"_"+i
    if os.path.exists(newspecfile):
        print "File "+newspecfile+" exists, I'm leaving it untouched"
    else:
        print "Generating "+newspecfile 
        p=open(newspecfile, "w")
        p.write(exe)
        p.write(log+"_"+i+"\n")
        p.write(prob)
        p.write(arg+" "+todo[i]+"\n")
        p.write(time)
        p.write(inc)
        p.write(rest)
        p.close()