예제 #1
0
def netcdf_cf_setup():

    # global vars
    gdaltest.netcdf_cf_method = None
    gdaltest.netcdf_cf_files = None
    gdaltest.netcdf_cf_check_error = ''

    # if netcdf is not supported, skip detection
    if gdaltest.netcdf_drv is None:
        pytest.skip()

    # skip if on windows
    if os.name != 'posix':
        pytest.skip('NOTICE: will skip CF checks because OS is not posix!')

    # try local method
    cdms2_installed = False
    try:
        imp.find_module('cdms2')
        cdms2_installed = True
    except ImportError:
        print('NOTICE: cdms2 not installed!')
        print('        see installation notes at http://pypi.python.org/pypi/cfchecker')
    if cdms2_installed:
        xml_dir = './data/netcdf_cf_xml'
        tmp_dir = './tmp/cache'
        files = dict()
        files['a'] = xml_dir + '/area-type-table.xml'
        files['s'] = tmp_dir + '/cf-standard-name-table-v18.xml'
        # either find udunits path in UDUNITS_PATH, or based on location of udunits app, or copy all .xml files to data
        # opt_u = '/home/soft/share/udunits/udunits2.xml'
        files['u'] = xml_dir + '/udunits2.xml'
        # look for xml files
        if not (os.path.exists(files['a']) and os.path.exists(files['s']) and os.path.exists(files['u'])):
            print('NOTICE: cdms2 installed, but necessary xml files are not found!')
            print('        the following files must exist:')
            print('        ' + xml_dir + '/area-type-table.xml from http://cf-pcmdi.llnl.gov/documents/cf-standard-names/area-type-table/1/area-type-table.xml')
            print('        ' + tmp_dir + '/cf-standard-name-table-v18.xml - http://cf-pcmdi.llnl.gov/documents/cf-standard-names/standard-name-table/18/cf-standard-name-table.xml')
            print('        ' + xml_dir + '/udunits2*.xml from a UDUNITS2 install')
            # try to get cf-standard-name-table
            if not os.path.exists(files['s']):
                # print '        downloading cf-standard-name-table.xml (v18) from http://cf-pcmdi.llnl.gov ...'
                if not gdaltest.download_file('http://cf-pcmdi.llnl.gov/documents/cf-standard-names/standard-name-table/18/cf-standard-name-table.xml',
                                              'cf-standard-name-table-v18.xml'):
                    print('        Failed to download, please get it and try again.')

        if os.path.exists(files['a']) and os.path.exists(files['s']) and os.path.exists(files['u']):
            gdaltest.netcdf_cf_method = 'local'
            gdaltest.netcdf_cf_files = files
            print('NOTICE: netcdf CF compliance checks: using local checker script')
            return

    # skip http method if GDAL_DOWNLOAD_TEST_DATA and GDAL_RUN_SLOW_TESTS are not defined
    if not gdaltest.download_test_data():
        print('NOTICE: skipping netcdf CF compliance checks')
        print('to enable remote http checker script, define GDAL_DOWNLOAD_TEST_DATA=YES')
        return

    if not gdaltest.run_slow_tests():
        print('NOTICE: skipping netcdf CF compliance checks')
        return

    # http method with curl, should use python module but easier for now
    success = False
    try:
        gdaltest.runexternal_out_and_err('curl')
    except OSError:
        print('no curl executable')
    else:
        # make sure script is responding
        handle = gdaltest.gdalurlopen("http://puma.nerc.ac.uk/cgi-bin/cf-checker.pl")
        if handle is not None:
            success = True
        else:
            print('script not responding')
    if success:
        gdaltest.netcdf_cf_method = 'http'
        print('NOTICE: netcdf CF compliance checks: using remote HTTP '
              'checker script, consider installing cdms2 locally')
        return

    if gdaltest.netcdf_cf_method is None:
        print('NOTICE: skipping netcdf CF compliance checks')
예제 #2
0
def netcdf_cf_setup():

    # global vars
    gdaltest.netcdf_cf_method = None
    gdaltest.netcdf_cf_files = None
    gdaltest.netcdf_cf_check_error = ''

    # if netcdf is not supported, skip detection
    if gdaltest.netcdf_drv is None:
        pytest.skip()

    # skip if on windows
    if os.name != 'posix':
        pytest.skip('NOTICE: will skip CF checks because OS is not posix!')

    # try local method
    cdms2_installed = False
    try:
        imp.find_module('cdms2')
        cdms2_installed = True
    except ImportError:
        print('NOTICE: cdms2 not installed!')
        print(
            '        see installation notes at http://pypi.python.org/pypi/cfchecker'
        )
    if cdms2_installed:
        xml_dir = './data/netcdf_cf_xml'
        tmp_dir = './tmp/cache'
        files = dict()
        files['a'] = xml_dir + '/area-type-table.xml'
        files['s'] = tmp_dir + '/cf-standard-name-table-v18.xml'
        # either find udunits path in UDUNITS_PATH, or based on location of udunits app, or copy all .xml files to data
        # opt_u = '/home/soft/share/udunits/udunits2.xml'
        files['u'] = xml_dir + '/udunits2.xml'
        # look for xml files
        if not (os.path.exists(files['a']) and os.path.exists(files['s'])
                and os.path.exists(files['u'])):
            print(
                'NOTICE: cdms2 installed, but necessary xml files are not found!'
            )
            print('        the following files must exist:')
            print(
                '        ' + xml_dir +
                '/area-type-table.xml from http://cf-pcmdi.llnl.gov/documents/cf-standard-names/area-type-table/1/area-type-table.xml'
            )
            print(
                '        ' + tmp_dir +
                '/cf-standard-name-table-v18.xml - http://cf-pcmdi.llnl.gov/documents/cf-standard-names/standard-name-table/18/cf-standard-name-table.xml'
            )
            print('        ' + xml_dir +
                  '/udunits2*.xml from a UDUNITS2 install')
            # try to get cf-standard-name-table
            if not os.path.exists(files['s']):
                # print '        downloading cf-standard-name-table.xml (v18) from http://cf-pcmdi.llnl.gov ...'
                if not gdaltest.download_file(
                        'http://cf-pcmdi.llnl.gov/documents/cf-standard-names/standard-name-table/18/cf-standard-name-table.xml',
                        'cf-standard-name-table-v18.xml'):
                    print(
                        '        Failed to download, please get it and try again.'
                    )

        if os.path.exists(files['a']) and os.path.exists(
                files['s']) and os.path.exists(files['u']):
            gdaltest.netcdf_cf_method = 'local'
            gdaltest.netcdf_cf_files = files
            print(
                'NOTICE: netcdf CF compliance checks: using local checker script'
            )
            return

    # skip http method if GDAL_DOWNLOAD_TEST_DATA and GDAL_RUN_SLOW_TESTS are not defined
    if not gdaltest.download_test_data():
        print('NOTICE: skipping netcdf CF compliance checks')
        print(
            'to enable remote http checker script, define GDAL_DOWNLOAD_TEST_DATA=YES'
        )
        return

    if not gdaltest.run_slow_tests():
        print('NOTICE: skipping netcdf CF compliance checks')
        return

    # http method with curl, should use python module but easier for now
    success = False
    try:
        gdaltest.runexternal_out_and_err('curl')
    except OSError:
        print('no curl executable')
    else:
        # make sure script is responding
        handle = gdaltest.gdalurlopen(
            "http://puma.nerc.ac.uk/cgi-bin/cf-checker.pl")
        if handle is not None:
            success = True
        else:
            print('script not responding')
    if success:
        gdaltest.netcdf_cf_method = 'http'
        print('NOTICE: netcdf CF compliance checks: using remote HTTP '
              'checker script, consider installing cdms2 locally')
        return

    if gdaltest.netcdf_cf_method is None:
        print('NOTICE: skipping netcdf CF compliance checks')