Use proper SafeCopy instances everywhere

SafeCopy can reuse Serialize instances, but doing so is not a good idea
because it means they are not robust to representation changes.

We had quite a number of SafeCopy instances that were directly reusing
Serialize instances. So introduce _v0 variants and use the SafeCopy upgrade
mechanism. The old _v0 variants still use Serialize to some extent, but now
there are no more Serialize instances for current (ie not _v0) types.
Shutdown cleanly on SIGTERM

We get this for free for SIGINT, but have to do the equiv manually for
SIGTERM. This should fix the problem where the acid state lock files are
not removed on shutdown.
Turns out we were not using the binary package
Split the server test suite into two, to avoid needing email by default

The user self-registration feature uses email, so needs local outgoing email
on the host running the test, via the /sbin/sendmail interface. Many hosts do
not have local email, including our own build bot. So we split the test suite
into two parts: the main part which does not use self-registration and a
separate test of self-registration specifically. The self-registration test is
not enabled by default but can be enabled with:
  cabal configure --enable-tests --flag=test-create-user
This should fix our build bot.
Fix package search problem where very common term returned no results

For performance reasons, we try to limit the number of documents we
have to score. For example if you used lots of terms covering lots of
documents, we could end up having to rank them all. So we use a common
trick which is to sort the terms by the number of documents they appear
in, and then just take the first few, until we have plenty -- but not
too many -- docs to rank. Since terms that occur in many docs
contribute little to the score, we can ignore docs that only have the
frequent terms and not the less common ones.

The problem was that if the first (ie least common) term already put us
over our limit then we would end up returning no documents at all! This
happened in practice for 'process' and 'time' (both terms occur in the
description of many packages, as is or as the stem, e.g. 'processing').
So now we take the first one no matter what. So now we should always
get some results, unless you search for one of the stop words.

Fixes #64.
Fix build with base-4.6
Add an "explain" mode for the package search

Should be useful for tweaking the search paramaters.

Example:
http://hackage.haskell.org/packages/search?terms=process+monitor&explain
Add non-term features to the search engine

But not yet used for any such features
Include more haddock markup in package search

In the package description, index search terms appearing as
haddock-markup identifiers or single-token code markup. For example
allow 'ByteString' and @text@ markup as search index terms (after
stripping off the markup obviously).
Add download counts to the search ranking

No parameter tuning yet.
Add download count to search explain/tweak page

So can see the values and can adjust the weighting.
Minor code tidy-up in build client
Add a --dry-run flag to the build client

So it does not actually upload anything. Helps with testing/debugging.
Significant overhaul of the builder client

Manages the build reports and log files itself now, and uploads them
itself. Keeps a more persistent record of what it has done, including
log files of why things failed.

Should now reliably upload build reports and log files.

Other simplifications and code tidy up. Could still do with more tidying
to reuse existing utils better (like the http utils & Cabal's process
functions).
Add an option to the builder client to prune unnecessary haddock files

In particular, to remove all the frames stuff that doesn't work.
Fix parsing of build reports

In the Either monad, fail is now error not Left. Was causing a 500 error
rather than a proper 400 error.
More sensible http response codes for docs and build reports
Do actually terminate when we get SIGTERM

The problem with catching all exceptions...
Use foldVersionRange' in MemSize VersionRange instance

Cabal deprecates using explicit constructors, instead recommending
foldVersionRange'.
Merge pull request #161 from chrisdone/use_foldversion

Use foldVersionRange' in MemSize VersionRange instance