|
1 | | -#!/usr/bin/python |
| 1 | +#!/usr/bin/env python |
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 | """ |
4 | 4 | Climaf is documented at ReadTheDocs : http://climaf.readthedocs.org/ |
|
11 | 11 |
|
12 | 12 | # Created : S.Sénési - 2014 |
13 | 13 |
|
14 | | -__all__ = ["site_settings", "cache", "classes", "clogging", "dataloc", "driver", "netcdfbasics", |
| 14 | +__all__ = ["cache", "classes", "dataloc", "driver", "netcdfbasics", |
15 | 15 | "operators", "period", "standard_operators", "cmacro", "html", "functions", "plot", |
16 | 16 | "projects", "derived_variables"] |
17 | 17 |
|
18 | | -version = "1.2.12" |
| 18 | +version = "1.2.13" |
19 | 19 |
|
20 | 20 |
|
21 | 21 | def tim(string=None): |
@@ -52,52 +52,89 @@ def tim(string=None): |
52 | 52 |
|
53 | 53 | tim("atexit") |
54 | 54 | # |
55 | | - import clogging |
56 | | - import site_settings |
| 55 | + import env.clogging as clogging |
| 56 | + import env.site_settings as site_settings |
57 | 57 | import cache |
58 | 58 | import standard_operators |
59 | 59 | import cmacro |
60 | 60 | import operators |
61 | 61 | import subprocess |
62 | 62 | import commands |
63 | | - |
| 63 | + |
| 64 | + |
64 | 65 | def my_which(soft): |
65 | | - p = subprocess.Popen(["which",soft], stdout=subprocess.PIPE) |
66 | | - return str.replace(p.stdout.readlines()[0],'\n','') |
| 66 | + p = subprocess.Popen(["which", soft], stdout=subprocess.PIPE) |
| 67 | + return str.replace(p.stdout.readlines()[0], '\n', '') |
| 68 | + |
| 69 | + |
67 | 70 | def bash_command_to_str(cmd): |
68 | | - return str.replace(subprocess.Popen(str.split(cmd,' '), stdout=subprocess.PIPE).stdout.readlines()[0],'\n','') |
| 71 | + return str.replace(subprocess.Popen(str.split(cmd, ' '), stdout=subprocess.PIPE).stdout.readlines()[0], '\n', |
| 72 | + '') |
| 73 | + |
69 | 74 |
|
70 | 75 | tim("imports") |
71 | 76 | print("CliMAF version = " + version, file=sys.stderr) |
72 | 77 | print("CliMAF install => " + "/".join(__file__.split("/")[:-2])) |
73 | | - print("python => "+my_which('python')) |
74 | | - print("---") |
75 | | - print("Required softwares to run CliMAF => you are using the following versions/installations:") |
76 | | - try: |
77 | | - print("ncl "+commands.getoutput(my_which('ncl')+' -V')+" => "+my_which('ncl')) |
78 | | - except: |
79 | | - print("Warning: ncl not found -> can't use CliMAF plotting scripts") |
80 | | - try: |
81 | | - tmp = str.split(commands.getstatusoutput(my_which('cdo')+' -V')[1],' ') |
82 | | - print("cdo "+tmp[tmp.index('version')+1]+" => "+my_which('cdo')) |
83 | | - except: |
84 | | - print("Error: cdo not found -> CDO is mandatory to run CliMAF") |
85 | | - my_which('cdo') |
86 | | - try: |
87 | | - tmp = str.split(commands.getstatusoutput(my_which('ncks')+' --version')[1], ' ') |
88 | | - print("nco (ncks) "+tmp[tmp.index('version')+1]+" => "+my_which('ncks')) |
89 | | - except: |
90 | | - print("Warning: nco not found -> can't use nco from CliMAF") |
91 | | - try: |
92 | | - if site_settings.atTGCC or site_settings.atIPSL or site_settings.onCiclad: |
93 | | - print("ncdump "+commands.getstatusoutput('/prodigfs/ipslfs/dods/jservon/miniconda/envs/cesmep_env/bin/ncdump')[-1].split('\n')[-1].split()[3]+" => "+my_which('ncdump')) |
94 | | - else: |
95 | | - binary_info = commands.getstatusoutput(my_which("ncdump") + " --version")[-1].split("\n")[-1] |
96 | | - binary_info = binary_info.split("version")[-1].split("of")[0].strip() |
97 | | - print("ncdump "+binary_info+" => "+my_which('ncdump')) |
98 | | - except: |
99 | | - print("Warning: ncdump not found -> can't use ncdump from CliMAF") |
100 | | - print("---") |
| 78 | + if os.environ.get('CLIMAF_CHECK_DEPENDENCIES', "yes") == "yes" : |
| 79 | + print("python => " + my_which('python')) |
| 80 | + print("---") |
| 81 | + print("Required softwares to run CliMAF => you are using the following versions/installations:") |
| 82 | + try: |
| 83 | + print("ncl " + commands.getoutput(my_which('ncl') + ' -V') + " => " + my_which('ncl')) |
| 84 | + except: |
| 85 | + print("Warning: ncl not found -> can't use CliMAF plotting scripts") |
| 86 | + try: |
| 87 | + tmp = str.split(commands.getstatusoutput(my_which('cdo') + ' -V')[1], ' ') |
| 88 | + print("cdo " + tmp[tmp.index('version') + 1] + " => " + my_which('cdo')) |
| 89 | + except: |
| 90 | + print("Error: cdo not found -> CDO is mandatory to run CliMAF") |
| 91 | + try: |
| 92 | + tmp = str.split(commands.getstatusoutput(my_which('ncks') + ' --version')[1], ' ') |
| 93 | + print("nco (ncks) " + tmp[tmp.index('version') + 1] + " => " + my_which('ncks')) |
| 94 | + except: |
| 95 | + print("Warning: nco not found -> can't use nco from CliMAF") |
| 96 | + try: |
| 97 | + if site_settings.atTGCC or site_settings.atIPSL or site_settings.onCiclad: |
| 98 | + ncdump_ret = commands.getstatusoutput('/prodigfs/ipslfs/dods/jservon/miniconda/envs/cesmep_env/bin/ncdump') |
| 99 | + print("ncdump " + ncdump_ret[-1].split('\n')[-1].split()[3] + " => " + my_which('ncdump')) |
| 100 | + else: |
| 101 | + binary_info = commands.getstatusoutput(my_which("ncdump") + " --version")[-1].split("\n")[-1] |
| 102 | + binary_info = binary_info.split("version")[-1].split("of")[0].strip() |
| 103 | + print("ncdump " + binary_info + " => " + my_which('ncdump')) |
| 104 | + except: |
| 105 | + print("Warning: ncdump not found -> can't use ncdump from CliMAF") |
| 106 | + # Check that tools for stamping are available or enforce stamping to None |
| 107 | + print("Check stamping requirements") |
| 108 | + do_stamping = True |
| 109 | + try: |
| 110 | + print("nco (ncatted) found -> " + my_which("ncatted")) |
| 111 | + except: |
| 112 | + print("nco (ncatted) not available, can not stamp netcdf files") |
| 113 | + do_stamping = False |
| 114 | + try: |
| 115 | + print("convert found -> " + my_which("convert")) |
| 116 | + except: |
| 117 | + print("convert not available, can not stamp png files") |
| 118 | + do_stamping = False |
| 119 | + try: |
| 120 | + print("pdftk found -> " + my_which("pdftk")) |
| 121 | + except: |
| 122 | + print("pdftk not available, can not stamp pdf files") |
| 123 | + do_stamping = False |
| 124 | + try: |
| 125 | + print("exiv2 found -> " + my_which("exiv2")) |
| 126 | + except: |
| 127 | + print("exiv2 not available, can not stamp eps files") |
| 128 | + do_stamping = False |
| 129 | + if not do_stamping and cache.stamping is True: |
| 130 | + print("At least one stamping requirement is not fulfilled, turn it to None.") |
| 131 | + cache.stamping = None |
| 132 | + print("---") |
| 133 | + # |
| 134 | + # Check that the variable TMPDIR, if defined, points to an existing directory |
| 135 | + if "TMPDIR" in os.environ and not os.path.isdir(os.environ["TMPDIR"]): |
| 136 | + # raise OSError("TMPDIR points to a non existing directory! Change the value of the variable to go on.") |
| 137 | + os.makedirs(os.environ["TMPDIR"]) |
101 | 138 |
|
102 | 139 | logdir = os.path.expanduser(os.getenv("CLIMAF_LOG_DIR", ".")) |
103 | 140 | # |
|
0 commit comments