def cb_filelist(args): # handles /trigger/tag to show all the entries tagged that # way req = args["request"] pyhttp = req.get_http() data = req.get_data() config = req.get_configuration() trigger = "/" + config.get("tags_trigger", "tag") if not pyhttp["PATH_INFO"].startswith(trigger): return datadir = config["datadir"] tagsfile = get_tagsfile(config) tagsdata = loadfile(tagsfile) tag = pyhttp["PATH_INFO"][len(trigger) + 1:] filelist = tagsdata.get(tag, []) if not filelist: tag, ext = os.path.splitext(tag) filelist = tagsdata.get(tag, []) if filelist: data["flavour"] = ext[1:] from Pyblosxom.entries import fileentry entrylist = [fileentry.FileEntry(req, e, datadir) for e in filelist] # sort the list by mtime entrylist = [(e._mtime, e) for e in entrylist] entrylist.sort() entrylist.reverse() entrylist = [e[1] for e in entrylist] return entrylist
def makeEntry(filename, request): """ @param filename: filename of matching entry @type filename: string @param request: the Request object @type request: Request """ config = request.getConfiguration() return fileentry.FileEntry(request, filename, config['datadir'])
def get_entries(request, registrydir, entries): items = [ fileentry.FileEntry(request, m, registrydir, registrydir) for m in entries ] for mem in items: desc = mem["body"] if len(desc) > 100: desc = desc[:100] + "..." mem["body"] = fix(mem["body"]) mem["short_body"] = fix(desc) return items
def build_entry(request, entry, registrydir, fix_body=True): f = fileentry.FileEntry(request, entry, registrydir, registrydir) summary = f.get("summary", f["title"]) if len(summary) > 200: summary = summary[:200] + "..." if fix_body: f["body"] = fix(f["body"]) f["summary"] = summary tags = f.get("registrytags", "") f["registrytags"] = " ".join([ '<span class="registry-tag">%s</span>' % tag for tag in tags.split(", ") if tag ]) return f
def cb_filelist(args): from Pyblosxom.pyblosxom import blosxom_truncate_list_handler from Pyblosxom import tools # handles /trigger/tag to show all the entries tagged that # way req = args["request"] pyhttp = req.get_http() data = req.get_data() config = req.get_configuration() trigger = "/" + config.get("tags_trigger", "tag") if not pyhttp["PATH_INFO"].startswith(trigger): return datadir = config["datadir"] tagsfile = get_tagsfile(config) tagsdata = loadfile(tagsfile) tag = pyhttp["PATH_INFO"][len(trigger) + 1:] filelist = tagsdata.get(tag, []) if not filelist: tag, ext = os.path.splitext(tag) filelist = tagsdata.get(tag, []) if filelist: data["flavour"] = ext[1:] from Pyblosxom.entries import fileentry entrylist = [fileentry.FileEntry(req, e, datadir) for e in filelist] # sort the list by mtime entrylist = [(e._mtime, e) for e in entrylist] entrylist.sort() entrylist.reverse() entrylist = [e[1] for e in entrylist] data["truncate"] = config.get("truncate_tags", True) args = {"request": req, "entry_list": entrylist} entrylist = tools.run_callback("truncatelist", args, donefunc=lambda x: x != None, defaultfunc=blosxom_truncate_list_handler) return entrylist
def buildtags(command, argv): """Builds the tags index. """ import config datadir = config.py.get("datadir") if not datadir: raise ValueError("config.py has no datadir property.") sep = config.py.get("tags_separator", ",") tagsfile = get_tagsfile(config.py) from Pyblosxom import pyblosxom from Pyblosxom import tools from Pyblosxom.entries import fileentry data = {} # register entryparsers so that we parse all possible file types. data["extensions"] = tools.run_callback( "entryparser", {"txt": pyblosxom.blosxom_entry_parser}, mappingfunc=lambda x, y: y, defaultfunc=lambda x: x) req = pyblosxom.Request(config.py, {}, data) # grab all the entries in the datadir filelist = tools.walk(req, datadir) entrylist = [fileentry.FileEntry(req, e, datadir) for e in filelist] tags_to_files = {} for mem in entrylist: tagsline = mem["tags"] if not tagsline: continue tagsline = [t.strip() for t in tagsline.split(sep)] for t in tagsline: tags_to_files.setdefault(t, []).append(mem["filename"]) savefile(tagsfile, tags_to_files) return 0
def buildtags(command, argv): """Command for building the tags index.""" import config datadir = config.py.get("datadir") if not datadir: raise ValueError("config.py has no datadir property.") sep = config.py.get("tags_separator", ",") tagsfile = get_tagsfile(config.py) from Pyblosxom.pyblosxom import blosxom_entry_parser, Pyblosxom from Pyblosxom import tools from Pyblosxom.entries import fileentry # build a Pyblosxom object, initialize it, and run the start # callback. this gives entry parsing related plugins a chance to # get their stuff together so that they work correctly. p = Pyblosxom(config.py, {}) p.initialize() req = p.get_request() tools.run_callback("start", {"request": req}) # grab all the entries in the datadir filelist = tools.walk(req, datadir) entrylist = [fileentry.FileEntry(req, e, datadir) for e in filelist] tags_to_files = {} for mem in entrylist: tagsline = mem["tags"] if not tagsline: continue tagsline = [t.strip() for t in tagsline.split(sep)] for t in tagsline: tags_to_files.setdefault(t, []).append(mem["filename"]) savefile(tagsfile, tags_to_files) return 0
def cb_filelist(args): global registrydir, TRIGGER, SUBMITTRIGGER request = args["request"] pyhttp = request.getHttp() data = request.getData() config = request.getConfiguration() form = pyhttp["form"] if not pyhttp["PATH_INFO"].startswith(TRIGGER): return data[INIT_KEY] = 1 data['root_datadir'] = config['datadir'] # Get our URL and configure the base_url param if pyhttp.has_key('SCRIPT_NAME'): if not config.has_key('base_url'): config['base_url'] = 'http://%s%s' % (pyhttp['HTTP_HOST'], pyhttp['SCRIPT_NAME']) else: config['base_url'] = config.get('base_url', '') config['base_url'] = config['base_url'] + TRIGGER # if they haven't add a registrydir to their config file, # we pleasantly error out if not config.has_key("registry_dir"): output = "<p>\"registry_dir\" config setting is not set. Refer to documentation.</p>" return [generate_entry(request, output, "setup error")] registrydir = config["registry_dir"] # make sure the registrydir has a / at the end if registrydir[-1] != os.sep: registrydir = registrydir + os.sep # if they are doing the queue thing, then we spin them off to queue # stuff. if pyhttp["PATH_INFO"].startswith(QUEUETRIGGER): data["extensions"]["txt-"] = data["extensions"]["txt"] return handle_registry_queue(args) # if they are doing the submit thing, then we spin them off to # the submit stuff. if pyhttp["PATH_INFO"].startswith(SUBMITTRIGGER): return handle_registry_submit(args) # check if we're looking for a listing of all entries if pyhttp["PATH_INFO"] == TRIGGER: entries = tools.Walk(request, registrydir) else: dir2 = pyhttp["PATH_INFO"][len(TRIGGER):] filename, ext = os.path.splitext(dir2) if os.path.isdir(registrydir + filename): entries = tools.Walk(request, registrydir + filename) else: fn = registrydir + filename[1:] fext = tools.what_ext(data["extensions"].keys(), fn) entries = [fn + "." + fext] if ext[1:]: data["flavour"] = ext[1:] # that entry doesn't exist.... if len(entries) == 0: output = "<p>No entries of that kind registered here.</p>" return [generate_entry(request, output)] # if we're looking at a specific entry.... if len(entries) == 1: try: entry = fileentry.FileEntry(request, entries[0], registrydir, registrydir) if entries[0].find("flavours") != -1: entry["template_name"] = "flavour-story" else: entry["template_name"] = "registry-story" if entry.has_key("contrib"): entry["body"] = entry["body"] + CONTRIB_DESC return [entry] except Exception, e: output = "That plugin does not exist." return [generate_entry(request, output)]