Skip to main content

repoze.bfg - Introduction and bootstrapping it on buildout

2 months without a post here .. T_T ... must .. restart .. blogging ...

Anyway, I've been poking around with repoze.bfg since last week and growing to love it by the days. Been thinking to post a blog on getting started on it but was a bit lazy .. until I saw lowkster's post about bfg at a few days ago.

Full documentation at

A little review

I love Zope Component Architecture because the modularity/reusability it offers, but Bluebream, Grok and Zope2 feels a bit big for simple web apps or for introducing ZCA to new people. Then I saw BFG.

BFG simplifies many concepts which I'm familiar with in Zope2/Zope3, and it does it without overwhelming developers with other parts of the framework. Not endorsing any type of storage backend, and giving an option between URL routing and traversal or a mix of both is a plus.

The initial base code is simple and straightforward, and there are no need to subclass any parent class when you want to create your initial project.

The starter project is as simple as:
class MyModel(object):

root = MyModel()

def get_root(request):
return root
def my_view(request):
return {'project':'helloworld'}

A registration of the view in configure.zcml:

And its template file which uses TAL compatible markup.

As the initial requirement is simple, and theres close to no enforcement on how developers supposed to write something on it, it made it easy for new people to quickly learn it and start being productive. BFG too, being something that uses many Zope concepts, can utilize many existing Zope/Z3C components out there, and if a developer know how to utilize ZCA well, what developed on a BFG project may also be componentized and reused in other frameworks.

What to know more on whats cool with BFG? .. read their Sales Pitch ;)

Installation on Buildout

Depending on your distribution, BFG might be available in your distro repository (Fedora have it). However, being a Zope/Plone developer as my main job, whenever it comes to installing python applications from pypi, I tend to prefer to use buildout to create a self-contained environment. So I'll use buildout here too.

First, if you don't have zc.buildout yet, install it using:
$ easy_install zc.buildout

Now lets create the contained environment
$ mkdir -p ~/repozebuildout/src
$ cd ~/repozebuildout

Then create a buildout.cfg file in the directory with this config:
parts =
develop =
versions = versions

recipe = zc.recipe.egg
eggs =
interpreter = python
entry-points = paster=paste.script.command:run

repoze.bfg = 1.2.1

What the buildout config will do is, it will create a buildout with repoze.bfg framework and its dependencies installed, with an interpreter script configured for the buildout environment, and a paster script.

Now initialize the buildout
$ buildout init
$ ./bin/buildout -vv

After the buildout initialization is done, you may start creating the project skeleton.

Creating your first project

There are several templates to choose from: bfg_starter, bfg_routesalchemy, bfg_alchemy, and bfg_zodb.

bfg_starter template simply give a very basic bfg skeleton to get started. Those who are familiar with Pylons/Django might want to look at bfg_routesalchemy and those who are familiar with Zope might want to look at bfg_alchemy and bfg_zodb.

For this example, i'll just create a simple project using bfg_starter template.

cd src/
../bin/paster create -t bfg_starter helloworld
cd ..

then , edit buildout.cfg and add helloworld into the eggs section:

eggs =

afterward, rerun buildout
./bin/buildout -vvv

Once that is done, you may start the server using:
./bin/paster serve src/helloworld/helloworld.ini

Now you can start developing on BFG!. Read the documentation to get you started in developing on BFG.

Happy hacking :D

Popular posts from this blog

Adding simple popup to Plone frontpage

Here is a little guide for those who want to add a simple popup to the Plone frontpage for some purpose (eg: announcements, advertisements, etc).

Create a basic html file containing the content you want to appear in the popup. Upload it into $PLONE_SITE/portal_skins/custom (as Page Template) and for the sake of this example, name it popup.html

Afterward, create a Javascript file with your Pop-Up loader script. For example , this script:

function popup(mylink, windowname)
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
href=mylink.href;, windowname, 'width=220,height=400,scrollbars=no');
return false;

popup('popup.html', 'My Popup');

Also upload this file into $PLONE_SITE/portal_skins/custom (as Page Template too). For this example, name it as popup.js

Afterward, in $PLONE_SITE/portal_javascripts , add popup.js as a new script into portal_javascripts…

HOWTO: Mirroring Yum repositories using Yum-Utils

As promised before in one of my previous post, a Howto on how to mirror and manage yum repositories using some of the utilities in yum-utils.

The first step is, well, of course, is to get yum-utils from fedora repository
yum install yum-utils

Reposync is a utility for mirroring and synchronizing local copy of a yum/rpmmetadata repository.

This utility is very useful if you wanted to make a yum repository mirror. Before this, I used "wget -R -np -N" but this method is a little bit tedious and it doesnt work with repos that didn't use directory listing. Plus, it also download together additional site stuff that I don't need/want and it doesn't verify checksum of the downloaded packages.

Mirroring a repo using this utility is easy, just execute this command
reposync -r <repoid> -a <arch> -n
and the repo will be mirrored in a folder with the same name of the repoid in the directory you executed the command. Eg: you executed the command in /mnt/storage/mi…

Consolidated community site infrastructure on Plone

In Inigo, we believe in helping out local FOSS communities and help them grow. We help out in community events where we can, present FOSS talks, and provide some platforms for local communities to grow. One of such platform is our consolidated community site infrastructure on Plone.

The system/infra and its components was originally developed for the Fedora Malaysia website, while keeping in mind to keep it generic enough so that other communities could use the same components for their own community sites. The infra is already at a usable state, and we can add new sites easily with just a few clicks.

Features in this consolidated infra are:
Document/Content management (Plone built-in)Calendar system (powered by solgema.fullcalendar addon)Conference/BarCamp system (powered by collective.conference addon, which was developed for FUDCon Kuala Lumpur 2012)Blog (powered by Products.Scrawl)Simple yet powerful theming engine (powered by Diazo) - Check out Diazo, you'l…