# Path: mtbmap/settings/production.py
# DEBUG = False
# TEMPLATE_DEBUG = DEBUG
# ALLOWED_HOSTS = ['.mtbmap.cz', '.tchor.fi.muni.cz']
# OSM2PGSQL_CACHE = 24576
# SERVER_EMAIL = 'server_message@mtbmap.cz'
# EMAIL_SUBJECT_PREFIX = '[mtbmap.cz admin] '


import os
import json
import shutil
import subprocess
from mtbmap.settings import production as settings
# -*- coding: utf-8 -*-

# Global imports

# Local imports


def swap_db():
    normal_style_filename = os.path.join(settings.MAPNIK_STYLES, 'mapnik2normal.xml')
    print_style_filename = os.path.join(settings.MAPNIK_STYLES, 'mapnik2print.xml')
    with open(settings.SECRETS_PATH, 'r') as fs:
        secrets = json.loads(fs.read())
        old_master = secrets['DB_NAME_DATA_MASTER']
        new_master = secrets['DB_NAME_DATA_UPDATE']

        _replace(old_master, new_master, normal_style_filename)
        _replace(old_master, new_master, print_style_filename)
        _update_db_names(secrets, new_master, old_master)


def _update_db_names(secrets, new_master, new_update):

    secrets['DB_NAME_DATA_MASTER'] = new_master
    secrets['DB_NAME_DATA_UPDATE'] = new_update

# Path: mtbmap/settings/production.py
# DEBUG = False
# TEMPLATE_DEBUG = DEBUG
# ALLOWED_HOSTS = ['.mtbmap.cz', '.tchor.fi.muni.cz']
# OSM2PGSQL_CACHE = 24576
# SERVER_EMAIL = 'server_message@mtbmap.cz'
# EMAIL_SUBJECT_PREFIX = '[mtbmap.cz admin] '


# Path: osm_data_processing/swap_db.py
import os
import json
import shutil
import subprocess
from mtbmap.settings import production as settings

# -*- coding: utf-8 -*-

# Global imports

# Local imports


def swap_db():
    normal_style_filename = os.path.join(settings.MAPNIK_STYLES, 'mapnik2normal.xml')
    print_style_filename = os.path.join(settings.MAPNIK_STYLES, 'mapnik2print.xml')
    with open(settings.SECRETS_PATH, 'r') as fs:
        secrets = json.loads(fs.read())
        old_master = secrets['DB_NAME_DATA_MASTER']
        new_master = secrets['DB_NAME_DATA_UPDATE']

        _replace(old_master, new_master, normal_style_filename)
        _replace(old_master, new_master, print_style_filename)
        _update_db_names(secrets, new_master, old_master)


def _update_db_names(secrets, new_master, new_update):

    secrets['DB_NAME_DATA_MASTER'] = new_master
    secrets['DB_NAME_DATA_UPDATE'] = new_update

    tmp_path = settings.SECRETS_PATH + '.tmp'