Example #1
0
def get_searcher():
    global bookish_searcher

    if bookish_searcher is None or not bookish_searcher.up_to_date():
        from bookish import flaskapp

        indexer = flaskapp.get_indexer(bookish_app)
        bookish_searcher = indexer.searcher()

    return bookish_searcher
Example #2
0
def textify(prefix, width=None):
    pages = flaskapp.get_wikipages(manager.app)
    txcls = flaskapp.get_textifier(manager.app, width=width)
    indexer = flaskapp.get_indexer(manager.app)
    searcher = indexer.searcher()

    for path in get_prefixed_paths(pages, prefix):
        if pages.is_wiki_source(path):
            jsondata = pages.json(path, searcher=searcher)
            output = txcls(jsondata).transform()
            print(output)
Example #3
0
def generate(dirpath, prefix="/", vars=None, longest=10, cache=True,
             nocache=False):
    pages = flaskapp.get_wikipages(manager.app)
    logger = manager.app.logger
    dirpath = _exp(dirpath)
    indexer = flaskapp.get_indexer(manager.app)
    searcher = indexer.searcher()

    if nocache:
        empty_cache(pages)

    count = 0
    largest = []

    if vars:
        vars = _parse_vars(vars)
        manager.app.config.setdefault("VARS", {}).update(vars)

    t = util.perf_counter()
    for path in get_prefixed_paths(pages, prefix):
        if not pages.is_wiki_source(path):
            continue

        logger.debug("Generating %s", path)
        count += 1

        tt = util.perf_counter()
        html = pages.html(path, save_to_cache=cache, searcher=searcher)
        tt = util.perf_counter() - tt

        htmlpath = paths.basepath(path) + ".html"
        filepath = os.path.join(dirpath, htmlpath[1:])

        # Make sure the destination directory exists, then create the file.
        parentdirpath = os.path.dirname(filepath)
        if not os.path.exists(parentdirpath):
            os.makedirs(parentdirpath)
        with open(filepath, "w") as f:
            f.write(html.encode("utf8"))

        # Keep track of slowest pages
        if len(largest) < longest or tt > largest[0][0]:
            if len(largest) >= longest:
                largest.pop(0)
            bisect.insort(largest, (tt, path))
    totaltime = util.perf_counter() - t

    logger.info("Generated %s files in %s secs", count, totaltime)
    logger.info("Average %s sec per page", totaltime / count)
    logger.info("Top %s longest times:")
    for gentime, path in largest:
        logger.info("%s | %03.04f secs ", path, gentime)
Example #4
0
def search(query, limit=None, stored=False):
    import pprint

    indexer = flaskapp.get_indexer(manager.app)
    q = indexer.query()
    q.set(query)
    if limit:
        q.set_limit(int(limit))

    for hit in q.search():
        if stored:
            pprint.pprint(dict(hit))
        else:
            print(hit["path"], hit["title"])
Example #5
0
def index(prefix="/", clean=False, nocache=False, option=None, touchfile=None,
          usages=False):
    pages = flaskapp.get_wikipages(manager.app)
    indexer = flaskapp.get_indexer(manager.app)
    logger = manager.app.logger

    if usages:
        _index_usages(pages, logger)

    if option:
        key, value = option.split("=", 1)
        value = util.pyliteral(value, fallback_to_string=False)
        indexer.set_option(key, value)

    if nocache:
        empty_cache(pages)

    changed = indexer.update(pages, prefix=prefix, clean=clean)

    if changed and touchfile:
        # Touch the change file to indicate something changed.
        # This is to help the Makefile
        open(touchfile, "a").close()
Example #6
0
from houdinihelp.server import get_houdini_app
from bookish import flaskapp
app = get_houdini_app(config_file=config, use_houdini_path=False)
pages = flaskapp.get_wikipages(app)
indexer = flaskapp.get_indexer(app)
indexer.update(pages, clean=False)

Example #7
0
def index_info():
    pages = flaskapp.get_wikipages(manager.app)
    indexer = flaskapp.get_indexer(manager.app)
    indexer.dump(pages)