We now introduce a database connection pool and a full implementation of our first call

In order to use our database connection, we have to make sure that psycopg2 is properly installed. To verify the installation run:
 $ python -c 'import psycopg2'
 $ echo $?
 0
 $
If your results differ you can install the library on Ubuntu GNU/Linux by running:
 $ sudo apt-get install python-psycopg2

We also introduced a shutter/config.py.example file containing our database connection
descriptor. Before running the application one has to make a copy of it and provide
credential matching the database setup:
 $ cp shutter/config.py.example shutter/config.py

It's advisible to add shutter/config.py to git ignore in order to not commit a file
with our database credentials into version control.

Next we introduce a new file shutter/service.py containing the implementation of our
actual service.

For now it only contains two methods, setup_database that stores the provided database
connection pool into a local attribute and snapshots - implementing our actual logic.

The snapshots method should return a Deferred. Since our use case for this function can be covered with a single database query we can use the adbapi runInteraction method which runs the provided function in an asynchronous way providing a Transaction (txn in the code) being equivalent in functionality to a regular psycopg2 cursor.

The _get_snapshot_urls local function just performs a query and returns all rows fetched by the database SQL driver.

Since the result of runInteraction is a Deferred, the callback a potential user of our service attached to this result will be automatically called as soon as data is available.

Next in line we change our protocol.py adding the connection pool initialization in the RemoteShutterFactory. We tell the library to use psycopg2 as the driver, the connection description from our config.py file and we set the cp_reconnect flag to true which will make adbapi attempt to reestablish connections if they drop for whatever reason.

We also initialize a new service attribute in the ShutterJSONRPCProtocol.__init__ method and remember to import our new modules: adbapi, config and Shutter.

After all the changes, we can now rerun our unit tests to confirm that the functionality we had so far didn't change in any way.