
    7j[              
           d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZ ddlmZm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 Zd Z e	j:                  ddeed       e	j:                  ddd       e	j:                  ddded       e	j:                  ddddd        e	j<                  d!e	j>                  j@                  jB                  rd"nd#      eed$                                                  Z"y)%zbKeyboard information script.

Compile an info.json for a particular keyboard and pretty-print it.
    N)FilesCompleter)Draft202012ValidatorRefResolver
validators)cli)Path)automagic_keyboardautomagic_keymap)	info_json)InfoJSONEncoder)compile_schema_store)keyboard_completerkeyboard_folder)is_keyboardnormpathc                 \    | j                   d   fd}t        j                  | d|i      S )z[Extends Draft202012Validator to remove properties that aren't specified in the schema.
    
propertiesc              3      K   t        |j                               D ]
  }||vs||=   | |||      D ]  }|  y w)N)listkeys)	validatorr   instanceschemaproperrorvalidate_propertiess         S/home/hanthebot/chat/keyboard/qmk_firmware/lib/python/qmk/cli/generate/info_json.pyremove_additional_propertiesz7pruning_validator.<locals>.remove_additional_properties   sQ     ) 	#D:%TN	# )J&Q 	EK	s   !??)
VALIDATORSr   extend)validator_classr   r   s     @r   pruning_validatorr"      s6     *44\B _|=Y.Z[[    c                     t               }t        t              }|d   }t        j                  |d   |      } |||      j
                  } ||       S )z7Remove the API-only properties from the info.json.
    zqmk.keyboard.v1)store)resolver)r   r"   r   r   from_schemavalidate)kb_info_jsonschema_storepruning_draft_validatorr   r&   r   s         r   strip_info_jsonr,   $   sX     ()L/0DE+,F&&|4E'Fl[H'BKKI\""r#   z-kbz
--keyboardzKeyboard to show info for.)type	completerhelpz-kmz--keymapz&Show the layers for a JSON keymap too.)r/   z-oz--outputTz>Write the output the specified file, overwriting if necessary.)arg_onlyr.   r/   z-owz--overwrite
store_truezFOverwrite the existing info.json. (Overrides the location of --output))r0   actionr/   z*Generate an info.json file for a keyboard.F)hiddenc                    | j                   j                  j                  s9| j                  j	                  d       | j
                  d   j                          yt        | j                   j                  j                        s;| j                  j	                  d| j                   j                  j                         y| j                  j                  rt        d      | j                   j                  j                  z  dz  j                         }| j                  j                  r| j                  j                  d|       || j                  _        t        | j                   j                  j                        }t        |       t!        j"                  |dt$        d	
      }| j                  j                  r|t'        | j                  j                        }|j)                         r| j                  j                  d|       |j+                  |dz          | j                  j-                  d|       yt/        |       y)z.Generate an info.json file for a keyboard
    zMissing parameter: --keyboardinfoFzInvalid keyboard: "%s"	keyboardsz	info.jsonz*Overwriting user supplied --output with %s   T)indentcls	sort_keyszOverwriting output file %s
zWrote info.json to %s.N)configgenerate_info_jsonkeyboardlogr   subcommands
print_helpr   args	overwriter   resolveoutputwarningr   r,   jsondumpsr   r   exists
write_textr5   print)r   output_pathr)   info_json_texts       r   r=   r=   0   s    ::((1156**,szz44==>.

0M0M0V0VW
xxK(3::+H+H+Q+QQT__hhj88??GGOOH+V% SZZ::CCDLL!ZZQOW[\N
xxsxx/GGOO8+F~45-{; 	nr#   )#__doc__rG   argcomplete.completersr   
jsonschemar   r   r   milcr   pathlibr   qmk.decoratorsr	   r
   qmk.infor   qmk.json_encodersr   qmk.json_schemar   qmk.keyboardr   r   qmk.pathr   r   r"   r,   argument
subcommandr<   user	developerr=    r#   r   <module>r^      s     1 D D   ?  - 0 < *\ 	# e\CU\xyeZ&NOdJ  OO  Pe]T,  NV  W<cjjooNgNgUmqr&   s W P P z&r#   