Skip to content

Commit

Permalink
Merge pull request #498 from ioos/cf-standard-print-stderr
Browse files Browse the repository at this point in the history
Print messages about CF standard table downloading to stderr, fixes #497
  • Loading branch information
lukecampbell authored May 17, 2017
2 parents 66ec69e + 4e3c9f0 commit 8c3010f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions compliance_checker/cf/cf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, division
from __future__ import unicode_literals, division, print_function
from compliance_checker.base import BaseCheck, BaseNCCheck, Result, TestCtx
from compliance_checker.cf.appendix_d import dimless_vertical_coordinates
from compliance_checker.cf.appendix_f import grid_mapping_dict
Expand All @@ -11,6 +11,7 @@
import numpy as np
import os
import re
import sys

import logging

Expand Down Expand Up @@ -132,7 +133,7 @@ def _find_cf_standard_name_table(self, ds):

# If the packaged version is what we're after, then we're good
if version == self._std_names._version:
print("Using packaged standard name table v{0}".format(version))
print("Using packaged standard name table v{0}".format(version), file=sys.stderr)
return False

# Try to download the version specified
Expand All @@ -142,15 +143,15 @@ def _find_cf_standard_name_table(self, ds):
# Did we already download this before?
if not os.path.isfile(location):
util.download_cf_standard_name_table(version, location)
print("Using downloaded standard name table v{0}".format(version))
print("Using downloaded standard name table v{0}".format(version), file=sys.stderr)
else:
print("Using cached standard name table v{0} from {1}".format(version, location))
print("Using cached standard name table v{0} from {1}".format(version, location), file=sys.stderr)

self._std_names = util.StandardNameTable(location)
return True
except Exception:
# There was an error downloading the CF table. That's ok, we'll just use the packaged version
print("Error fetching standard name table. Using packaged v{0}".format(self._std_names._version))
print("Error fetching standard name table. Using packaged v{0}".format(self._std_names._version), file=sys.stderr)
return False

def _find_coord_vars(self, ds, refresh=False):
Expand Down
4 changes: 3 additions & 1 deletion compliance_checker/cf/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import print_function
import io
import itertools
import requests
import os
import sys
from copy import deepcopy
from collections import defaultdict
from lxml import etree
Expand Down Expand Up @@ -327,7 +329,7 @@ def download_cf_standard_name_table(version, location=None):
url = "http://cfconventions.org/Data/cf-standard-names/{0}/src/cf-standard-name-table.xml".format(version)
r = requests.get(url, allow_redirects=True)
if r.status_code == 200:
print("Downloading cf-standard-names table version {0} from: {1}".format(version, url))
print("Downloading cf-standard-names table version {0} from: {1}".format(version, url), file=sys.stderr)
with open(location, 'wb') as f:
f.write(r.content)
else:
Expand Down

0 comments on commit 8c3010f

Please sign in to comment.