#!/usr/bin/python
from __future__ import print_function
import rb
import rhythmdb

class FileOrganizer(rb.Plugin):
	class RDBEntry(object):
		"""Our attributes are RhythmDB information."""

		def __init__(self, rdb, song):
			self.rdb = rdb
			self.song = song

		def __getattr__(self, prop):
			p = getattr(rhythmdb, "PROP_"+prop.upper())
			return self.rdb.entry_get(self.song, p)

	def activate(self, shell):
		"""This is called when we're activated or RhythmBox starts."""

		print("activating...")

		self.new_path = "{0.artist}/{0.album}/{0.track_number} - {0.title}.mp3"
		self.shell = shell
		self.rdb = shell.get_property("db")

		self.organize()

	def deactivate(self, shell):
		"""This is called when we're deactivated or RhythmBox exits."""

		print("deactivating")

		del self.shell, self.rdb

	def organize(self):
		"""Rename all the music in our database based on its metadata."""

		def organize_entry(entry):
			"""We're needed because RhythmDB doesn't support the iteration
			protocol."""

			s = type(self).RDBEntry(self.rdb, entry)
			uri = entry.get_playback_uri()

			if not uri.startswith("file://"):
				print("ignoring " % uri)
				return
			else:
				new_path = self.new_path.format(s)
				print("%r -> %r" % (uri, new_path))

		self.rdb.entry_foreach(organize_entry)

@@ -86,41 +86,9 @@
 ass 
-FileOrganizer(rb.Plugin):%0A%09class 
+_
 RDBE
@@ -101,17 +101,16 @@
 bject):%0A
-%09
 %09%22%22%22Our 
@@ -146,25 +146,24 @@
 mation.%22%22%22%0A%0A
-%09
 %09def __init_
@@ -182,17 +182,16 @@
  song):%0A
-%09
 %09%09self.r
@@ -201,17 +201,16 @@
 = rdb%0A%09%09
-%09
 self.son
@@ -219,17 +219,16 @@
 = song%0A%0A
-%09
 %09def __g
@@ -249,17 +249,16 @@
  prop):%0A
-%09
 %09%09p = ge
@@ -297,17 +297,16 @@
 er())%0A%09%09
-%09
 return s
@@ -338,16 +338,48 @@
 ng, p)%0A%0A
+class FileOrganizer(rb.Plugin):%0A
 %09def act
@@ -1006,19 +1006,9 @@
 s = 
-type(self).
+_
 RDBE

Move FileOrganizer.RDBEntry to the more Pythonic _RDBEntry.