
    7j              
          d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZmZ ddlmZ dd	lmZ d
 Z ej&                  ddddg d       ej&                  ddde
e	dd       ej(                  dd      d                      Zy)z0Migrate keyboard configuration to "Data Driven"
    N)Path)dotty)cli)keyboard_completerkeyboard_folder)	info_jsonfind_info_json)InfoJSONEncoder)	json_loadc                     t        |       }t        d      }g }|j                  D ]/  }||z  }|j                  |dz         |j                  |dz         1 |D cg c]  }|j                         s| c}S c c}w )N	keyboardszconfig.hzrules.mk)r   partsappendexists)keyboardkb_dircur_dirfilesdirfiles         H/home/hanthebot/chat/keyboard/qmk_firmware/lib/python/qmk/cli/migrate.py_candidate_filesr      sv    (^F;GE|| +C-Wz)*Wz)*+
 #4TdkkmD444s   A81A8z-fz--filterTr   zFilter the performed migrations based on the supplied value. Supported format is 'KEY' located from 'data/mappings'. May be passed multiple times.)arg_onlyactiondefaulthelpz-kbz
--keyboardzThe keyboard's name)r   type	completerrequiredr   z)Migrate keyboard config to "Data Driven".)hiddenc                 `   t        t        d            }t        t        d            }i ||t        t        | j                  j                        d         }t        t        |            }t        t        | j                  j                              }t        | j                  j                        }t        t        fdj                                     }| j                  j                  rt        t        |      t        | j                  j                        z        }t        | j                  j                        t        |      z
  }|D ]!  }	| j                  j                  d|	 d       # | j                  j                  d| j                  j                   d       |D ]B  }
| j                  j                  d	|
        |
j                  d
      j                  d      }|D ]  }	t!        |      D ]  \  }}|j#                  |	 d      s|j#                  d|	 d      s0| j                  j                  d|	 d       |j%                         j'                  d      r6|j)                  |       ||   }|j%                         j'                  d      r6|j)                  |       |	   d   }||v s||   ||<     |
j+                  dj-                  |      d
       E | j                  j                  d|        |j+                  t/        j0                  |j3                         t4        d             | j                  j                  d| j                  j                   d       | j                  j                  d| j                  j                   d       y)z4Migrate keyboard configuration to "Data Driven"
    zdata/mappings/info_config.hjsonzdata/mappings/info_rules.hjsonr   c                 .    |    j                  dd      S )Nto_jsonT)get)keyinfo_maps    r   <lambda>zmigrate.<locals>.<lambda>2   s    8C=#4#4Y#E     z{fg_yellow}Skipping z as migration not possible...z&{fg_green}Migrating keyboard {fg_cyan}z{fg_green}.{fg_reset}z  Migrating file zutf-8)encoding
z =z#define  z    Migrating z...\info_keyz  Updating T)cls	sort_keysz){fg_green}Migration of keyboard {fg_cyan}z{fg_green} complete!{fg_reset}z-Verify build with {fg_yellow}qmk compile -kb z -km default{fg_reset}.N)r   r   r	   argsr   r   r   r   listfilterkeyssetloginfo	read_textsplit	enumerate
startswithrstripendswithpop
write_textjoinjsondumpsto_dictr
   )r   info_config_mapinfo_rules_maptarget_info	info_datakb_info_jsonr   r3   rejectedr%   r   file_contentsnumline
update_keyr&   s                  @r   migraterM      s     %F GHOt$DEFN4/4^4H ~chh&7&78;<Ki,-I 388#4#456L SXX../E Ex}}WXD
xxCICHHOO 445sxx'#d)3 	VCGGLL1#6STU	V GGLL=chh>O>O=PPijk  D(/08>>tD 	IC&}5 I	T??cU":.$//HSEQRBS2TGGLL>#c!:;++-006%))#.,S1 ++-006 "%%c*!)#z!:J!\10<Z0H	*-I	I 			-07C#D( GGLL;{m,-4::i&7&7&9Z^_`GGLL@ARAR@SSuvwGGLLB388CTCTBUUnopr(   )__doc__r@   pathlibr   
dotty_dictr   milcr   qmk.keyboardr   r   qmk.infor   r	   qmk.json_encodersr
   qmk.json_schemar   r   argument
subcommandrM    r(   r   <module>rY      s        < . - %
5 dJh  Rf  ge\DRdos  {Q  R;DI5q J R g5qr(   