示例#1
0
文件: common.py 项目: beanyh/yeobaek
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
示例#3
0
文件: common.py 项目: xepost/ocropy
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/")
示例#4
0
文件: common.py 项目: beanyh/yeobaek
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
示例#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
示例#6
0
文件: common.py 项目: beanyh/yeobaek
    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)