ó
öD1Uc           @   sh   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l m Z d   Z d   Z d   Z	 d   Z
 d S(   i˙˙˙˙N(   t
   productionc          C   s¨   t  j j t j d  }  t  j j t j d  } t t j d  ` } t j | j	    } | d } | d } t
 | | |   t
 | | |  t | | |  Wd  QXd  S(   Ns   mapnik2normal.xmls   mapnik2print.xmlt   rt   DB_NAME_DATA_MASTERt   DB_NAME_DATA_UPDATE(   t   ost   patht   joint   settingst   MAPNIK_STYLESt   opent   SECRETS_PATHt   jsont   loadst   readt   _replacet   _update_db_names(   t   normal_style_filenamet   print_style_filenamet   fst   secretst
   old_mastert
   new_master(    (    s,   /var/www/html/osm_data_processing/swap_db.pyt   swap_db   s    

c         C   s   | |  d <| |  d <t  j d } t | d  ) } | j t j |  d d d d
  Wd  QXt j | t  j  t j	 |  d  S(   NR   R   s   .tmpt   wt   indenti   t
   separatorst   ,s   : (   R   s   : (
   R   R
   R	   t   writeR   t   dumpst   shutilt   copyfileR   t   remove(   R   R   t
   new_updatet   tmp_patht   f(    (    s,   /var/www/html/osm_data_processing/swap_db.pyR      s    

(c         C   s>   | d } t  |  | | |  t j | |  t j |  d  S(   Ns   .tmp(   t   _sedR   R   R   R   (   t
   old_stringt
   new_stringt   filenamet   tmp_filename(    (    s,   /var/www/html/osm_data_processing/swap_db.pyR   &   s    
c      
   C   s1   t  j d j d |  d | d | d |  d t S(   NsJ   sed -e "s~{old_string}~{new_string}~" {input_filename} > {output_filename}R$   R%   t   input_filenamet   output_filenamet   shell(   t
   subprocesst   check_outputt   formatt   True(   R$   R%   R(   R)   (    (    s,   /var/www/html/osm_data_processing/swap_db.pyR#   -   s
    	(   R   R   R   R+   t   mtbmap.settingsR    R   R   R   R   R#   (    (    (    s,   /var/www/html/osm_data_processing/swap_db.pyt   <module>   s   			