BrT

Musings about technology and other neat stuff

BrT random header image

MetaweblogFS: Ruby, FUSE, XML-RPC, oh my

March 31st, 2007 · Comments

I have been wanting to learn [Ruby](http://www.ruby-lang.org/en/), and
I recently started playing with [FUSE](http://fuse.sourceforge.net/), for
creating file systems in user space in Unix.

And a couple of days ago, [Marcel](http://marcel-g.homeip.net/) asks
me if I knew of any blogging client that would allow complete offline
editing of the posts as files, and then synchronize them. That was
enough to plant the seed in my mind…

So I give you [MetaWeblogFS](/brt/files/metaweblogfs.rb), a quite
simple Ruby script that uses the
[FuseFS](http://rubyforge.org/projects/fusefs/) Ruby-FUSE bindings to
mount a filesystem in which your blog posts (for any blog that
implements the MetaWeblog API, including Wordpress) appear as
files. The filenames are the titles, and you can edit posts simply by
editing the files, and create new posts by creating new files.

Here is how to use it:

ruby metaweblogfs.rb mountdirectory password host path user [blogid]

You can specify values for all the parameters at the beginning of the
script. It will connect to your blog, read the list of posts, and
create a file system in the mountpoint you specified. You can edit or
create new files there. Press Ctrl-C to finish the script and unmount
the filesystem.

This was in total about two hours of coding, having _never_ written a
Ruby program before. FUSE is just too cool, and the Ruby bindings make
it very easy to use.

Some tips, issues and (maybe) future development:

* Posts are saved as drafts by default (you can modify this at the top
of the script). To set a post to “published”, simply “touch” the
file.

* “touch reload” to reload the list of posts (it is automatically reloaded after you modify or create files).

* FuseFS doesn’t allow to specify the mtime or atime of a file, so
post creation dates cannot be used as the file timestamp.

* For now it’s just a flat directory. Could be made to show
directories for categories, or time ranges, etc.

* New posts are created in the default category. I guess this could be fixed by having a directory structure representing categories, so you could create new files in the correct one.

Credit where credit is due: I took the XML-RPC code from [crafterm's
weblog](http://crafterm.net/blog/articles/2006/09/22/blog-content-migration-from-movabletype-to-typo-using-xml-rpc),
and borrowed a lot from the FuseFS sample programs.

I’m writing this post in Emacs, directly on my blog’s mounted
directory :-)

Tags: · ·