def _get_uri_(self,uri,ignore_errors=False,followlinks=True): out_uris = [] if isinstance(uri,basestring): uris = [uri] else: uris = uri assert(len(uri) >= 1) for uri in uris: ret = None ## check if the path exists locally if os.path.exists(uri) or '://' in uri: ret = uri ## if it does not exist, check the directory locations else: if env.DIR_DATA is not None: if isinstance(env.DIR_DATA,basestring): dirs = [env.DIR_DATA] else: dirs = env.DIR_DATA for directory in dirs: for filepath in locate(uri,directory,followlinks=followlinks): ret = filepath break if ret is None: if not ignore_errors: raise(ValueError('File not found: "{0}". Check env.DIR_DATA or ensure a fully qualified URI is used.'.format(uri))) else: if not os.path.exists(ret) and not ignore_errors: raise(ValueError('Path does not exist and is likely not a remote URI: "{0}". Set "ignore_errors" to True if this is not the case.'.format(ret))) out_uris.append(ret) return(out_uris)
def get_uri(uri, ignore_errors=False, followlinks=True): out_uris = [] if isinstance(uri, six.string_types): uris = [uri] else: uris = uri assert (len(uri) >= 1) for uri in uris: ret = None # check if the path exists locally if os.path.exists(uri) or '://' in uri: ret = uri # if it does not exist, check the directory locations else: if env.DIR_DATA is not None: if isinstance(env.DIR_DATA, six.string_types): dirs = [env.DIR_DATA] else: dirs = env.DIR_DATA for directory in dirs: for filepath in locate(uri, directory, followlinks=followlinks): ret = filepath break if ret is None: if not ignore_errors: msg = 'File not found: "{0}". Check env.DIR_DATA or ensure a fully qualified URI is used.'.format( uri) ocgis_lh(logger='request', exc=ValueError(msg)) else: if not os.path.exists(ret) and not ignore_errors: msg = 'Path does not exist and is likely not a remote URI: "{0}". Set "ignore_errors" to True if ' \ 'this is not the case.' msg = msg.format(ret) ocgis_lh(msg, exc=ValueError(msg)) out_uris.append(ret) return out_uris