|
| 1 | +Version = 'GIT_DESCRIBE' |
| 2 | +ping_checked = False |
| 3 | +check_in_progress = False |
| 4 | + |
| 5 | + |
| 6 | +def version(): |
| 7 | + sp = Version.split("-") |
| 8 | + vnm = "-".join(sp[:-2]) |
| 9 | + vlist = vnm.split(".") + sp[-2:] |
| 10 | + return vlist |
| 11 | + |
| 12 | + |
| 13 | +def get_drs_dirs(): |
| 14 | + return [os.path.join(sys.prefix, "lib")] |
| 15 | + |
| 16 | + |
| 17 | +def get_drs_libs(): |
| 18 | + return ['drsfortran', 'gfortran'] |
| 19 | + |
| 20 | + |
| 21 | +sleep = 60 # minutes (int required) |
| 22 | + |
| 23 | +actions_sent = {} |
| 24 | + |
| 25 | +SOURCE = 'CDAT' |
| 26 | + |
| 27 | + |
| 28 | +def get_version(): |
| 29 | + return Version |
| 30 | + |
| 31 | + |
| 32 | +def get_prefix(): |
| 33 | + import sys |
| 34 | + return sys.prefix |
| 35 | + |
| 36 | + |
| 37 | +def get_sampledata_path(): |
| 38 | + import os |
| 39 | + try: |
| 40 | + return os.path.join(os.environ["UVCDAT_SETUP_PATH"], |
| 41 | + "share", "uvcdat", "sample_data") |
| 42 | + except KeyError: |
| 43 | + raise RuntimeError( |
| 44 | + "UVCDAT environment not configured. Please source the setup_runtime script.") |
| 45 | + |
| 46 | + |
| 47 | +def runCheck(): |
| 48 | + import cdat_info |
| 49 | + import os |
| 50 | + if cdat_info.ping_checked is False: |
| 51 | + check_in_progress = True |
| 52 | + val = None |
| 53 | + envanom = os.environ.get("UVCDAT_ANONYMOUS_LOG", None) |
| 54 | + if envanom is not None: |
| 55 | + if envanom.lower() in ['true', 'yes', 'y', 'ok']: |
| 56 | + val = True |
| 57 | + elif envanom.lower() in ['false', 'no', 'n', 'not']: |
| 58 | + val = False |
| 59 | + else: |
| 60 | + import warnings |
| 61 | + warnings.warn( |
| 62 | + "UVCDAT logging environment variable UVCDAT_ANONYMOUS_LOG should be set to 'True' or 'False', you have it set to '%s', will be ignored" % |
| 63 | + envanom) |
| 64 | + if val is None: # No env variable looking in .uvcdat |
| 65 | + fanom = os.path.join( |
| 66 | + os.path.expanduser("~"), |
| 67 | + ".uvcdat", |
| 68 | + ".anonymouslog") |
| 69 | + if os.path.exists(fanom): |
| 70 | + f = open(fanom) |
| 71 | + for l in f.readlines(): |
| 72 | + sp = l.strip().split("UVCDAT_ANONYMOUS_LOG:") |
| 73 | + if len(sp) > 1: |
| 74 | + try: |
| 75 | + val = eval(sp[1]) |
| 76 | + except: |
| 77 | + pass |
| 78 | + f.close() |
| 79 | + |
| 80 | + reload(cdat_info) |
| 81 | + return val |
| 82 | + |
| 83 | + |
| 84 | +def askAnonymous(val): |
| 85 | + import cdat_info |
| 86 | + import os |
| 87 | + while cdat_info.ping_checked is False and not val in [ |
| 88 | + True, False]: # couldn't get a valid value from env or file |
| 89 | + val2 = raw_input( |
| 90 | + "Allow anonymous logging usage to help improve UV-CDAT? (you can also set the environment variable UVCDAT_ANONYMOUS_LOG to yes or no) [yes/no]") |
| 91 | + if val2.lower() in ['y', 'yes', 'ok']: |
| 92 | + val = True |
| 93 | + elif val2.lower() in ['n', 'no', 'not']: |
| 94 | + val = False |
| 95 | + if val in [True, False]: # store result for next time |
| 96 | + try: |
| 97 | + fanom = os.path.join( |
| 98 | + os.path.expanduser("~"), ".uvcdat", ".anonymouslog") |
| 99 | + if not os.path.exists(os.path.join( |
| 100 | + os.path.expanduser("~"), ".uvcdat")): |
| 101 | + os.makedirs( |
| 102 | + os.path.join( |
| 103 | + os.path.expanduser("~"), |
| 104 | + ".uvcdat")) |
| 105 | + f = open(fanom, "w") |
| 106 | + print >>f, "#Store information about allowing UVCDAT anonymous logging" |
| 107 | + print >>f, "# Need sto be True or False" |
| 108 | + print >>f, "UVCDAT_ANONYMOUS_LOG: %s" % val |
| 109 | + f.close() |
| 110 | + except Exception as err: |
| 111 | + pass |
| 112 | + else: |
| 113 | + if cdat_info.ping_checked: |
| 114 | + val = cdat_info.ping |
| 115 | + cdat_info.ping = val |
| 116 | + cdat_info.ping_checked = True |
| 117 | + check_in_progress = False |
| 118 | + |
| 119 | + |
| 120 | +def pingPCMDIdb(*args, **kargs): |
| 121 | + import cdat_info |
| 122 | + import os |
| 123 | + while cdat_info.check_in_progress: |
| 124 | + reload(cdat_info) |
| 125 | + val = cdat_info.runCheck() |
| 126 | + if val is False: |
| 127 | + cdat_info.ping_checked = True |
| 128 | + cdat_info.ping = False |
| 129 | + return |
| 130 | + try: |
| 131 | + if not cdat_info.ping: |
| 132 | + return |
| 133 | + except: |
| 134 | + pass |
| 135 | + cdat_info.askAnonymous(val) |
| 136 | + import threading |
| 137 | + kargs['target'] = pingPCMDIdbThread |
| 138 | + kargs['args'] = args |
| 139 | + t = threading.Thread(**kargs) |
| 140 | + t.start() |
| 141 | + |
| 142 | + |
| 143 | +def pingPCMDIdbThread(*args, **kargs): |
| 144 | + import threading |
| 145 | + kargs['target'] = submitPing |
| 146 | + kargs['args'] = args |
| 147 | + t = threading.Thread(**kargs) |
| 148 | + t.start() |
| 149 | + import time |
| 150 | + time.sleep(5) # Lets wait 5 seconds top for this ping to work |
| 151 | + if t.isAlive(): |
| 152 | + try: |
| 153 | + t._Thread__stop() |
| 154 | + except: |
| 155 | + pass |
| 156 | + |
| 157 | + |
| 158 | +def submitPing(source, action, source_version=None): |
| 159 | + try: |
| 160 | + import urllib2 |
| 161 | + import sys |
| 162 | + import os |
| 163 | + import cdat_info |
| 164 | + import hashlib |
| 165 | + import urllib |
| 166 | + if source in ['cdat', 'auto', None]: |
| 167 | + source = cdat_info.SOURCE |
| 168 | + if cdat_info.ping: |
| 169 | + if not source in actions_sent.keys(): |
| 170 | + actions_sent[source] = [] |
| 171 | + elif action in actions_sent[source]: |
| 172 | + return |
| 173 | + else: |
| 174 | + actions_sent[source].append(action) |
| 175 | + data = {} |
| 176 | + uname = os.uname() |
| 177 | + data['platform'] = uname[0] |
| 178 | + data['platform_version'] = uname[2] |
| 179 | + data['hashed_hostname'] = hashlib.sha1(uname[1]).hexdigest() |
| 180 | + data['source'] = source |
| 181 | + if source_version is None: |
| 182 | + data['source_version'] = cdat_info.get_version() |
| 183 | + else: |
| 184 | + data['source_version'] = source_version |
| 185 | + data['action'] = action |
| 186 | + data['sleep'] = cdat_info.sleep |
| 187 | + data['hashed_username'] = hashlib.sha1(os.getlogin()).hexdigest() |
| 188 | + urllib2.urlopen( |
| 189 | + 'http://uv-cdat.llnl.gov/UVCDATUsage/log/add/', |
| 190 | + urllib.urlencode(data)) |
| 191 | + except Exception as err: |
| 192 | + pass |
| 193 | + |
| 194 | +import os |
| 195 | +import sys |
| 196 | +os.environ["UVCDAT_SETUP_PATH"] = sys.prefix |
| 197 | +CDMS_INCLUDE_DAP = 'yes' |
| 198 | +CDMS_DAP_DIR = '.' |
| 199 | +CDMS_HDF_DIR = '.' |
| 200 | +CDMS_GRIB2LIB_DIR = sys.prefix |
| 201 | +CDMS_INCLUDE_GRIB2LIB = 'yes' |
| 202 | +CDMS_INCLUDE_DRS = 'no' |
| 203 | +CDMS_INCLUDE_HDF = 'no' |
| 204 | +CDMS_INCLUDE_PP = 'yes' |
| 205 | +CDMS_INCLUDE_QL = 'no' |
| 206 | +drs_file = os.path.join(sys.prefix, 'lib', 'libdrs.a') |
| 207 | +netcdf_directory = sys.prefix |
| 208 | +netcdf_include_directory = sys.prefix + '/include' |
| 209 | +cdunif_include_directories = [ |
| 210 | + sys.prefix + '/include/cdms'] + [ |
| 211 | + sys.prefix + '/include', |
| 212 | + sys.prefix + '/lib/libffi-3.1/include', |
| 213 | + '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include', |
| 214 | + '/usr/X11R6/include'] + [] |
| 215 | +cdunif_library_directories = [sys.prefix + '/lib'] + get_drs_dirs( |
| 216 | +) + [sys.prefix + '/lib'] + ["/usr/X11/lib", "/usr/X11R6/lib"] |
| 217 | +cdunif_libraries = ['cdms', 'netcdf'] + ['netcdf'] + \ |
| 218 | + get_drs_libs() + [] + ['grib2c', 'png', 'jasper'] |
| 219 | +x11include = ['/usr/X11R6/include', '/usr/include', '/opt/include'] |
| 220 | +x11libdir = ['/usr/X11R6/lib', '/usr/lib', '/opt/lib'] |
| 221 | +mathlibs = ['m'] |
| 222 | +externals = sys.prefix |
0 commit comments