OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
build_manifest_ocssw.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 """
4 Created on Wed Nov 20 15:56:47 EST 2019
5 
6 @author: dshea
7 """
8 
9 import sys
10 import argparse
11 import subprocess
12 import multiprocessing as mp
13 
14 machineInfo = [
15  # CentOS 7
16  {
17  "name" : "linux_64",
18  "login" : "seadasdev201",
19  "initStr" : "source .bash_profile && source /opt/rh/devtoolset-7/enable",
20  "exitStr" : ""
21  },
22  # RHEL 8
23 # {
24 # "name" : "linux_64",
25 # "login" : "seadasdev301",
26 # "initStr" : "source .bash_profile",
27 # "exitStr" : ""
28 # },
29  # Ubuntu 20.04
30  {
31  "name" : "odps",
32  "login" : "analysis401",
33  "initStr" : "source .profile",
34  "exitStr" : ""
35  },
36  # macOS
37  {
38  "name" : "macosx_intel",
39  "login" : "seadas4",
40  "initStr" : "source .bash_profile",
41  "exitStr" : " && fix_mac_rpath.py"
42  },
43 ]
44 
45 firstRunStr = " && if [ ! -d ocssw ]; then mkdir ocssw; fi && if [ ! -d ocssw/share ]; then mkdir ocssw/share; fi && if [ ! -d ocssw/testdata ]; then mkdir ocssw/testdata; fi && if [ ! -d ocssw/var ]; then mkdir ocssw/var; fi && if [ ! -d ocssw/opt ]; then mkdir ocssw/opt; fi"
46 saveOcsswStr = " && rm -rf saveOcssw && mkdir saveOcssw && cd ocssw && mv share testdata var ../saveOcssw"
47 restoreOcsswStr = " && rm -rf share/modis && mv ../saveOcssw/share ../saveOcssw/testdata ../saveOcssw/var ."
48 saveOptStr = " && mv opt ../saveOcssw"
49 restoreOptStr = " && mv ../saveOcssw/opt ."
50 getOcsswStr = " && cd && rm -rf ocssw && git clone https://oceandata.sci.gsfc.nasa.gov/rcs/obpg/ocssw.git && cd ocssw && source OCSSW_bash.env"
51 getSubmodulesStr = " && git submodule init && git submodule update"
52 buildOptStr = " && ./get_lib3_src.sh && cd opt/src && ./BuildIt.py && cd ../.."
53 buildOcsswStr = " && mkdir build && cd build && cmake .. -DBUILD_ALL=1 && make -j 20 install"
54 getViirsStr = " && cd && rm -rf viirs_l1 && git clone https://oceandata.sci.gsfc.nasa.gov/rcs/viirs/viirs_l1.git && cd viirs_l1"
55 buildViirsStr = " && mkdir build && cd build && cmake .. && make -j 20 install"
56 getFocsStr = " && cd && rm -rf focs && git clone https://oceandata.sci.gsfc.nasa.gov/rcs/obpg/focs.git && cd focs"
57 buildFocsStr = " && mkdir build && cd build && cmake .. && make -j 20 install"
58 
59 
60 def doIt(cmd, logFilename, out):
61  logFile = open(logFilename, "w")
62  result = subprocess.run(cmd, shell=True, stderr=subprocess.STDOUT, stdout=logFile)
63  logFile.close()
64  out.put(result.returncode)
65 
66 
67 def run():
68  processes = []
69 
70  parser = argparse.ArgumentParser(description="Build OCSSW on all of our architectures")
71  parser.add_argument("-t", "--tag", default=None,
72  help="git tag or branch that you want to build")
73  parser.add_argument("-a", "--arch", default=None,
74  help="comma separated list of architectures that you want to build (linux_64,odps,macosx_intel)")
75  parser.add_argument("--build_opt", default=False, action="store_true",
76  help="build opt (lib3) first")
77 
78 
79  args = parser.parse_args()
80 
81  # make sure the arch list is valid
82  if args.arch:
83  machineList = []
84  for info in machineInfo:
85  machineList.append(info["name"])
86  archList = args.arch.split(',')
87  for arch in archList:
88  if arch not in machineList:
89  print("Architecture", arch, "is not in the list of supported architectures")
90  sys.exit(1)
91 
92  runList = []
93 
94  # Define an output queue
95  output = mp.Queue()
96 
97  archFound = False
98  for info in machineInfo:
99  if args.arch:
100  if info["name"] not in args.arch:
101  continue
102  archFound = True
103 
104  runList.append(info["name"])
105  print("\n---making", info["name"])
106 
107  commandLine = "ssh " + info["login"] + ' "' + info["initStr"] + firstRunStr + saveOcsswStr
108  if not args.build_opt:
109  commandLine += saveOptStr
110  commandLine += getOcsswStr
111  if args.tag:
112  commandLine += " && git checkout " + args.tag
113  commandLine += getSubmodulesStr
114  if args.build_opt:
115  commandLine += buildOptStr
116  else:
117  commandLine += restoreOptStr
118  commandLine += restoreOcsswStr
119  commandLine += " && rm -rf ../saveOcssw"
120  commandLine += buildOcsswStr
121 
122  # build VIIRS
123  commandLine += getViirsStr
124  if args.tag:
125  commandLine += " && git checkout " + args.tag
126  commandLine += getSubmodulesStr
127  commandLine += buildViirsStr
128 
129  # build FOCS
130  commandLine += getFocsStr
131  if args.tag:
132  commandLine += " && git checkout " + args.tag
133  commandLine += getSubmodulesStr
134  commandLine += buildFocsStr
135 
136  commandLine += info["exitStr"]
137  commandLine += '"'
138 
139  logFilename = "build." + info["name"] + ".log"
140 
141  processes.append(mp.Process(target=doIt, args=(commandLine, logFilename, output)))
142 
143  if not archFound:
144  print("Architecture", args.arch, "is not valid")
145  sys.exit(1)
146 
147  print("Starting Processes")
148 
149  # Run processes
150  for p in processes:
151  p.start()
152 
153  print("Waiting for Processes")
154 
155  # Exit the completed processes
156  for p in processes:
157  p.join()
158 
159  print("Checking results")
160 
161  # check the return result
162  result = True
163  count = 0
164  for p in processes:
165  tmp = output.get()
166  if tmp != 0:
167  result = False
168  print(runList[count], "return code =", tmp)
169  else:
170  print(runList[count], "Success")
171 
172  count += 1
173 
174  if result:
175  print("Everyting completed successfully.")
176 
177  return 0
178 
179 
180 if __name__ == "__main__":
181  sys.exit(run())
def doIt(cmd, logFilename, out)