1 | #! /usr/bin/env python |
---|
2 | # |
---|
3 | # file sfd2readall.py |
---|
4 | # ============== |
---|
5 | # |
---|
6 | # version 1, 2-Jul-2007 |
---|
7 | # |
---|
8 | # Takes sfd file and creates read commands for each line of it |
---|
9 | # K. Stammler, 2-Jul-2007 |
---|
10 | |
---|
11 | import sys |
---|
12 | import os |
---|
13 | import datetime |
---|
14 | |
---|
15 | #------------------------------------------------------------------------------- |
---|
16 | |
---|
17 | |
---|
18 | |
---|
19 | def Sh2Datetime( shtime ): |
---|
20 | """Convert SH time string to datetime. |
---|
21 | |
---|
22 | shtime: SH time string |
---|
23 | """ |
---|
24 | |
---|
25 | x = os.popen( "$SH_UTIL/timename time_to_int "+shtime ).readlines() |
---|
26 | if len(x) < 1: |
---|
27 | print 'Sh2Datetime failed on', '>', shtime, '<' |
---|
28 | return None |
---|
29 | y = x[0].rstrip() |
---|
30 | res = y.split( " " ) |
---|
31 | if (len(res) < 7): |
---|
32 | print "Syntax error in shtime:", shtime |
---|
33 | sys.exit() |
---|
34 | year, month, day, hour, minute, sec, ms = res |
---|
35 | s_time = datetime.datetime( int(year), int(month), int(day), int(hour), \ |
---|
36 | int(minute), int(sec), int(ms)*1000 ) |
---|
37 | return s_time |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | #------------------------------------------------------------------------------- |
---|
42 | |
---|
43 | # check for parameters |
---|
44 | if len(sys.argv) < 3: |
---|
45 | print "Usage: %s <sfdfile> <readdir>" % sys.argv[0] |
---|
46 | sys.exit() |
---|
47 | |
---|
48 | sfdfile = sys.argv[1] |
---|
49 | readdir = sys.argv[2] |
---|
50 | |
---|
51 | if not os.path.exists(sfdfile): |
---|
52 | print "file", sfdfile, "not found abort" |
---|
53 | sys.exit() |
---|
54 | |
---|
55 | print "nr" |
---|
56 | |
---|
57 | sfd = open( sfdfile ) |
---|
58 | for line in sfd.readlines(): |
---|
59 | idx = line.find("s>") |
---|
60 | stream = line[idx+2:].split()[0] |
---|
61 | idx = line.find("b>") |
---|
62 | stime = line[idx+2:].split()[0] |
---|
63 | idx = line.find("e>") |
---|
64 | etime = line[idx+2:].split()[0] |
---|
65 | timewdw = Sh2Datetime( etime ) - Sh2Datetime( stime ) |
---|
66 | rwdw = float(timewdw.seconds) + float(timewdw.microseconds)/1000000.0 |
---|
67 | s = stream.split("-") |
---|
68 | if len(s) != 3: continue |
---|
69 | print "reads/noswap", readdir, stime, rwdw, s[0], s[2], s[1] |
---|
70 | |
---|
71 | sfd.close() |
---|
72 | |
---|
73 | print "rd" |
---|
74 | print "rd" |
---|
75 | print "return" |
---|
76 | |
---|