30 from optparse
import OptionParser
33 from ligo
import segments
39 from lal
import git_version
42 __author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
43 __version__ =
"git id %s" % git_version.id
44 __date__ = git_version.date
57 parser = OptionParser(
59 usage =
"usage: %prog [options]\n\nExample:\n\tls *.xml | %prog"
61 parser.add_option(
"-a",
"--include-all", action =
"store_true", help =
"Include all files in output. Unparseable file names are assigned empty metadata.")
62 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.")
63 parser.add_option(
"-i",
"--input", metavar=
"filename", help=
"Read input from this file (default = stdin).")
64 parser.add_option(
"-o",
"--output", metavar=
"filename", help=
"Write output to this file (default = stdout).")
65 parser.add_option(
"-v",
"--verbose", action=
"store_true", help=
"Be verbose.")
66 return parser.parse_args()[0]
91 if options.input
is not None:
92 src = open(options.input)
96 if options.output
is not None:
97 dst = open(options.output,
"w")
107 seglists = segments.segmentlistdict()
116 path, filename = os.path.split(line.strip())
117 url =
"file://localhost%s" % os.path.abspath(os.path.join(path, filename))
119 cache_entry = CacheEntry.from_T050017(url)
120 except ValueError
as e:
121 if options.include_all:
122 cache_entry =
CacheEntry(
None,
None,
None, url)
127 print(str(cache_entry), file=dst)
129 if cache_entry.segment
is not None:
130 seglists |= cache_entry.segmentlistdict.coalesce()
139 print(
"Size of cache: %d URLs" % path_count, file=sys.stderr)
140 for instrument, seglist
in list(seglists.items()):
141 ext = seglist.extent()
143 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)
144 span = seglists.union(seglists)
147 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.