Ejemplo n.º 1
0
def cb_filelist(args):
    req = args["request"]

    pyhttp = req.getHttp()
    data = req.getData()
    config = req.getConfiguration()

    if not pyhttp["PATH_INFO"].startswith("/" + TRIGGER):
        return

    data[INIT_KEY] = 1
    datadir = config["datadir"]
    data['root_datadir'] = config['datadir']
    staticdir = config.get("staticdir", config['datadir'])

    staticdir = staticdir.replace("/", os.sep)
    if not staticdir[-1] == os.sep:
        staticdir = staticdir + os.sep

    page_name = pyhttp["PATH_INFO"][len("/" + TRIGGER)+1:]

    if not page_name:
        return

    # FIXME - need to do a better job of sanitizing
    page_name = page_name.replace(os.sep, "/")

    if not page_name:
        return

    if page_name[-1] == os.sep:
        page_name = page_name[:-1]
    if page_name.find("/") > 0:
        page_name = page_name[page_name.rfind("/"):]

    # if the page has a flavour, we use that.  otherwise
    # we default to the static flavour
    page_name, flavour = os.path.splitext(page_name)
    if flavour:
        data["flavour"] = flavour[1:]

    # we build our own config dict for the fileentry to kind of
    # fake it into loading this file correctly rather than
    # one of the entries.
    newdatadir = staticdir
    # config["datadir"] = newdatadir

    ext = tools.what_ext(data["extensions"].keys(), staticdir + page_name)

    if not ext:
        return []

    data['root_datadir'] = page_name + '.' + ext
    data['bl_type'] = 'file'
    filename = staticdir + page_name + "." + ext

    if not os.path.isfile(filename):
        return []

    fe = FileEntry(req, filename, staticdir)
    # now we evaluate python code blocks
    body = fe.getData()
    body = eval_python_blocks(req, body)
    body = "<!-- STATIC PAGE START -->\n\n" + body + "<!-- STATIC PAGE END -->\n"
    fe.setData(body)

    fe["absolute_path"] = TRIGGER
    fe["fn"] = page_name
    fe["file_path"] = TRIGGER + "/" + page_name
    fe["template_name"] = "static"

    data['blog_title_with_path'] = config.get("blog_title", "") + " : " + fe.get("title", "")

    # set the datadir back
    config["datadir"] = datadir

    return [fe]
Ejemplo n.º 2
0
def cb_filelist(args):
    req = args["request"]

    pyhttp = req.get_http()
    data = req.get_data()
    config = req.get_configuration()
    page_name = None

    if not (is_trigger(pyhttp, config) or is_frontpage(pyhttp, config)):
        return

    data[INIT_KEY] = 1
    datadir = config["datadir"]
    data['root_datadir'] = config['datadir']
    pagesdir = config["pagesdir"]

    pagesdir = pagesdir.replace("/", os.sep)
    if not pagesdir[-1] == os.sep:
        pagesdir = pagesdir + os.sep

    pathinfo = pyhttp.get("PATH_INFO", "")
    path, ext = os.path.splitext(pathinfo)
    if pathinfo == "/" or path == "/index":
        page_name = "frontpage"
    else:
        page_name = pyhttp["PATH_INFO"][len("/" + TRIGGER) + 1:]

    if not page_name:
        return

    # FIXME - need to do a better job of sanitizing
    page_name = page_name.replace(os.sep, "/")

    if not page_name:
        return

    if page_name[-1] == os.sep:
        page_name = page_name[:-1]
    if page_name.find("/") > 0:
        page_name = page_name[page_name.rfind("/"):]

    # if the page has a flavour, we use that.  otherwise
    # we default to the default flavour.
    page_name, flavour = os.path.splitext(page_name)
    if flavour:
        data["flavour"] = flavour[1:]

    ext = tools.what_ext(data["extensions"].keys(), pagesdir + page_name)

    if not ext:
        return []

    data['root_datadir'] = page_name + '.' + ext
    data['bl_type'] = 'file'
    filename = pagesdir + page_name + "." + ext

    if not os.path.isfile(filename):
        return []

    fe = FileEntry(req, filename, pagesdir)
    # now we evaluate python code blocks
    body = fe.get_data()
    body = eval_python_blocks(req, body)
    body = ("<!-- PAGES PAGE START -->\n\n" +
            body +
            "<!-- PAGES PAGE END -->\n")
    fe.set_data(body)

    fe["absolute_path"] = TRIGGER
    fe["fn"] = page_name
    fe["file_path"] = TRIGGER + "/" + page_name
    fe["template_name"] = "pages"

    data['blog_title_with_path'] = (
        config.get("blog_title", "") + " : " + fe.get("title", ""))

    # set the datadir back
    config["datadir"] = datadir

    return [fe]
Ejemplo n.º 3
0
def cb_filelist(args):
    req = args["request"]

    pyhttp = req.getHttp()
    data = req.getData()
    config = req.getConfiguration()

    if not pyhttp["PATH_INFO"].startswith("/" + TRIGGER):
        return

    data[INIT_KEY] = 1
    datadir = config["datadir"]
    data['root_datadir'] = config['datadir']
    staticdir = config.get("staticdir", config['datadir'])

    staticdir = staticdir.replace("/", os.sep)
    if not staticdir[-1] == os.sep:
        staticdir = staticdir + os.sep

    page_name = pyhttp["PATH_INFO"][len("/" + TRIGGER) + 1:]

    if not page_name:
        return

    # FIXME - need to do a better job of sanitizing
    page_name = page_name.replace(os.sep, "/")

    if not page_name:
        return

    if page_name[-1] == os.sep:
        page_name = page_name[:-1]
    if page_name.find("/") > 0:
        page_name = page_name[page_name.rfind("/"):]

    # if the page has a flavour, we use that.  otherwise
    # we default to the static flavour
    page_name, flavour = os.path.splitext(page_name)
    if flavour:
        data["flavour"] = flavour[1:]

    # we build our own config dict for the fileentry to kind of
    # fake it into loading this file correctly rather than
    # one of the entries.
    newdatadir = staticdir
    # config["datadir"] = newdatadir

    ext = tools.what_ext(data["extensions"].keys(), staticdir + page_name)

    if not ext:
        return []

    data['root_datadir'] = page_name + '.' + ext
    data['bl_type'] = 'file'
    filename = staticdir + page_name + "." + ext

    if not os.path.isfile(filename):
        return []

    fe = FileEntry(req, filename, staticdir)
    # now we evaluate python code blocks
    body = fe.getData()
    body = eval_python_blocks(req, body)
    body = "<!-- STATIC PAGE START -->\n\n" + body + "<!-- STATIC PAGE END -->\n"
    fe.setData(body)

    fe["absolute_path"] = TRIGGER
    fe["fn"] = page_name
    fe["file_path"] = TRIGGER + "/" + page_name
    fe["template_name"] = "static"

    data['blog_title_with_path'] = config.get(
        "blog_title", "") + " : " + fe.get("title", "")

    # set the datadir back
    config["datadir"] = datadir

    return [fe]
Ejemplo n.º 4
0
def cb_filelist(args):
    req = args["request"]

    pyhttp = req.get_http()
    data = req.get_data()
    config = req.get_configuration()
    page_name = None

    if not (is_trigger(pyhttp, config) or is_frontpage(pyhttp, config)):
        return

    data[INIT_KEY] = 1
    datadir = config["datadir"]
    data['root_datadir'] = config['datadir']
    pagesdir = config["pagesdir"]

    pagesdir = pagesdir.replace("/", os.sep)
    if not pagesdir[-1] == os.sep:
        pagesdir = pagesdir + os.sep

    pathinfo = pyhttp.get("PATH_INFO", "")
    path, ext = os.path.splitext(pathinfo)
    if pathinfo == "/" or path == "/index":
        page_name = "frontpage"
    else:
        page_name = pyhttp["PATH_INFO"][len("/" + TRIGGER) + 1:]

    if not page_name:
        return

    # FIXME - need to do a better job of sanitizing
    page_name = page_name.replace(os.sep, "/")

    if not page_name:
        return

    if page_name[-1] == os.sep:
        page_name = page_name[:-1]
    if page_name.find("/") > 0:
        page_name = page_name[page_name.rfind("/"):]

    # if the page has a flavour, we use that.  otherwise
    # we default to the default flavour.
    page_name, flavour = os.path.splitext(page_name)
    if flavour:
        data["flavour"] = flavour[1:]

    ext = tools.what_ext(data["extensions"].keys(), pagesdir + page_name)

    if not ext:
        return []

    data['root_datadir'] = page_name + '.' + ext
    data['bl_type'] = 'file'
    filename = pagesdir + page_name + "." + ext

    if not os.path.isfile(filename):
        return []

    fe = FileEntry(req, filename, pagesdir)
    # now we evaluate python code blocks
    body = fe.get_data()
    body = eval_python_blocks(req, body)
    body = ("<!-- PAGES PAGE START -->\n\n" + body +
            "<!-- PAGES PAGE END -->\n")
    fe.set_data(body)

    fe["absolute_path"] = TRIGGER
    fe["fn"] = page_name
    fe["file_path"] = TRIGGER + "/" + page_name
    fe["template_name"] = "pages"

    data['blog_title_with_path'] = (config.get("blog_title", "") + " : " +
                                    fe.get("title", ""))

    # set the datadir back
    config["datadir"] = datadir

    return [fe]
Ejemplo n.º 5
0
def cb_filelist(args):
    """
    This handles kicking off wbgwiki functionality if we see a
    url that we handle.
    """
    req = args["request"]

    pyhttp = req.getHttp()
    config = req.getConfiguration()
    pathinfo = pyhttp["PATH_INFO"]

    if not pathinfo.startswith("/" + TRIGGER):
        return

    logger = tools.getLogger()

    data = req.getData()
    data[INIT_KEY] = 1
    datadir = config["datadir"]
    data['root_datadir'] = config['datadir']
    wikidir = config.get("wikidir", config['datadir'])

    # convert the / to os.sep so that we can use os.path stuff.
    wikidir = wikidir.replace("/", os.sep)
    if not wikidir.endswith(os.sep):
        wikidir = wikidir + os.sep

    page_name = pathinfo[len("/" + TRIGGER) + 1:]

    if not page_name:
        return

    page_name = page_name.replace("/", os.sep)

    if not page_name:
        return

    if page_name.endswith(os.sep):
        page_name = page_name[:-1]

    # if the page has a flavour, we use that.  otherwise
    # we default to the wiki flavour
    page_name, flavour = os.path.splitext(page_name)
    if flavour:
        data["flavour"] = flavour[1:]

    # wikifile should hold the absolute path on the file system to
    # the wiki file we're looking at.  if it's in a parent directory
    # of wikidir, then we abort.
    wikifile = os.path.normpath(os.path.join(wikidir, page_name))
    if not wikifile.startswith(wikidir):
        logger.info("wiki file requested '%s' is not in wikidir." % wikifile)
        return []

    # we build our own config dict for the fileentry to kind of
    # fake it into loading this file correctly rather than
    # one of the entries.
    newdatadir = wikidir

    ext = tools.what_ext(data["extensions"].keys(), wikifile)

    if not ext:
        logger.info("wiki file '%s' does not exist." % wikifile)
        return []

    data['root_datadir'] = page_name + '.' + ext
    data['bl_type'] = 'file'
    wikifile = wikifile + "." + ext

    if not os.path.isfile(wikifile):
        return []

    fe = FileEntry(req, wikifile, wikidir)

    # now we evaluate python code blocks
    body = fe.getData()
    body = eval_python_blocks(req, body)
    body = "<!-- STATIC PAGE START -->\n\n%s\n<!-- STATIC PAGE END -->\n" % body

    # now we evaluate for wikilinks
    body = connect_links(config["base_url"], data["extensions"].keys(),
                         wikidir, body)

    fe.setData(body)

    fe["absolute_path"] = TRIGGER
    fe["fn"] = page_name
    fe["file_path"] = TRIGGER + "/" + page_name
    fe["template_name"] = "wiki"

    data['blog_title_with_path'] = "%s : %s" % \
                   (config.get("blog_title", ""), fe.get("title_escaped", ""))

    # set the datadir back
    config["datadir"] = datadir

    return [fe]
Ejemplo n.º 6
0
def cb_filelist(args):
    """
    This handles kicking off wbgwiki functionality if we see a
    url that we handle.
    """
    req = args["request"]

    pyhttp = req.getHttp()
    config = req.getConfiguration()
    pathinfo = pyhttp["PATH_INFO"]

    if not pathinfo.startswith("/" + TRIGGER):
        return

    logger = tools.getLogger()

    data = req.getData()
    data[INIT_KEY] = 1
    datadir = config["datadir"]
    data['root_datadir'] = config['datadir']
    wikidir = config.get("wikidir", config['datadir'])

    # convert the / to os.sep so that we can use os.path stuff.
    wikidir = wikidir.replace("/", os.sep)
    if not wikidir.endswith(os.sep):
        wikidir = wikidir + os.sep

    page_name = pathinfo[len("/" + TRIGGER)+1:]

    if not page_name:
        return

    page_name = page_name.replace("/", os.sep)

    if not page_name:
        return

    if page_name.endswith(os.sep):
        page_name = page_name[:-1]

    # if the page has a flavour, we use that.  otherwise
    # we default to the wiki flavour
    page_name, flavour = os.path.splitext(page_name)
    if flavour:
        data["flavour"] = flavour[1:]

    # wikifile should hold the absolute path on the file system to
    # the wiki file we're looking at.  if it's in a parent directory
    # of wikidir, then we abort.  
    wikifile = os.path.normpath(os.path.join(wikidir, page_name))
    if not wikifile.startswith(wikidir):
        logger.info("wiki file requested '%s' is not in wikidir." % wikifile)
        return []

    # we build our own config dict for the fileentry to kind of
    # fake it into loading this file correctly rather than
    # one of the entries.
    newdatadir = wikidir

    ext = tools.what_ext(data["extensions"].keys(), wikifile)

    if not ext:
        logger.info("wiki file '%s' does not exist." % wikifile)
        return []

    data['root_datadir'] = page_name + '.' + ext
    data['bl_type'] = 'file'
    wikifile = wikifile + "." + ext

    if not os.path.isfile(wikifile):
        return []

    fe = FileEntry(req, wikifile, wikidir)

    # now we evaluate python code blocks
    body = fe.getData()
    body = eval_python_blocks(req, body)
    body = "<!-- STATIC PAGE START -->\n\n%s\n<!-- STATIC PAGE END -->\n" % body

    # now we evaluate for wikilinks
    body = connect_links(config["base_url"],
                         data["extensions"].keys(),
                         wikidir,
                         body)

    fe.setData(body)

    fe["absolute_path"] = TRIGGER
    fe["fn"] = page_name
    fe["file_path"] = TRIGGER + "/" + page_name
    fe["template_name"] = "wiki"

    data['blog_title_with_path'] = "%s : %s" % \
                   (config.get("blog_title", ""), fe.get("title_escaped", ""))

    # set the datadir back
    config["datadir"] = datadir

    return [fe]