コード例 #1
0
ファイル: webapp.py プロジェクト: huanghao/bookworm
def get_item(match):
    meta = json.loads(match.document.get_data())
    if not meta['paths']:
        return

    key = meta['key']
    docpath = meta['paths'][0]
    #FIXME: hardcode here
    docpath = os.path.join('files', docpath.split('Documents/ebook/')[1])
    title = os.path.basename(docpath).replace('.', ' ').replace('_', ' ')

    item = {
        'rank': match.rank,
        'docid': match.docid,
        'filelink': docpath,
        'title': title,
        'key': key,
        }

    kpath = key_to_path(key)
    thumbpath = os.path.join(kpath, 'thumb.png')
    if os.path.exists(os.path.join(repo_path, thumbpath)):
        item['thumb'] = os.path.join('repo', thumbpath)

    metapath = os.path.join(repo_path, kpath, 'meta')
    if os.path.exists(metapath):
        item['meta'] = json.load(open(metapath))
    return item
コード例 #2
0
def main(args):
    if not os.path.isdir(args.db_path):
        logger.error('db path does not exist(%s), '
                     'please use -d to specify a correct db path' %
                     args.db_path)
        return 1
    if not os.path.isdir(args.repo_path):
        logger.error('repo path does not exist(%s), '
                     'please use -r to specify a correct repo path' %
                     args.repo_path)
        return 1

    nap = 0.
    db = DB(args.db_path)
    if args.keys:
        for key in args.keys:
            itempath = os.path.join(args.repo_path, key_to_path(key))
            logger.debug(itempath)
            db.index(key, itempath, args.force_index)
            time.sleep(nap)
    else:
        for key, itempath in Repo(args.repo_path).walk():
            logger.debug(itempath)
            db.index(key, itempath, args.force_index)
            time.sleep(nap)
コード例 #3
0
def get_item(match):
    meta = json.loads(match.document.get_data())
    if not meta['paths']:
        return

    key = meta['key']
    docpath = meta['paths'][0]
    #FIXME: hardcode here
    docpath = os.path.join('files', docpath.split('Documents/ebook/')[1])
    title = os.path.basename(docpath).replace('.', ' ').replace('_', ' ')

    item = {
        'rank': match.rank,
        'docid': match.docid,
        'filelink': docpath,
        'title': title,
        'key': key,
    }

    kpath = key_to_path(key)
    thumbpath = os.path.join(kpath, 'thumb.png')
    if os.path.exists(os.path.join(repo_path, thumbpath)):
        item['thumb'] = os.path.join('repo', thumbpath)

    metapath = os.path.join(repo_path, kpath, 'meta')
    if os.path.exists(metapath):
        item['meta'] = json.load(open(metapath))
    return item
コード例 #4
0
ファイル: index.py プロジェクト: huanghao/bookworm
def main(args):
    if not os.path.isdir(args.db_path):
        logger.error('db path does not exist(%s), '
        'please use -d to specify a correct db path' % args.db_path)
        return 1
    if not os.path.isdir(args.repo_path):
        logger.error('repo path does not exist(%s), '
        'please use -r to specify a correct repo path' % args.repo_path)
        return 1

    nap = 0.
    db = DB(args.db_path)
    if args.keys:
        for key in args.keys:
            itempath = os.path.join(args.repo_path, key_to_path(key))
            logger.debug(itempath)
            db.index(key, itempath, args.force_index)
            time.sleep(nap)
    else:
        for key, itempath in Repo(args.repo_path).walk():
            logger.debug(itempath)
            db.index(key, itempath, args.force_index)
            time.sleep(nap)