def main(args): parser = setup_options() (options, args) = parser.parse_args(args) if len(args) not in (2, 3): usage() url = args[1] rend = None if len(args) == 3: try: rend = htmlrends.get_renderer(args[2]) except derrors.RendErr as e: die(str(e)) try: app, r = dwconfig.materialize(args[0], options) # We're one of the people who actually needs this. cfg, ms, webserv, staticstore, cachestore = r except derrors.WikiErr as e: die("dwiki error: " + str(e)) env = setup_env(url) if rend: httpcore.environSetup(env, cfg, ms, webserv, staticstore, cachestore) env['dwiki.logger'] = None rdata = httpcore.gather_reqdata(env) if 'query' not in rdata: die("URL %s is not accepted by the core" % url) ctx = context.HTMLContext(cfg, ms, webserv, rdata) if cachestore: ctx.setvar(':_cachestore', cachestore) runrend(rend, ctx) else: runwsgi(env, app)
def main(args): parser = setup_options() (options, args) = parser.parse_args(args) if len(args) not in (2, 3): usage() url = args[1] rend = None if len(args) == 3: try: rend = htmlrends.get_renderer(args[2]) except derrors.RendErr as e: die(str(e)) try: app, r = dwconfig.materialize(args[0], options) # We're one of the people who actually needs this. cfg, ms, webserv, staticstore, cachestore = r except derrors.WikiErr as e: die("dwiki error: "+str(e)) env = setup_env(url) if rend: httpcore.environSetup(env, cfg, ms, webserv, staticstore, cachestore) env['dwiki.logger'] = None rdata = httpcore.gather_reqdata(env) if 'query' not in rdata: die("URL %s is not accepted by the core" % url) ctx = context.HTMLContext(cfg, ms, webserv, rdata) if cachestore: ctx.setvar(':_cachestore', cachestore) runrend(rend, ctx) else: runwsgi(env, app)
def main(args): parser = setup_options() (options, args) = parser.parse_args(args) op = options.operation if len(args) not in (3, 4): usage() cnt = int(args[2]) url = args[1] rend = None if len(args) == 4: try: rend = htmlrends.get_renderer(args[3]) except derrors.RendErr as e: die(str(e)) try: app, r = dwconfig.materialize(args[0], options) # We're one of the people who actually needs this. cfg, ms, webserv, staticstore, cachestore = r except derrors.WikiErr as e: die("dwiki error: "+str(e)) env = setup_env(url) if options.ip6origin: # This format matches what the Fedora 17 lighttpd # puts into $REMOTE_ADDR. Your mileage may vary for # other web servers, although it's probably right # for Apache too. env['REMOTE_ADDR'] = "::1" if rend: httpcore.environSetup(env, cfg, ms, webserv, staticstore, cachestore) env['dwiki.logger'] = None rdata = httpcore.gather_reqdata(env) if 'query' not in rdata: die("URL %s is not accepted by the core" % url) ctx = context.HTMLContext(cfg, ms, webserv, rdata) if cachestore: ctx.setvar(':_cachestore', cachestore) if options.prerun: runLimited(*(options.prerun, runrend, rend, ctx)) op(cnt, runrend, rend, ctx) else: if options.prerun: runLimited(*(options.prerun, runwsgi, env, app)) op(cnt, runwsgi, env, app)
def main(args): parser = setup_options() (options, args) = parser.parse_args(args) op = options.operation if len(args) not in (3, 4): usage() cnt = int(args[2]) url = args[1] rend = None if len(args) == 4: try: rend = htmlrends.get_renderer(args[3]) except derrors.RendErr as e: die(str(e)) try: app, r = dwconfig.materialize(args[0], options) # We're one of the people who actually needs this. cfg, ms, webserv, staticstore, cachestore = r except derrors.WikiErr as e: die("dwiki error: " + str(e)) env = setup_env(url) if options.ip6origin: # This format matches what the Fedora 17 lighttpd # puts into $REMOTE_ADDR. Your mileage may vary for # other web servers, although it's probably right # for Apache too. env["REMOTE_ADDR"] = "::1" if rend: httpcore.environSetup(env, cfg, ms, webserv, staticstore, cachestore) env["dwiki.logger"] = None rdata = httpcore.gather_reqdata(env) if "query" not in rdata: die("URL %s is not accepted by the core" % url) ctx = context.HTMLContext(cfg, ms, webserv, rdata) if cachestore: ctx.setvar(":_cachestore", cachestore) if options.prerun: runLimited(*(options.prerun, runrend, rend, ctx)) op(cnt, runrend, rend, ctx) else: if options.prerun: runLimited(*(options.prerun, runwsgi, env, app)) op(cnt, runwsgi, env, app)
def m_titleindex(rend, args): """Insert a table of dates and entry titles (or relative paths for entries without titles), linking to entries and to the day pages. The table is in reverse chronological order. The single argument is the page hierarchy to do this for; if it is not specified, it is done for the current directory. The actual rendering is done by the blog::titleindex renderer.""" if len(args) > 1: return False elif len(args) == 1: dp = page_from_arg(rend, args[0]) else: dp = rend.ctx.page.curdir() if dp.type != "dir": return False rend.markComplex() nc = rend.ctx.clone_to_page(dp) rnd = htmlrends.get_renderer("blog::titles") res = rnd(nc) if not res: return False rend.addPiece(res) return True
def m_titleindex(rend, args): """Insert a table of dates and entry titles (or relative paths for entries without titles), linking to entries and to the day pages. The table is in reverse chronological order. The single argument is the page hierarchy to do this for; if it is not specified, it is done for the current directory. The actual rendering is done by the blog::titleindex renderer.""" if len(args) > 1: return False elif len(args) == 1: dp = page_from_arg(rend, args[0]) else: dp = rend.ctx.page.curdir() if dp.type != "dir": return False rend.markComplex() nc = rend.ctx.clone_to_page(dp) rnd = htmlrends.get_renderer("blog::titles") res = rnd(nc) if not res: return False rend.addPiece(res) return True
def titleindex(context): """Like _blog::blog_, except that instead of rendering entries through a template, it just displays a table of dates and entry titles (or relative paths for entries without titles), linking to entries and to the day pages. Respects VirtualDirectory restrictions. Unlike _blog::blog_, it always displays information for all applicable entries.""" if context.page.type != "dir": return '' if not context.page.displayable(): raise derrors.IntErr("undisplayable directory page") # This automatically applies restrictions. dl = context.cache_page_children(context.page) if not dl: return '' # Building a table is unfortunately much more complicated # than a <dl> would be, because we have to use <br> to separate # multiple entries for the same day instead of <td>, which means # that we have to keep track of when we need to generate one and # so on. rl = ['<table class="blogtitles">\n',] lday = None dupDict = {} rootpath = context.page.me().path # Rather than directly use a wikirend routine by importing # it, we indirect through the renderer registration. Since # either way we know a wikirend name, I figure this is no # worse. rfunc = htmlrends.get_renderer("wikitext:title:nolinks") for ts, path in dl: # FIXME: this duplication is code smell. np = context.model.get_page(path) if not np.realpage() or np.is_util() or \ not np.access_ok(context): continue pageid = np.identity() if pageid in dupDict: continue else: dupDict[pageid] = None # Do we need to generate a new row for a new day? # Our basic running state is that we are always in # a <td> for page links (except right at the start), # so we must close it off et cetera and then reopen # it. t = time.localtime(ts) plain = "%d-%02d-%02d" % (t.tm_year, t.tm_mon, t.tm_mday) if plain != lday: if lday: # Not first entry ever, so close off # the last day table row. rl.append("\n</td> </tr>\n") rl.append("<tr> <td> %s: </td> <td>\n" % \ link_to_tm(context, t, plain)) lday = plain else: # If we are the second or later entry for a # given day, we must put a <br> between ourselves # and the previous entry. rl.append("<br>\n") # As usual, we must work in a new context. nc = context.clone_to_page(np) ltitle = rfunc(nc) if not ltitle: ltitle = httputil.quotehtml(path[len(rootpath)+1:]) # We can't use htmlrends.makelink() because that would # quote the live HTML in real titles. rl.append(' <a href="%s">%s</a>' % \ (context.nurl(np), ltitle)) context.newtime(nc.modtime) # Done all; close off the <table> rl.append('\n</td></tr></table>\n') return ''.join(rl)
def titleindex(context): """Like _blog::blog_, except that instead of rendering entries through a template, it just displays a table of dates and entry titles (or relative paths for entries without titles), linking to entries and to the day pages. Respects VirtualDirectory restrictions. Unlike _blog::blog_, it always displays information for all applicable entries.""" if context.page.type != "dir": return '' if not context.page.displayable(): raise derrors.IntErr("undisplayable directory page") # This automatically applies restrictions. dl = context.cache_page_children(context.page) if not dl: return '' # Building a table is unfortunately much more complicated # than a <dl> would be, because we have to use <br> to separate # multiple entries for the same day instead of <td>, which means # that we have to keep track of when we need to generate one and # so on. rl = [ '<table class="blogtitles">\n', ] lday = None dupDict = {} rootpath = context.page.me().path # Rather than directly use a wikirend routine by importing # it, we indirect through the renderer registration. Since # either way we know a wikirend name, I figure this is no # worse. rfunc = htmlrends.get_renderer("wikitext:title:nolinks") for ts, path in dl: # FIXME: this duplication is code smell. np = context.model.get_page(path) if not np.realpage() or np.is_util() or \ not np.access_ok(context): continue pageid = np.identity() if pageid in dupDict: continue else: dupDict[pageid] = None # Do we need to generate a new row for a new day? # Our basic running state is that we are always in # a <td> for page links (except right at the start), # so we must close it off et cetera and then reopen # it. t = time.localtime(ts) plain = "%d-%02d-%02d" % (t.tm_year, t.tm_mon, t.tm_mday) if plain != lday: if lday: # Not first entry ever, so close off # the last day table row. rl.append("\n</td> </tr>\n") rl.append("<tr> <td> %s: </td> <td>\n" % \ link_to_tm(context, t, plain)) lday = plain else: # If we are the second or later entry for a # given day, we must put a <br> between ourselves # and the previous entry. rl.append("<br>\n") # As usual, we must work in a new context. nc = context.clone_to_page(np) ltitle = rfunc(nc) if not ltitle: ltitle = httputil.quotehtml(path[len(rootpath) + 1:]) # We can't use htmlrends.makelink() because that would # quote the live HTML in real titles. rl.append(' <a href="%s">%s</a>' % \ (context.nurl(np), ltitle)) context.newtime(nc.modtime) # Done all; close off the <table> rl.append('\n</td></tr></table>\n') return ''.join(rl)
def renderer(self, mo): actor = mo.group(2) if not actor.strip(): raise derrors.RendErr("badly formed renderer macro: "+mo.group(1)) rfunc = htmlrends.get_renderer(actor) return rfunc(self.context)