'Restore GeoServer Catalog'

def restore_geoserver_backup(self, settings, target_folder):

    url = settings.OGC_SERVER['default']['PUBLIC_LOCATION']
    user = settings.OGC_SERVER['default']['USER']
    passwd = settings.OGC_SERVER['default']['PASSWORD']
    geoserver_bk_file = os.path.join(target_folder, 'geoserver_catalog.zip')
    if (not os.path.exists(geoserver_bk_file)):
        print ('Skipping    geoserver    restore:    ' + 'file    "{}"    not    found.'.format(geoserver_bk_file))
        return
    print (((("Restoring    'GeoServer    Catalog    [" + url) + "]'    into    '") + geoserver_bk_file) + "'.")
    data = {'restore': {'archiveFile': geoserver_bk_file, 'options': {}}}
    headers = {'Content-type': 'application/json'}
    r = requests.post((url + 'rest/br/restore/'), data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(user, passwd))
    error_backup = ('Could    not    successfully    restore    GeoServer    ' + 'catalog    [{}rest/br/backup/]:    {}    -    {}')
    if (r.status_code > 201):
        try:
            gs_backup = r.json()
        except ValueError:
            raise ValueError(error_backup.format(url, r.status_code, r.text))
        gs_bk_exec_id = gs_backup['restore']['execution']['id']
        r = requests.get((((url + 'rest/br/restore/') + str(gs_bk_exec_id)) + '.json'), auth=HTTPBasicAuth(user, passwd))
        if (r.status_code == 200):
            try:
                gs_backup = r.json()
            except ValueError:
                raise ValueError(error_backup.format(url, r.status_code, r.text))
            gs_bk_progress = gs_backup['restore']['execution']['progress']
            print gs_bk_progress
        raise ValueError(error_backup.format(url, r.status_code, r.text))
    else:
        try:
            gs_backup = r.json()
        except ValueError:
            raise ValueError(error_backup.format(url, r.status_code, r.text))
        gs_bk_exec_id = gs_backup['restore']['execution']['id']
        r = requests.get((((url + 'rest/br/restore/') + str(gs_bk_exec_id)) + '.json'), auth=HTTPBasicAuth(user, passwd))
        if (r.status_code == 200):
            gs_bk_exec_status = gs_backup['restore']['execution']['status']
            gs_bk_exec_progress = gs_backup['restore']['execution']['progress']
            gs_bk_exec_progress_updated = '0/0'
            while ((gs_bk_exec_status != 'COMPLETED') and (gs_bk_exec_status != 'FAILED')):
                if (gs_bk_exec_progress != gs_bk_exec_progress_updated):
                    gs_bk_exec_progress_updated = gs_bk_exec_progress
                r = requests.get((((url + 'rest/br/restore/') + str(gs_bk_exec_id)) + '.json'), auth=HTTPBasicAuth(user, passwd))
                if (r.status_code == 200):
                    try:
                        gs_backup = r.json()
                    except ValueError:
                        raise ValueError(error_backup.format(url, r.status_code, r.text))
                    gs_bk_exec_status = gs_backup['restore']['execution']['status']
                    gs_bk_exec_progress = gs_backup['restore']['execution']['progress']
                    print ((str(gs_bk_exec_status) + '    -    ') + gs_bk_exec_progress)
                    time.sleep(3)
                else:
                    raise ValueError(error_backup.format(url, r.status_code, r.text))
        else:
            raise ValueError(error_backup.format(url, r.status_code, r.text))
