| 1 |
import sys,os |
| 2 |
import sqlite3 |
| 3 |
|
| 4 |
def run(): |
| 5 |
""" Generate TestCases from cmdfile according to the pattern in patternfile""" |
| 6 |
|
| 7 |
impheader = """import sys |
| 8 |
import conv_base |
| 9 |
|
| 10 |
""" |
| 11 |
|
| 12 |
pattern="""class Test%d(conv_base.%sCase): |
| 13 |
@classmethod |
| 14 |
def setUpClass(cls): |
| 15 |
cls.obsmode="%s" |
| 16 |
cls.spectrum="%s" |
| 17 |
cls.fname="C%s_%s.fits" |
| 18 |
cls.setup2()\n\n""" |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
outfiles = {'None':'sponly/sponly.py', |
| 23 |
'acs':'acs/acs.py', |
| 24 |
'nicmos':'nicmos/nicmos.py', |
| 25 |
'stis':'stis/stis.py', |
| 26 |
'wfc3,ir':'wfc3_ir/wfc3_ir.py', |
| 27 |
'wfc3,uvis1':'wfc3_uvis1/wfc3_uvis1.py', |
| 28 |
'wfc3,uvis2':'wfc3_uvis2/wfc3_uvis2.py', |
| 29 |
'oops':'oops/oops.py' |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
casetype = {"None": "Spec", |
| 34 |
"nicmos": "Therm", |
| 35 |
"wfc3,ir": "Therm"} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
db = sqlite3.connect("/ssbwebv1/data1/pandokia/old/pdk/c3/db/pdk.db") |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
setdirs(outfiles) |
| 44 |
for k in outfiles: |
| 45 |
outfiles[k] = open(outfiles[k], 'w') |
| 46 |
outfiles[k].write(impheader) |
| 47 |
|
| 48 |
count=0 |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
c = db.execute(""" SELECT DISTINCT obsmode, spectrum |
| 58 |
FROM synpysyn |
| 59 |
WHERE spectrum != "None" |
| 60 |
ORDER BY obsmode""") |
| 61 |
|
| 62 |
|
| 63 |
for x in c: |
| 64 |
obsmode, spectrum = x |
| 65 |
count+=1 |
| 66 |
outkey=pickname(obsmode,outfiles) |
| 67 |
defn=pattern%(count, |
| 68 |
casetype.get(outkey, "Comm"), |
| 69 |
obsmode,spectrum,count,"%s") |
| 70 |
outfiles[outkey].write(defn) |
| 71 |
|
| 72 |
|
| 73 |
for k in outfiles: |
| 74 |
outfiles[k].close() |
| 75 |
|
| 76 |
def setdirs(outfiles): |
| 77 |
"""Create the directories if need be""" |
| 78 |
for k in outfiles: |
| 79 |
fname=outfiles[k] |
| 80 |
dname= os.path.dirname(fname) |
| 81 |
if not os.path.isdir(dname): |
| 82 |
os.mkdir(dname) |
| 83 |
|
| 84 |
def pickname(obsmode, outfiles): |
| 85 |
"""The obsmode string starts with one of the keys of outfiles. |
| 86 |
Pick the right one and return it.""" |
| 87 |
|
| 88 |
for k in outfiles: |
| 89 |
if obsmode.startswith(k): |
| 90 |
return k |
| 91 |
|
| 92 |
return 'oops' |
| 93 |
|
| 94 |
if __name__ == '__main__': |
| 95 |
run() |
| 96 |
|