Prepare a testing instance of GeoServer.

def setup_geoserver(options):
    """Prepare a testing instance of GeoServer."""
    fast = options.get('fast', False)
    download_dir = path('downloaded')
    if not download_dir.exists():
        download_dir.makedirs()

    geoserver_dir = path('geoserver')
    geoserver_bin = path('geoserver_ext/target/geoserver.war')

    if not geoserver_bin.exists():
        geoserver_bin = download_dir / os.path.basename(ROGUE_GEOSERVER_URL)
        grab(ROGUE_GEOSERVER_URL, geoserver_bin, "geoserver binary")

    jetty_runner = download_dir / os.path.basename(JETTY_RUNNER_URL)
    grab(JETTY_RUNNER_URL, jetty_runner, "jetty runner")

    data_dir = download_dir / os.path.basename(DATA_DIR_URL)
    grab(DATA_DIR_URL, data_dir, "data dir")

    if not geoserver_dir.exists():
        geoserver_dir.makedirs()

        webapp_dir = geoserver_dir
        if not webapp_dir:
            webapp_dir.makedirs()

        print 'extracting geoserver'
        z = zipfile.ZipFile(geoserver_bin, "r")
        z.extractall(webapp_dir)

        # Set the geonode auth config to dev port 8000
        sh("perl -pi.back -e 's/localhost/localhost:8000/g;' geoserver/data/security/auth/geonodeAuthProvider/config.xml")