
    7jM                        d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 d Z
dZd Zd	 Zd
 Zd Zd Z e	j"                  ddeddd       e	j"                  ddeddd       e	j"                  ddddd       e	j"                  ddddd       e	j"                  ddddd       e	j$                  d       d!                                           Zy)"zNThis script automates the copying of the default keymap into your own keymap.
    N)QMK_FIRMWARE)normpath)clic                  :    t        | dt        j                  i| y )Nfile)printsysstderr)argskwargss     T/home/hanthebot/chat/keyboard/qmk_firmware/lib/python/qmk/cli/chibios/confmigrate.pyeprintr      s    	4+cjj+F+    a  /* Copyright 2020 QMK
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * This file was auto-generated by:
 *    `qmk chibios-confmigrate -i {0} -r {1}`
 */

#pragma once
c                    t        | dd      5 }|j                         }t        j                  dt        j                        }t        j                  dt        j
                        }|j                  |      }g i d}|D ]\  }|j                  |      }|d   j                  |j                  d             |j                  d	      |d
   |j                  d      <   ^ |cd d d        S # 1 sw Y   y xY w)Nrutf-8encodingz#(?m)^#\s*define\s+(?:.*\\\r?\n)*.*$zB^#\s*define\s+(?P<name>[a-zA-Z0-9_]+(\([^\)]*\))?)\s*(?P<value>.*))keysdictr   namevaluer   )
openreadrecompile	MULTILINEDOTALLfindallsearchappendgroup)	filepathfcontentdefine_searchvalue_searchdefine_matchesdefinesdefine_matchvalue_matchs	            r   collect_definesr,   *   s    	hg	. !&&(

#I2<<Xzz"gikirirs&..w7r** 	TL&--l;KFO"";#4#4V#<=9D9J9J79SGFOK--f56	T   s   CC**C3c                    g }g }g }|d   D ]  }|| d   vs|j                  |        | d   D ]  }|| d   vs|j                  |        | d   D ]5  }||d   v s| d   |   |d   |   k7  s|j                  || d   |   f       7 |||fS )Nr   r   )r!   )
input_defsreference_defsnot_present_in_inputnot_present_in_referenceto_overridekeys         r   check_diffsr4   9   s    !Kf% j(( '',
 &! j(( '',
 &! ?.((Z-?-DW]H^_bHc-cZ%7%<=>? -/GHHr   c                 f   t        t        j                  t        j                  j
                  j                  t              t        j                  j                  j                  t                    |       | D ](  }t        d|d   d|d   |       t        d|       * t        d|       y )Nr   #define r        z#include_next <chconf.h>
	r   file_headerformatr   r   inputrelative_tor   	referencer2   outfileoverrides      r   migrate_chconf_hrD   O   s    	+

SXX^^77EsxxGYGYGeGefrGs
t  |C  D  !hqk:Ibw  

&W5r   c                 f   t        t        j                  t        j                  j
                  j                  t              t        j                  j                  j                  t                    |       | D ](  }t        d|d   d|d   |       t        d|       * t        d|       y )Nr6   r7   r   r8   r9   r:   z#include_next <halconf.h>
r;   rA   s      r   migrate_halconf_hrF   Y   s    	+

SXX^^77EsxxGYGYGeGefrGs
t  |C  D  !hqk:Ibw  

'g6r   c                    t        t        j                  t        j                  j
                  j                  t              t        j                  j                  j                  t                    |       t        d|       | D ];  }t        d|d   z  |       t        d|d   d|d   |       t        d|       = y )	Nr6   z#include_next <mcuconf.h>
z	#undef %sr   r7   r8   r9   r:   r;   rA   s      r   migrate_mcuconf_hrH   c   s    	+

SXX^^77EsxxGYGYGeGefrGs
t  |C  D	
'g6  kXa[)8!hqk:Ibw r   z-iz--inputTzSpecify input config file.)typearg_onlyrequiredhelpz-rz--referencez-Specify the reference file to compare againstz-oz--overwrite
store_truez+Overwrites the input file during migration.)rJ   actionrL   z-dz--deletezCIf the file has no overrides, migration will delete the input file.z-fz--forcezVRe-migrates an already migrated file, even if it doesn't detect a full ChibiOS config.zgGenerates a migrated ChibiOS configuration file, as a result of comparing the input against a referencec           
      z   t        | j                  j                        }t        | j                  j                        }t	        ||      \  }}}t        |      dkD  r t        d       |D ]  }t        d|z          t        |      dkD  r t        d       |D ]  }t        d|z          t        |      dk(  rLt        d       | j                  j                  r*t        j                  | j                  j                         yyt        d       |D ]a  }t        |d   dd|d	   |d      j                  d
      j                  d      d|d   j                  d
      j                  d             c t        d       | j                  j                  j                  dk(  rd|d	   v sd|d	   v s| j                  j                  rkt        |t        j                          | j                  j"                  r9t%        | j                  j                  dd      5 }t        ||       ddd       yy| j                  j                  j                  dk(  rd|d	   v sd|d	   v s| j                  j                  rkt'        |t        j                          | j                  j"                  r9t%        | j                  j                  dd      5 }t'        ||       ddd       yy| j                  j                  j                  dk(  rd|d	   v sd|d	   v s| j                  j                  rkt)        |t        j                          | j                  j"                  r9t%        | j                  j                  dd      5 }t)        ||       ddd       yyyy# 1 sw Y   yxY w# 1 sw Y   yxY w# 1 sw Y   yxY w)zuGenerates a usable ChibiOS replacement configuration file, based on a fully-defined conf and a reference config.
    r   zVKeys not in input, but present inside reference (potential manual migration required):z   %szVKeys not in reference, but present inside input (potential manual migration required):zdNo overrides found! If there were no missing keys above, it should be safe to delete the input file.zOverrides found:z>40z: r   unicode_escaper   z -> r9   z&--------------------------------------zchconf.hCHCONF_H
_CHCONF_H_)rB   wr   Nz	halconf.h	HALCONF_H_HALCONF_H_z	mcuconf.h	MCUCONF_H_MCUCONF_H_)r,   r   r>   r@   r4   lenr   deleteosremoveencodedecoder   forcerD   r	   stdout	overwriter   rF   rH   )	r   r.   r/   r2   r0   r1   r3   rC   out_files	            r   chibios_confmigraterb   n   s    !0J$SXX%7%78NDOPZ\jDkA[&(@
 1$gh' 	$C7c?#	$ #$q(gh+ 	$C7c?#	$ ;1uv88??IIchhnn%  	!"# 	yHx{N64J8TU;4W4^4^_o4p4w4wx  5A  CK  LM  CN  CU  CU  Vf  Cg  Cn  Cn  ov  Cw  x  y	y 	7888>>*,*
6@R2RVbfpqwfxVx|  }E  }E  }K  }K[#**=xx!!#((..#@ DH$[(CD D " XX^^  K/[JvDV5VZgkuv|k}Z}  BE  BJ  BJ  BP  BPk3::>xx!!#((..#@ EH%k8DE E " XX^^  K/[JvDV5VZgkuv|k}Z}  BE  BJ  BJ  BP  BPk3::>xx!!#((..#@ EH%k8DE E " BP/D DE EE Es$   NN%?N1N"%N.1N:)__doc__r   r	   rZ   qmk.constantsr   qmk.pathr   milcr   r   r<   r,   r4   rD   rF   rH   argument
subcommandrb    r   r   <module>rj      s   	 
 	 &  ,4I,67  dIHtdQmndM4$  VE  FdMDLyzdJl  JO  PdI\  Ib  cyz.E { c P { F o.Er   