bin/openquake:

Moved some DB queries to the `engine` module.
export/core:

Modify the @makedirsdeco to support either a file path or file-like.
export/hazard, export/risk:

Massive refactoring of export functions. Changes include:

- Updated parameter names (instead of `target_dir`, just `target`)
- Updated return value interface; instead of a list of things, each
  function just returns one thing.
  - If the target was a path, return the path to the exported file
  - If the target was a file-like, return the same object
bin/openquake:

Updated the export function to expect a single output per export
function call, instead of a list.
tests/export/hazard_test, tests/export/risk_test:

Made hazard and risk export tests pass with the new export interface
and associated renaming.
qa_tests:

Updated all relevant QA tests to use the new export interface.

All tests pass.
calcs/base:

Fixed exported filename collection in the base `export` method.
export/risk:

Fixed a couple of risk export functions, where the `dest` parameter (a
path or file-like) was being passed as a keyword arg--which was not
appropriate, since this is a positional argument and makes refactoring/
renaming error-prone.
tests/export/risk_test:

Fixed a few broken tests, due to some slight changes in the calls to
the various output serializers.
export/hazard:

PEP8/pyflakes cleanup.
export/risk:

s/target_dir/target/g
utils:

Added FileWrapper context manager util class.
export/hazard:

Updated a few isinstance checks (on file paths) to check if the var is
either basestring or buffer.
export/risk:

Refactored the way export targets are handled. There is no longer tight
coupling with filepaths/the filesystem. Now, we can specify any kind of
target, either a filepath or a file-like object.
tests/export/risk_test:

Updated tests per some refactoring to the risk export implementation.
export/risk:

Removed an obsolete bit of docstring.
Merge pull request #1231 from larsbutler/export-to-path-or-file

Export to path or file (not just path)

[r=matley] [f=1202259]