Exemplo n.º 1
0
def debug_wiki(path):
    from bookish.grammars.wiki import blocks
    from bookish.parser import parser, rules

    pages = flaskapp.get_wikipages(manager.app)
    src = wikipages.condition_string(pages.content(path))

    ctx = wikipages.bootstrap_context()
    i = 0
    blist = []
    t = util.perf_counter()
    missed = False
    while rules.streamend.accept(src, i, ctx)[0] is parser.Miss:
        tt = util.perf_counter()
        out, newi = blocks(src, i, ctx)
        tt = util.perf_counter() - tt

        if not isinstance(out, dict):
            lines = parser.Lines(src)
            line, col = lines.line_and_col(i)
            print("Miss at line", line, "column", col, "(char %s)" % i)
            print(repr(src[i:i+10]))
            missed = True
            break

        i = newi
        blist.append((tt, out.get("type"),
                      repr(functions.string(out.get("text"))[:40])))
    t = util.perf_counter() - t
    print("%0.06f" % t)

    if not missed:
        blist.sort(reverse=True)
        for tt, typename, txt in blist:
            print("%0.06f" % tt, typename, txt)
Exemplo n.º 2
0
def trace(path):
    from bookish.grammars.wiki import blocks
    from bookish.parser import parser, rules

    pages = flaskapp.get_wikipages(manager.app)
    src = pages.content(path)
    src = wikipages.condition_string(src)
    lines = parser.Lines(src)

    ctx = wikipages.bootstrap_context()
    i = 0
    while not rules.streamend.at_end(src, i):
        out, newi = blocks(src, i, ctx)
        print(i, out, newi)
        if not isinstance(out, dict):
            line, col = lines.line_and_col(i)
            print("Miss at line", line, "column", col, "(char %s)" % i)
            print(repr(src[i:]))
            break
        if newi == i:
            line, col = lines.line_and_col(i)
            print("Stall at line", line, "column", col, "(char %s)" % i)
            print(repr(src[i:]))
            break
        i = newi
Exemplo n.º 3
0
def index_usages(prefix="/examples/nodes/", touchfile=None):
    pages = flaskapp.get_wikipages(manager.app)
    logger = manager.app.logger

    changed = _index_usages(pages, logger)

    if changed and touchfile:
        # Touch the change file to indicate something changed.
        # This is to help the Makefile
        open(touchfile, "a").close()
Exemplo n.º 4
0
def missing(images=False, links=False, unused=False, prefix="/", verbose=False):
    if not (images or links or unused):
        images = links = unused = True

    pages = flaskapp.get_wikipages(manager.app)
    all_images = set()
    used_images = set()
    for path in get_prefixed_paths(pages, prefix):
        if paths.extension(path) in (".png", ".jpg", ".jpeg", ".gif"):
            all_images.add(path)

        if not pages.is_wiki_source(path):
            continue

        if verbose:
            print(path)

        printed = False
        json = pages.json(path)
        for link in functions.find_links(json):
            value = link["value"]
            scheme = link.get("scheme")

            if value.startswith("#") or scheme in ("Icon", "Smallicon", "Largeicon"):
                continue

            fullpath = link.get("fullpath")
            if not fullpath:
                continue

            if pages.is_wiki(fullpath):
                fullpath = pages.source_path(fullpath)
            exists = pages.exists(fullpath)

            isimage = scheme in ("Image", "Anim")
            if isimage:
                used_images.add(fullpath)

            if exists:
                continue

            if (images and isimage) or (links and not isimage):
                if not verbose and not printed:
                    print(path)
                    printed = True
                print("    ", value, "  ", fullpath)

    if unused:
        unused_images = all_images - used_images
        bytes = 0
        for imgpath in sorted(unused_images):
            size = pages.size(imgpath)
            bytes += size
            print("Unused image:", imgpath, size)
        print(len(unused_images), "unused images (", bytes, ") out of", len(all_images))
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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()
Exemplo n.º 8
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)

Exemplo n.º 9
0
def get_pages():
    from bookish import flaskapp

    return flaskapp.get_wikipages(bookish_app)
Exemplo n.º 10
0
def html(path):
    pages = flaskapp.get_wikipages(manager.app)
    print(pages.html(path))
Exemplo n.º 11
0
def clear_cache():
    pages = flaskapp.get_wikipages(manager.app)
    empty_cache(pages)
Exemplo n.º 12
0
def parse_page(path, **kwargs):
    pages = flaskapp.get_wikipages(manager.app)
    jsondata = pages.json(path, **kwargs)
    return jsondata
Exemplo n.º 13
0
def prewarm(prefix="/"):
    pages = flaskapp.get_wikipages(manager.app)
    for path in pages.store.list_all(prefix):
        print(path)
        _ = pages.json(path, save_to_cache=True)
Exemplo n.º 14
0
def index_info():
    pages = flaskapp.get_wikipages(manager.app)
    indexer = flaskapp.get_indexer(manager.app)
    indexer.dump(pages)