BrT

Musings about technology and other neat stuff

BrT random header image

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

March 31st, 2007 · 9 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: · ·

9 responses so far ↓

  • 1  tadek // Mar 31, 2007 at 10:41 am

    Wow. That’s uber-cool! I haven’t gotten to install Fuse on my Mac (recently released by Google) but now I have no excuse ;-)

  • 2  Marcel // Apr 2, 2007 at 10:39 am

    Thanks, Diego! It was surprisingly simple to set up on Gentoo: enable FUSE in the kernel, emerge fuse, and for Ruby support emerge fusefs.

    Next experiment: combine FUSE and Unison file synchronisation for offline capability.

  • 3  Marcel // Apr 4, 2007 at 6:05 pm

    No, Unison does not work yet. When it propagates an update from the offline directory to the FUSE directory, it creates a temporary file and changes permissions on it. The chmod step fails with the message “Function not implemented”.

    Then I tried rsync. It does not have the chmod problem. But it leaves temporary files around, one for each file, even if the file hasn’t changed. Finally the problem remains that files that were updated are moved to Drafts.

  • 4  Jason // Oct 5, 2007 at 8:48 pm

    Hey this is pretty cool… your file doesn’t list a license used for it. Do you mind if I make changes to it and post the changes if they are useful?

  • 5  Hitchhiker // Oct 5, 2007 at 8:58 pm

    Jason: by all means, go ahead! Consider it as freeware. I haven’t had time to continue developing it, but I’d be happy to see new features added to it.

  • 6 Jason E. Ormes - Linux, OS X, programming, tips, and other stuff that I find interesting…. » First release of modifications to metaweblogfs.rb // Oct 9, 2007 at 6:42 pm

    [...] to use the built in editor to Wordpress as I much prefer to use offline editors. I stumbled across metaweblogfs.rb created by Diego Zamboni. I asked if I could make some modifications and I am greatful that he has [...]

  • 7 Jason E. Ormes - Linux, OS X, programming, tips, and other stuff that I find interesting…. » Question for the small masses that read this blog // Oct 9, 2007 at 8:28 pm

    [...] I’d like to add the ability to remove a blog post to this little script. metaweblogfs.rb [...]

  • 8 /* Litchis ? */ » Blog Archive » Ruby, Trac and XML-RPC // Nov 19, 2007 at 5:25 pm

    [...] few days ago, I was just wandering in blogs, and found this. A couple of minutes later, I installed the XML-RPC plugin on my Trac repository. After some issues [...]

  • 9 pascal.germroth.name::blog::archive » Fun with FUSE // May 19, 2008 at 10:46 am

    [...] unbelievably easy to implement new and awesome filesystems for Linux, such as for example MetaweblogFS, which allows me to write this post using cat > $title && touch $title [...]