Convert to app factory pattern

This required a lot of refactoring throughout the codebase. Some smaller
changes were made as well (e.g. ElementTree -> cElementTree), but these aren't
worth documenting.

The fabfile/ stuff is a little up in the air. I've had several problems getting
fabric to act within an app context, even with app.app_context() .