Exemplo n.º 1
0
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())
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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/")
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
    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)