def finddir(name): """Find some OCRopus-related resource by looking in a bunch off standard places. (This needs to be integrated better with setup.py and the build system.)""" local = getlocal() path = name if os.path.exists(path) and os.path.isdir(path): return path path = local+name if os.path.exists(path) and os.path.isdir(path): return path _,tail = os.path.split(name) path = tail if os.path.exists(path) and os.path.isdir(path): return path path = local+tail if os.path.exists(path) and os.path.isdir(path): return path raise IOError("file '"+path+"' not found in . or %s" % getlocal())
def findfile_old(name, error=1): """Find some OCRopus-related resource by looking in a bunch off standard places. (FIXME: The implementation is pretty adhoc for now. This needs to be integrated better with setup.py and the build system.)""" local = getlocal() path = name if os.path.exists(path) and os.path.isfile(path): return path path = local + name if os.path.exists(path) and os.path.isfile(path): return path path = local + "/gui/" + name if os.path.exists(path) and os.path.isfile(path): return path path = local + "/models/" + name if os.path.exists(path) and os.path.isfile(path): return path path = local + "/words/" + name if os.path.exists(path) and os.path.isfile(path): return path _, tail = os.path.split(name) path = tail if os.path.exists(path) and os.path.isfile(path): return path path = local + tail if os.path.exists(path) and os.path.isfile(path): return path if error: raise IOError("file '" + path + "' not found in . or /usr/local/share/ocropus/") else: return None
def finddir(name): """Find some OCRopus-related resource by looking in a bunch off standard places. (This needs to be integrated better with setup.py and the build system.)""" local = getlocal() path = name if os.path.exists(path) and os.path.isdir(path): return path path = local+name if os.path.exists(path) and os.path.isdir(path): return path _,tail = os.path.split(name) path = tail if os.path.exists(path) and os.path.isdir(path): return path path = local+tail if os.path.exists(path) and os.path.isdir(path): return path raise FileNotFound("file '"+path+"' not found in . or /usr/local/share/ocropus/")
def findfile(name,error=1): """Find some OCRopus-related resource by looking in a bunch off standard places. (FIXME: The implementation is pretty adhoc for now. This needs to be integrated better with setup.py and the build system.)""" local = getlocal() path = name if os.path.exists(path) and os.path.isfile(path): return path path = os.path.join(local,name) if os.path.exists(path) and os.path.isfile(path): return path path = os.path.join(local,"gui",name) if os.path.exists(path) and os.path.isfile(path): return path path = os.path.join(local,"models",name) if os.path.exists(path) and os.path.isfile(path): return path path = os.path.join(local,"words",name) if os.path.exists(path) and os.path.isfile(path): return path _,tail = os.path.split(name) path = tail if os.path.exists(path) and os.path.isfile(path): return path path = local+tail if os.path.exists(path) and os.path.isfile(path): return path if error: raise IOError("file '"+path+"' not found in . or %s" % getlocal()) else: return None
def findfile_old(name,error=1): """Find some OCRopus-related resource by looking in a bunch off standard places. (FIXME: The implementation is pretty adhoc for now. This needs to be integrated better with setup.py and the build system.)""" local = getlocal() path = name if os.path.exists(path) and os.path.isfile(path): return path path = local+name if os.path.exists(path) and os.path.isfile(path): return path path = local+"/gui/"+name if os.path.exists(path) and os.path.isfile(path): return path path = local+"/models/"+name if os.path.exists(path) and os.path.isfile(path): return path path = local+"/words/"+name if os.path.exists(path) and os.path.isfile(path): return path _,tail = os.path.split(name) path = tail if os.path.exists(path) and os.path.isfile(path): return path path = local+tail if os.path.exists(path) and os.path.isfile(path): return path if error: raise FileNotFound("file '"+path+"' not found in . or /usr/local/share/ocropus/") else: return None
else: return args class OcropusFileNotFound: """Some file-not-found error during OCROpus processing.""" def __init__(self,fname): self.fname = fname def __str__(self): return "<OcropusFileNotFound "+self.fname+">" data_paths = [ ".", os.path.join('.','models'), os.path.join('.','data'), os.path.join('.','gui'), os.path.join(getlocal(),"models"), os.path.join(getlocal(),"data"), os.path.join(getlocal(),"gui"), getlocal(), ] def ocropus_find_file(fname): """Search for OCRopus-related files in common OCRopus install directories (as well as the current directory).""" if os.path.exists(fname): return fname for path in data_paths: full = os.path.join(path,fname) if os.path.exists(full): return full raise OcropusFileNotFound(fname)