OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
rewrite_seadas_config.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 """
4 Rewrite the seadas configuration file (usually
5 $SEADAS/config/seadas.config), changing the value
6 of the seadas.ocssw.root line to a value passed
7 in via the command line call.
8 """
9 import argparse
10 import shutil
11 import sys
12 
13 def rewrite_seadas_config(seadas_config, install_dir):
14  """
15  Reads the input file then writes it to a temporary file,
16  changing the appropriate entry. Then it copies the temporary
17  file over the original.
18  """
19  with open(seadas_config, 'rt') as in_file:
20  in_content = in_file.readlines()
21 
22  with open('seadas_config.tmp', 'wt') as out_file:
23  for line in in_content:
24  if line.startswith('seadas.ocssw.root'):
25  out_line = 'seadas.ocssw.root = ' + install_dir + '\n'
26  else:
27  out_line = line
28  out_file.write(out_line)
29  shutil.copy('seadas_config.tmp', seadas_config)
30  return
31 
32 def main():
33  version = "1.0"
34  parser = argparse.ArgumentParser(prog="rewrite_seadas_config")
35  parser.add_argument('--version', action='version', version='%(prog)s ' + version)
36  parser.add_argument("seadasConfig",
37  help="SeaADAS config file to edit", metavar="CONFIGFILE")
38  parser.add_argument("OCSSWROOT",
39  help="OCSSW root directory", metavar="OCSSWROOT")
40 
41  args = parser.parse_args()
42  if args.seadasConfig is None or args.OCSSWROOT is None:
43  parser.print_help()
44  sys.exit(1)
45 
46  rewrite_seadas_config(args.seadasConfig, args.OCSSWROOT)
47  return 0
48 
49 if __name__ == '__main__':
50  sys.exit(main())
def rewrite_seadas_config(seadas_config, install_dir)