31from optparse
import OptionParser
34import igwn_segments
as segments
40from lal
import git_version
43__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
44__version__ =
"git id %s" % git_version.id
45__date__ = git_version.date
58 parser = OptionParser(
60 usage =
"usage: %prog [options]\n\nExample:\n\tls *.xml | %prog"
62 parser.add_option(
"-a",
"--include-all", action =
"store_true", help =
"Include all files in output. Unparseable file names are assigned empty metadata.")
63 parser.add_option(
"-f",
"--force", action =
"store_true", help =
"Ignore errors. Unparseable file names are removed from the output. This has no effect if --include-all is given.")
64 parser.add_option(
"-i",
"--input", metavar=
"filename", help=
"Read input from this file (default = stdin).")
65 parser.add_option(
"-o",
"--output", metavar=
"filename", help=
"Write output to this file (default = stdout).")
66 parser.add_option(
"-v",
"--verbose", action=
"store_true", help=
"Be verbose.")
67 return parser.parse_args()[0]
92if options.input
is not None:
93 src = open(options.input)
97if options.output
is not None:
98 dst = open(options.output,
"w")
108seglists = segments.segmentlistdict()
117 path, filename = os.path.split(line.strip())
118 url =
"file://localhost%s" % os.path.abspath(os.path.join(path, filename))
120 cache_entry = CacheEntry.from_T050017(url)
121 except ValueError
as e:
122 if options.include_all:
123 cache_entry =
CacheEntry(
None,
None,
None, url)
128 print(str(cache_entry), file=dst)
130 if cache_entry.segment
is not None:
131 seglists |= cache_entry.segmentlistdict.coalesce()
140 print(
"Size of cache: %d URLs" % path_count, file=sys.stderr)
141 for instrument, seglist
in list(seglists.items()):
142 ext = seglist.extent()
144 print(
"Interval spanned by %s: %s (%s s total, %.4g%% duty cycle)" % (instrument, str(ext), str(dur), 100.0 * float(dur) / float(abs(ext))), file=sys.stderr)
145 span = seglists.union(seglists)
148 print(
"Interval spanned by union: %s (%s s total, %.4g%% duty cycle)" % (str(ext), str(dur), 100.0 * float(dur) / float(abs(ext))), file=sys.stderr)
A Python object representing one line in a LAL cache file.