| •1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
""" |
| 6 |
Extensive documentation for the Python language is available at |
| 7 |
http://www.python.org. |
| 8 |
""" |
| 9 |
|
| 10 |
import os, sys, time, getopt, tempfile |
| 11 |
import MyFile |
| 12 |
import MatchRecord |
| 13 |
|
| 14 |
class AtacFile: |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
def __init__( self, runName): |
| 20 |
"You must supply a atac file called runName.atac." |
| 21 |
self.runName = runName |
| 22 |
self.comments = [] |
| 23 |
self.metacommands = [] |
| 24 |
self.globals = {} |
| 25 |
self.tableformat = {} |
| 26 |
self.tabledata = {} |
| 27 |
self.matches = MyFile.myfile() |
| 28 |
self.runs = MyFile.myfile() |
| 29 |
|
| 30 |
fp = open(runName,"r") |
| 31 |
for line in fp: |
| 32 |
self.atac_file_parse_line(line) |
| 33 |
|
| 34 |
def atac_file_parse_line( self, line): |
| 35 |
line = line.strip() |
| 36 |
if(not line): |
| 37 |
return |
| 38 |
|
| 39 |
linetype = line[0] |
| 40 |
if(linetype == '#'): |
| 41 |
|
| 42 |
self.comments.append(line) |
| 43 |
return |
| 44 |
elif(linetype == '!'): |
| 45 |
self.metacommands.append(line) |
| 46 |
return |
| 47 |
elif(linetype == '/'): |
| 48 |
|
| 49 |
(key,value) = line[1:].split('=') |
| 50 |
self.globals[key] = value.strip() |
| 51 |
return |
| 52 |
elif(linetype == '@'): |
| 53 |
list = line[1:].split() |
| 54 |
name = list[0] |
| 55 |
self.tableformat[name] = list[1:] |
| 56 |
self.tabledata[name] = [] |
| 57 |
return |
| 58 |
elif(linetype == 'M'): |
| 59 |
fields = line.split() |
| 60 |
if(fields[1] == 'r'): |
| •61 |
print(line, file=self.runs) |
| 62 |
else: |
| •63 |
print(line, file=self.matches) |
| 64 |
return |
| 65 |
elif(line == ''): |
| 66 |
pass |
| 67 |
else: |
| •68 |
print("The offending line:", file=sys.stderr) |
| 69 |
print(line, file=sys.stderr) |
| 70 |
assert(0) |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
def checkpoint(self, filename): |
| 75 |
self.globals["modificationDate"] = time.asctime() |
| 76 |
fp = open(filename,"w") |
| 77 |
for line in self.metacommands: |
| •78 |
print(line, file=fp) |
| 79 |
for line in self.comments: |
| •80 |
print(line, file=fp) |
| 81 |
|
| 82 |
list = [] |
| 83 |
for key in self.globals: |
| 84 |
list.append("/" + key + "=" + str(self.globals[key])) |
| 85 |
list.sort() |
| 86 |
for line in list: |
| •87 |
print(line, file=fp) |
| 88 |
self.matches.seek(0) |
| 89 |
for line in self.matches: |
| •90 |
fp.write(line.decode("utf-8")) |
| 91 |
self.matches.seek(0) |
| 92 |
self.runs.seek(0) |
| 93 |
for line in self.runs: |
| 94 |
fp.write(line) |
| 95 |
self.runs.seek(0) |
| 96 |
fp.close() |