LALPulsar 7.1.2.1-bf6a62b
lalpulsar_PublicSFTDirs.py
Go to the documentation of this file.
1##python
2# Copyright (C) 2025 Karl Wette
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with with program; see the file COPYING. If not, write to the
16# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17# MA 02110-1301 USA
18
19## \file
20## \ingroup lalpulsar_bin_SFTTools
21"""Output the public directory for the given SFT name(s), following the
22convention detailed in the SFT spec (T040164)."""
23
24
25import argparse
26import sys
27import os
28
29from lalpulsar.public_sft_directory import public_sft_directory
30from lalpulsar import git_version
31
32__author__ = "Karl Wette <karl.wette@ligo.org>"
33__version__ = git_version.id
34__date__ = git_version.date
35
36
38 # parse command line
39 parser = argparse.ArgumentParser(description=__doc__)
40 parser.add_argument(
41 "-F",
42 "--format",
43 dest="fmt",
44 type=str,
45 default="{dir}",
46 help="format output using this Python {}-style formatter, where: {dir}=public SFT directory, {name}=SFT name, {orig}=original SFT path",
47 )
48 parser.add_argument(
49 "SFT_paths",
50 type=str,
51 nargs="*",
52 help="SFT paths; if not given, read from standard input",
53 )
54 args = parser.parse_args()
55
56 return args
57
58
59if __name__ == "__main__":
61
62 # iterate either over command lines or standard input
63 SFT_path_source = args.SFT_paths
64 if not SFT_path_source:
65 SFT_path_source = sys.stdin
66
67 for SFT_path_str in SFT_path_source:
68
69 # original SFT path
70 fmt_vals = {"orig": SFT_path_str.rstrip()}
71
72 # get original SFT path and SFT name
73 _, fmt_vals["name"] = os.path.split(fmt_vals["orig"])
74
75 # get public SFT directory
76 fmt_vals["dir"] = public_sft_directory(fmt_vals["name"])
77
78 # print output
79 print(args.fmt.format(**fmt_vals))