Go to the documentation of this file.
2 from pathlib
import Path
9 A simple module to populate some important environment variables
11 if os.getenv(
"OCSSWROOT")
is None:
12 scriptdir = Path(__file__).resolve().parent
13 if 'src' in scriptdir.parts:
14 self.dirs[
'packageroot'] = scriptdir.parents[2]
16 self.dirs[
'packageroot'] = scriptdir.parents[1]
18 self.dirs[
'packageroot'] = Path(os.getenv(
"OCSSWROOT"))
20 self.dirs[
'root'] = self.dirs[
'packageroot'] /
"share"
21 if os.getenv(
"OCDATAROOT"):
22 self.dirs[
'root'] = Path(os.getenv(
"OCDATAROOT"))
24 if not self.dirs[
'root'].exists():
25 print(
"ERROR: The OCDATAROOT {} directory does not exist.".format(self.dirs[
'root']))
26 print(
"Please make sure you have downloaded and installed OCSSW and sourced the OCSSW environment")
29 self.dirs[
'scripts'] = self.dirs[
'packageroot'] /
"scripts"
30 if os.getenv(
"OCSSW_SCRIPTS"):
31 self.dirs[
'scripts'] = Path(os.getenv(
"OCSSW_SCRIPTS"))
33 self.dirs[
'var'] = self.dirs[
'packageroot'] /
"var"
34 if os.getenv(
"OCVARROOT"):
35 self.dirs[
'var'] = Path(os.getenv(
"OCVARROOT"))
37 self.dirs[
'bin'] = self.dirs[
'packageroot'] /
"bin"
38 if os.getenv(
"OCSSW_BIN"):
39 self.dirs[
'bin'] = Path(os.getenv(
"OCSSW_BIN"))
41 self.dirs[
'bin3'] = self.dirs[
'packageroot'] /
"opt" /
"bin"
42 if os.getenv(
"LIB3_BIN"):
43 self.dirs[
'bin3'] = Path(os.getenv(
"LIB3_BIN"))
45 self.dirs[
'log'] = self.dirs[
'var'] /
"log"
46 Path(self.dirs[
'log']).mkdir(parents=
True, exist_ok=
True)
48 if os.getenv(
"OCSSW_DEBUG")
is not None and int(os.getenv(
"OCSSW_DEBUG")) > 0:
49 if not os.path.exists(self.dirs[
'bin']):
50 print(
"Error: OCSSW_DEBUG set, but...\n\t%s\ndoes not exist!" % self.dirs[
'bin'])
53 print(
"Running debug binaries...\n\t%s" % self.dirs[
'bin'])
55 self.dirs[
'run'] = Path.cwd()
57 self.dirs[
'anc'] = self.dirs[
'run']
59 if self.ancdir
is None:
60 if os.getenv(
"L2GEN_ANC")
is None and os.getenv(
"USER_L2GEN_ANC")
is None:
62 print(
"Neither the L2GEN_ANC nor USER_L2GEN_ANC environment variables are set.")
63 print(
"...using the current working directory for ancillary file download.")
65 self.dirs[
'anc'] = self.dirs[
'run']
67 if os.getenv(
"L2GEN_ANC")
is not None:
68 self.dirs[
'anc'] = os.getenv(
"L2GEN_ANC")
70 self.dirs[
'anc'] = os.getenv(
"USER_L2GEN_ANC")
72 self.dirs[
'anc'] = Path(self.ancdir)
76 Returns the path to the program named in prog_name as a pathlib Path object.
77 None is returned if the program is not found.
80 if os.getenv(
"OCSSWROOT"):
81 packageroot = Path(os.getenv(
"OCSSWROOT"))
83 prog_path = packageroot /
'bin' / prog_name
84 if not Path.exists(prog_path):
85 err_msg =
"Cannot find program %s" % prog_name
86 logging.error(err_msg)
def build_executable_path(prog_name)