def autoping(name): request = Request() # Load up the cache (You can just import the base cache here) cache_driver = tools.importName('Pyblosxom.cache', config.py.get('cacheDriver', 'base')) cache = cache_driver.BlosxomCache(request, config.py.get('cacheConfig', '')) try: filename = os.path.join(config.py['datadir'], name) entryData = {} cache.load(filename) # Look for cached documents if cache.isCached(): entryData = cache.getEntry() # Cached? Try our entryparsers then. if not entryData: fileExt = re.search(r'\.([\w]+)$', filename) try: entryData = blosxom_entry_parser(filename, request) except IOError, e: tools.log(e) name = re.sub(config.py['datadir'],'',name) parser = link(name, entryData['title'].strip(), entryData['body'].strip(), config.py['blog_title']) trackback(parser) pingback(parser)
def _basic_test(self, req, filedata, output_dict): datadir = req.get_configuration()["datadir"] if not os.path.exists(datadir): os.makedirs(datadir) filename = os.path.join(datadir, "firstpost.txt") fp = open(filename, "w") fp.write(filedata) fp.close() entry_dict = blosxom_entry_parser(filename, req) self.cmpdict(output_dict, entry_dict)
def cb_filelist(args): request = args["request"] pyhttp = request.getHttp() data = request.getData() config = request.getConfiguration() baseurl = config['base_url'] trigger = config['gallerytrigger'] captions = config.get('gallerycaptions', True) columns = config.get('gallerycolumns', 4) imagepath = config['imagedata'] + trigger gallery = pyhttp["PATH_INFO"][len(trigger) + 1:] #Check if we have been started with the trigger if not pyhttp["PATH_INFO"].startswith(trigger): return #Check whether we are going to access a list of galleries, a gallery, or an image if pyhttp["PATH_INFO"] == trigger or pyhttp["PATH_INFO"] == trigger + "/" : #Find out what folders there are dirlist = os.listdir(imagepath) nicelist = [] #Generate list of galleries for x in dirlist: nicelist.append("<a href=\"" + baseurl + trigger + "/" + x + "\">" + x + "</a><br />") contents = string.join(nicelist) #Generate entry and return it absolute_path = "" fn = trigger[1:] file_path = trigger[1:] fe = entries.base.generate_entry(request, {"title": "Gallery" , "absolute_path": absolute_path , "file_path": file_path, "fn": fn } , contents, None) return [fe] elif string.find(gallery, "/") == -1: #find out what images we have abspath = imagepath + "/" + gallery + "/thumbs" if not os.path.isdir(abspath): return list = os.listdir(abspath) i = str(len(list)) #generate table with thumbnails and stringlist = [] stringlist.append("<table>") j = 1 stringlist.append("<tr>") for x in list: stringlist.append("<td><a href=\"" + baseurl + trigger + "/" + gallery + "/" + x + "\"><img src=\"" + baseurl + trigger + "/" + gallery + "/thumbs/" + x + "\" alt=\"" + x + "\" /></a><br />") if captions: stringlist.append(x) stringlist.append("</td>") j = 1 + j if j % columns == 1: stringlist.append("</tr>") stringlist.append("<tr>") stringlist.append("</tr></table>") contents = string.join(stringlist) absolute_path = trigger[1:] fn = gallery file_path = absolute_path + "/" + fn #generate entry and return it data = {"title": gallery, "absolute_path": absolute_path, "file_path": file_path, "fn": fn} # parse the header and footer for filename in ['foot.txt', 'head.txt']: path = os.path.join(config['datadir'], file_path, filename) if os.path.isfile(path): data.update(pyblosxom.blosxom_entry_parser(path, request)) data[filename] = data['body'] else: data[filename] = '' contents = '\n\n'.join([data['head.txt'], contents, data['foot.txt']]) fe = entries.base.generate_entry(request, data, contents, None) return [fe] else: # unknown URL return None
def cb_filelist(args): request = args["request"] pyhttp = request.getHttp() data = request.getData() config = request.getConfiguration() baseurl = config['base_url'] trigger = config['gallerytrigger'] captions = config.get('gallerycaptions', True) columns = config.get('gallerycolumns', 4) imagepath = config['imagedata'] + trigger gallery = pyhttp["PATH_INFO"][len(trigger) + 1:] #Check if we have been started with the trigger if not pyhttp["PATH_INFO"].startswith(trigger): return #Check whether we are going to access a list of galleries, a gallery, or an image if pyhttp["PATH_INFO"] == trigger or pyhttp["PATH_INFO"] == trigger + "/": #Find out what folders there are dirlist = os.listdir(imagepath) nicelist = [] #Generate list of galleries for x in dirlist: nicelist.append("<a href=\"" + baseurl + trigger + "/" + x + "\">" + x + "</a><br />") contents = string.join(nicelist) #Generate entry and return it absolute_path = "" fn = trigger[1:] file_path = trigger[1:] fe = entries.base.generate_entry( request, { "title": "Gallery", "absolute_path": absolute_path, "file_path": file_path, "fn": fn }, contents, None) return [fe] elif string.find(gallery, "/") == -1: #find out what images we have abspath = imagepath + "/" + gallery + "/thumbs" if not os.path.isdir(abspath): return list = os.listdir(abspath) i = str(len(list)) #generate table with thumbnails and stringlist = [] stringlist.append("<table>") j = 1 stringlist.append("<tr>") for x in list: stringlist.append("<td><a href=\"" + baseurl + trigger + "/" + gallery + "/" + x + "\"><img src=\"" + baseurl + trigger + "/" + gallery + "/thumbs/" + x + "\" alt=\"" + x + "\" /></a><br />") if captions: stringlist.append(x) stringlist.append("</td>") j = 1 + j if j % columns == 1: stringlist.append("</tr>") stringlist.append("<tr>") stringlist.append("</tr></table>") contents = string.join(stringlist) absolute_path = trigger[1:] fn = gallery file_path = absolute_path + "/" + fn #generate entry and return it data = { "title": gallery, "absolute_path": absolute_path, "file_path": file_path, "fn": fn } # parse the header and footer for filename in ['foot.txt', 'head.txt']: path = os.path.join(config['datadir'], file_path, filename) if os.path.isfile(path): data.update(pyblosxom.blosxom_entry_parser(path, request)) data[filename] = data['body'] else: data[filename] = '' contents = '\n\n'.join([data['head.txt'], contents, data['foot.txt']]) fe = entries.base.generate_entry(request, data, contents, None) return [fe] else: # unknown URL return None