PyBlosxom plug-in: latest_comments.py

latest_comments.py

You may have noticed a new feature on Copia. This one was inspired by a feature from Burningbird (Shelley Powers' blog). Copia now lists the last ten comments posted, with links to the author and the referenced entry. This weekend I wrote another plug-in latest_comments.py, which implements this feature. from the doc string:

Generates a template variable, $latest_comments, which contains a listing of the most recent comments to the Weblog, in the form:

<div class="comment-link">
Author 1
on
Entry 1 title
</div>
<div class="comment-link">
Author 2
on
Entry 2 title
</div>

This plugin requires the comments plug-in (comments.py).

This module supports the following, optional config parameter:

latest_comment_count - the number of comments to include in the
                         output (default 5)

It's taken a beating over the past few days, and held up OK. James Governor exposed a Unicode bug when he tracked back to an entry with a title using high characters. That's all fixed now (it took down Copia for a little while).

I release it under Creative Commons Attribution-ShareAlike 2.0 License (I really need to iron out the CC licensing throughout Copia).)

Let me know what you think. I need to get all these plug-ins into CVS and into the PyBlosxom registry one of these days.

[Uche Ogbuji]

via Copia

XsltRenderer for PyBlosxom

XsltRenderer.py

The XSLT renderer is a renderer that takes any output from the default renderer (i.e. after processing using flavors), and applies an XSLT, using the result. If you have handy XSLTs that start with XML vocabularies such as Atom or XHTML, you can create such output just as you currently do in PyBlosxom, by appliying your flavor of choice. You can then use the XSLTs you have to produce additional types of output quite easily.

I used this to add an RSS 1.0 feed here on Copia. It starts with the Atom flavor, and uses Antonio Cavedoni's XSLT to translate the atom to RSS 1.0. Taking this approach in general made thinsg a lot easier for me. I went from nothing to RSS 1.0 feed in about two hours of hacking, which included a lot of learning about the plug-in API. Based on the hassles that other PyBlosxom feed projects seemed to be working through, I think the detour through XSLT was quite valuable. It made it easier to lean on the shoulders of others outside the PyBlosxom community.

Anyway some other sample uses:

  • A very simple "plain text" feed. Start with the Atom flavor and then use a tiny (5 lines or so) XSLT to strip all tags
  • An alternative, image-free view. Start with a flavor that generates XHTML, then apply a tiny (5 lines or so) XSLT to strip all images

There is one configuration option for this plug-in-- xslt_trigger_suffix. See the module header doc for more info.

[Uche Ogbuji]

via Copia

Copia gets RSS 1.0, courtesy XSLT

I added RSS 1.0 feeds to Copia yesterday. It was a fun Sunday evening hack project, and even though parts of PyBlosxom still make me scratch my head, I'm in even more awe of its hackability.

It seems RSS 1.0 has always been a sketchy area for PyBlosxom. Because RSS 1.0 essentially needs 2 modes, the item list and the item details, you can't emit it linearly, and so you can't use a PyBlosxom flavor, as with RSS 0.91 or atom. I found some discussion of an RSS 1.0 from time to time in the archives, including this Perl port, but nothing readily usable, so I had to roll my own.

But what does an XML head do when faced with such a task? He runs a simple equation: existing atom flavor for PyBlosxom + plenty of Atom to RSS 1.0 XSLT transforms out there = decision to implement an XsltRenderer for PyBlosxom. The XsltRenderer can take a flavor's output and run it through an XSLT to produce the final output.

More on that in a follow-up item, but for now, I've added the whole site feed to the feed discovery convention in the HTML headers, and also to the right hand listing. There are also topic-specific feeds for all keywords.

So, for example, here is the RSS 1.0 Python feed, and here is the XML Atom feed. Note: we use lowercase for keywords on Copia.

[Uche Ogbuji]

via Copia

Posting to Pyblosxom with WebDAV

"Pyblosxom: Posting with WebDAV" -- The industrious Eric Gaumer again

Yeah, blog posting to WebDAV occurred to me at some point when I was pulling out my hair (psych. No hair) about the horrid state of blog posting clients. But it seemed too much additional cranial load given everything else I was having to learn and hack on (been a while since I've used mod_dav). Nice to see Eric has it working, and I might head in that direction some day. First of all, though, I might consider working on a plug-in to accept posts via e-mail. Incedentally, Kingsley Idehen was also just telling me today that his blog uses SQLX over WebDAV (I'm still trying to get my head around that). Hey. writing the Web starts at home.

[Uche Ogbuji]

via Copia

Holy xmlrpc_metaweblog barf

So the title of my last entry was "Holy trésor retrouvé!". Well, that's how you find yet another bug in xmlrpc_metaweblog.py. My first clue something was amiss when I clicked the "Post Entry" button in BloGTK was that I didn't get the usual, annoying pop-up to tell me the entry had been posted. I looked at the console from which I'd launched BloGTK and I saw:

Traceback (most recent call last):   File "/usr/bin/BloGTK", line 664, in prepPost
    post.getPostInfo(self.url, self.user, self.passwd, self.system, blogID, catID, title, body, checkPublish, self.mainGlade, self.useUTF, extended, excerpt, keywords, trackbackURLS, breaks, commentsAllow, pingsAllow)
  File "/usr/lib/blogtk/post.py", line 90, in getPostInfo
    metaweblogPost(url, user, passwd, blogID, title, body, publish, mainGlade, excerpt, extended, keywords)
  File "/usr/lib/blogtk/post.py", line 167, in metaweblogPost
    confirmPost(post, mainGlade)
  File "/usr/lib/blogtk/post.py", line 184, in confirmPost
    postLabel = gtk.Label("Entry Posted. ID = " + post)
TypeError: cannot concatenate 'str' and 'bool' objects

Which usually means xmlrpc_metaweblog.py got confused and reported its confusion with an XML-RPC response of 1. I checked the Copia site and found that the result was an empty file for the entry. I didn't find any useful tracebacks server-side, and I'm out of steam for the night, so no further debugging. I just pasted the entry into vi over ssh and all was well again.

P.S. Same problem with this entry when I tried to post it. WTF? xmlrpc_metaweblog.py should be stateless, so the presumed non-ASCII in title bug shouldn't have affected further posting, should it?

[Uche Ogbuji]

via Copia

PyBlosxom permissions headaches: hand edit versus XML-RPC

Generally I use BloGTK via XML-RPC to post here. Sometimes I want to ssh in and hand edit files as well. Occasionally I want to hand create entries and maybe even edit via BloGTK. Either way, permissions become a pain in the ass. Apache runs as user $APACHEU and group $APACHEV (I'm using shell variables rather than revealing the actual names out of bootless paranoia). When I log in, I'm user $UCHE in group $OGBUJIS. Here is the rather brute way I solved part of the problem.

I set the SGID bit on all the directories to which I expect files written through pyblosxom.cgi:

chmod g+s $DATADIR chmod g+s $DATADIR/metadata chmod g+s $DATADIR/comments

I made sure the group of each was $OGBUJIS, of course. So now whenever a new file is created through XML-RPC or some other plug-in, it's created with group $OGBUJIS, and I can happily ssh in to edit as $UCHE.

This doesn't solve the converse problem of using CGI to edit files I created by hand, but this is rare enough that i just log in as root and use chown to sort things out.

Does anyone else have a better way? I thought of Apache suexec, but my past experiences with it have been nightmares of impenetrable detail.

[Uche Ogbuji]

via Copia

Copia goes down, thanks to logstats plug-in (?)

So this morning I noticed Copia was down. Requests would hang until they timed out. Apache seemed up, and running pyblosxom.cgi directly worked fine. I enabled the CGI debug line:

import cgitb; cgitb.enable()

But this didn't help. It felt like an infinite loop somewhere in the guts of processing. After fitful debugging efforts (got work piling up), I traced the problem to the logstats.py module. My approach in the end was to use py['load_plugins'] in config.py, comment out all plug-ins, and uncomment them until I found the culprit. It was really cool to uncover comments one by one and see different aspects of the site start working step by step. It really reinforces the power of PyBlosxom's "microkernel" approach. My resulting config was:

py['load_plugins'] = [
  "comments",
  "firstdaydiv",
  "keywords",
  "logrequest",
  #"logstats",
  "meta",
  "metatime",
  "pyarchives",
  "pycalendar",
  "pymarkdown",
  "trackback",
  "xmlrpc_blogger",
  "xmlrpc_metaweblog",
  "xmlrpc",
]
#The above list is only for debug purposes.  If *not* debugging,
#Uncomment the following line
#del py['load_plugins']

I'll have to check later into what;s causing logstats.py to kill the server, but other PyBlosxom users might want to take note.

[Uche Ogbuji]

via Copia

Moving to MetaWebLog API

Getting BloGTK to play nice with PyBlosxom
Updated xmlrpc_metaweblog.py for PyBlosxom, as used on Copia

Eric Gaumer and Ted Leung continue to be my main support in getting up to speed with blogging in general and PyBlosxom in particular. Thanks, guys. Always easier to go a-hacking when you have fellow hackers in the trenches with you.

So Eric's entry was a nudge to finally get MetaWebLog going on Copia. First of all, I applied his patch to BloGTK. Then I set up xmlrpc_metaweblog.py. But first I had to update it to follow my convention of storing entries within directories for each date. If anyone else would like to go with that convention, you might want to check out my custom version of xmlrpc_metaweblog.py, linked above.

I'll specify a trackback when posting, to see if it does the trick. I'll post a comment with the apparent results.

But first of all, I'll save my blog entry to a local file. I'll be doing that a lot while using BloGTK. It has exhibited a few weird, not-obviously-reproducible quirks from time to time that worry me a bit. Unfortunately, the author has apparently abandoned the 1.1. branch in favor of BloGTK2, so I guess there will be some more hacking to do. Lucky thing I know Python. Even luckier thing Eric's learning Python so rapidly. At least the BloGTK2 preview looks cleaner. I'll look forward to it.

[Uche Ogbuji]

via Copia

Serving up UTF-8 in PyBlosxom

It's 2005, people. No room for blogs and other sites without the most basic underpinnings of i18n. Turns out serving up UTF-8 from PyBlosxom is not the complete slam dunk I expected. To be fair, getting it to send UTF-8 was easy, given instructions in the config file. You want to add to your config a line such as:

py['blog_encoding'] = "utf-8"

This does cause PyBlosxom to render UTF-8 pages. But you also have to be sure the browser knows the pages are in UTF-8, or most browsers I've found will default to ISO-8859-1 and thus garble non-ASCII characters. I tried using HTML meta, by adding the following to the head template for my flavor (head.copia):

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

But this was not enough. Browsers rightly prefer to believe the HTTP content type header, so the trick lies in the content_type template for your flavor. Most HTML templates you find out there contain only text/html. You want to expand this to

text/html; charset=UTF-8

Your browser probably gives you a "page info" display of some sort with which you can check that your content type header is right. In Firefox 1.0.2 it's Tools -> Page Info or Ctrl+I. See the following example dialog:

Firefox page info dialog for Copia

[Uche Ogbuji]

via Copia