+
     iM  c                  sL   R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
HtHtHtHtHtHt ^ RIHtHtHtHtHtHtHtHtHtHtHt ^ RIHt ^ RIH t H!t! ^ RI"H#t# ^ R	I$H%t%H&t& ^ R
I'H(t( ^ RI)H*t* ^ RI+H,t, ^ RI-H.t. ^ RI/H0t0H1t1 ^ RI2H3t3  ! R R]4      t4 ! R R4      t5R# )zMigration functions.

Only write changes to disk, if there actually are changes. Otherwise, file-modification
dates are destroyed.
)annotationsN)Path)IteratorTupleDictListOptional	TypedDict)EV_KEYEV_ABSEV_RELABS_XABS_YABS_RXABS_RYREL_XREL_YREL_WHEEL_HI_RESREL_HWHEEL_HI_RES)version)InputCombinationInputConfig)keyboard_layout)Mapping	UIMapping)	PathUtils)Preset)GlobalUInputs)Parser)loggerVERSION)	UserUtilsc                  s@    ] tR t^=t$ R]R&   R]R&   R]R&   R]R&   R	tR
# )ConfigzOptional[InputCombination]input_combinationstrtarget_uinputintoutput_typezOptional[int]output_code N)__name__
__module____qualname____firstlineno__Z__annotations____static_attributes__r'       E/usr/lib/python3.14/site-packages/inputremapper/configs/migrations.pyr    r    =   s    11r-   r    c                  s    ] tR t^DtR R ltR tR R ltR tR tR t	R	 t
R
 tR tR tR tR tR R ltR R ltR tR tRtR# )
Migrationsc                   V ^8  d   QhRR/# )   global_uinputsr   r'   Zformat   "r.   __annotate__Migrations.__annotate__E   s     - -} -r-   c                	s    Wn         R # )Nr2   )selfr2   s   &&r.   __init__ZMigrations.__init__E   s    ,r-   c                s    V P                  4        V P                  4        V P                  4       pV\        P                  ! R4      8  d!   V P                  4        V P                  4        V\        P                  ! R4      8  d   V P                  4        V\        P                  ! R4      8  d+   V P                  P                  4        V P                  4        V\        P                  ! R4      8  d   V P                  4        V\        P                  ! R4      8  d   V P                  4        V\        P                  ! R4      8  d   V P                  4        V\        P                  ! \        4      8  d   V P                  4        R# R# )z,Migrate config files to the current release.z0.4.0z1.2.2z1.4.0z1.4.1z1.5.0z
1.6.0-betaN)_rename_to_input_remapper_copy_to_v2config_versionr   parse_config_suffix_preset_path_mapping_keysr2   Zprepare_all_add_target_otherwise_to_else_remove_logs_convert_to_individual_mappingsr   _update_version)r8   Zv   & r.   migrateZMigrations.migrateH   s    	&&(!w}}W%%!w}}W%% w}}W%%++-w}}W%%##%w}}W%%w}}\**002 w}}W%%  " &r-   c               r0   )r1   returnz)Iterator[Tuple[os.PathLike, Dict | List]]r'   r3   r4   r.   r5   r6   j   s      	2r-   c           	   #  s  "   \         P                  P                  \        P                  ! 4       4      '       g   R# \        \        P                  ! 4       4      pVP                  4        F~  pVP                  4       '       g   K  VP                  4        FO  pVP                  R8w  d   K   \        VR4      ;_uu_ 4       p\        P                  ! V4      pW53x  RRR4       KQ  	  K  	  R#   + '       g   i     Kj  ; i  \        P                  P                   d    \        P                  ! RT4        K  i ; i5i)z'Get all presets for all groups as list.Nz.jsonrz"Invalid json format in preset "%s")ospathexistsr   get_preset_pathr   ZiterdirZis_dirZsuffixopenjsonloadZdecoderZJSONDecodeErrorr   Zwarning)r8   Zpreset_pathZfolderpresetZfpreset_structure   &     r.   all_presetsZMigrations.all_presetsj   s      ww~~i779::94467!))+F==?? ..*==G+fc**a+/99Q<($66 +* +	 , +** ||33 NN#GPsN   B*E -DC/	D%
E /D :D>E  D6D=9E <D==E c                s   \         P                  P                  \        P                  ! 4       R4      p\         P                  P                  V4      '       g   \        P                  ! R4      # \        VR4      ;_uu_ 4       p\        P                  ! V4      pRRR4       RXP                  4       9   d   \        P                  ! VR,          4      # \        P                  ! R4      #   + '       g   i     LX; i)zBGet the version string in config.json as packaging.Version object.config.jsonz0.0.0rI   Nr   )rJ   rK   joinr   config_pathrL   r   r=   rN   rO   rP   keys)r8   rW   fileconfig   &   r.   r<   ZMigrations.config_version   s    ggll9#8#8#:MJww~~k**==))+s##tYYt_F $ %==	!233}}W%% $#s   C**C:	c                s   \         P                  P                  \        P                  ! 4       R4      p\         P                  P                  \        P                  ! 4       R4      p\         P                  P                  V4      '       dW   \         P                  P                  V4      '       g0   \        P                  ! RW4       \         P                  ! W4       R# R# R# )z+Append the .json suffix to the config file.rZ   rU   Moving "%s" to "%s"N)	rJ   rK   rV   r   rW   rL   r   inforename)r8   Zdeprecated_pathrW      &  r.   r>   ZMigrations._config_suffix   s    '',,y'<'<'>Iggll9#8#8#:MJ77>>/**277>>+3N3NKK-LIIo3 4O*r-   c                s   \         P                  P                  \        P                  ! 4       R4      p\         P                  P                  \        P                  ! 4       4      '       g9   \         P                  P                  \        P                  ! 4       4      '       g   R# \        P                  ! R4       \         P                  ! \        P                  ! 4       4      p\        P                  ! \        P                  ! 4       4       V F  p\         P                  P                  \        P                  ! 4       V4      p\         P                  P                  V4      '       g   K]  VP                  \        P                  ! 4       V4      p\        P                  ! RWE4       \         P                  ! WE4       K  	  \        P                  ! R4       R# )zcMigrate the folder structure from < 0.4.0.

Move existing presets into the new subfolder 'presets'
ZpresetsNz!Migrating presets from < 0.4.0...r\   Zdone)rJ   rK   rV   r   rW   rL   rM   r   r]   ZlistdirZmkdirZisdirZreplacer^   )r8   Znew_preset_folderZgroupsZgrouprK   targetrS   r.   r?   ZMigrations._preset_path   s   
 GGLL)>)>)@)L77>>)33566bggnn!!#?
 ?
 78I1134	1134E77<<	 5 5 7?Dww}}T""i&;&;&=?PQ14@		$'  	Fr-   c           	     s   V P                  4        EF  w  r\        V\        4      '       d   K  ^ pRVP                  4       9   d{   \        P
                  ! VR,          4      pVP                  4        FI  pVP                  R4      ^8X  g   K  VR,          P                  V4      VR,          V R2&   V^,          pKK  	  V'       g   K  \        VR4      ;_uu_ 4       p\        P                  ! RV4       \        P                  ! W&^R7       VP                  R4       RRR4       EK  	  R#   + '       g   i     EK/  ; i)	z]Update all preset mappings.

Update all keys in preset to include value e.g.: '1,5'->'1,5,1'
mapping,z,1wzUpdating mapping keys of "%s"Zindent
N)rT   
isinstancelistrX   copyZdeepcopyZcountZpoprN   r   r]   rO   dumpwrite)r8   rQ   rR   Zchangesra   keyrY   s   &      r.   r@   ZMigrations._mapping_keys   s    
 )-(8(8(:$F*D11G,1133--(8(CD"<<>Cyy~*BR%C#c( )3se2J?  1 * w&#&&$KK ?HII.Q?JJt$ '& ); '&&s   AD..E c                s    \         P                  P                  \        P                  ! 4       R4      p\         P                  P                  V4      '       g   R# \        VR4      ;_uu_ 4       p\        P                  ! V4      pRRR4       \        XR&   \        VR4      ;_uu_ 4       p\        P                  ! R\        4       \        P                  ! W2^R7       RRR4       R#   + '       g   i     Lk; i  + '       g   i     R# ; i)z-Write the current version to the config file.rU   NrI   r   rc   z"Updating version in config to "%s"rd   )rJ   rK   rV   r   rW   rL   rN   rO   rP   r   r   r]   ri   )r8   Zconfig_filerY   rZ   r[   r.   rE   ZMigrations._update_version   s    ggll9#8#8#:MJww~~k**+s##tYYt_F $ $y+s##tKK<gFIIf1- $#	 $# $##s   /C)+4C<)C9	<D	c                s   \         P                  P                  \        P                  R4      p\         P                  P                  \        P                  ! 4       4      '       g   \         P                  P                  V4      '       dX   \        P                  ! RV\        P                  ! 4       4       \        P                  ! V\        P                  ! 4       4       R# R# R# )z4Rename .config/key-mapper to .config/input-remapper.z.config/key-mapperzMoving %s to %sN)rJ   rK   rV   r   homerL   r   rW   r   r]   shutilmove)r8   Zold_config_pathrF   r.   r:   Z$Migrations._rename_to_input_remapper   s    '',,y~~7KLww~~i33566277>><
 <
 KK)?I<Q<Q<STKK)>)>)@A	<
6r-   c                s   \         \        4       \        \        4       /p\        P                  ! V4      '       d   R# \
        P                  ! V4      0V\         &   \        V\        ,          4      ^ 8  d   R# V P                  P                  P                  4        FD  w  r4V\         ,          P                  VP                  4       \         ,          4      '       g   KB  Vu # 	  \        P                  ! RV4       R# )zCTry to find a uinput with the required capabilities for the symbol.Nmousez0could not find a suitable target UInput for "%s")r   Zsetr
   r   is_this_a_macror   getZlenr2   ZdevicesitemsZissubsetcapabilitiesr   r]   )r8   symbolrs   ZnameZuinputs   &&   r.   _find_targetZMigrations._find_target   s    vsu5!!&))  / 3 3F ;<V|F#$q( //77==?LDF#,,V-@-@-B6-JKK @ 	FOr-   c           	     s   V P                  4        EF)  w  r\        V\        4      '       d   K  RVP                  4       9  d   K5  RpVR,          P	                  4       P                  4        Fb  w  rE\        V\        4      '       d   K  V P                  V4      pVf   RpV R2p\        P                  ! RVVV4       WV.pWRR,          V&   RpKd  	  V'       g   K  \        VR4      ;_uu_ 4       p\        P                  ! R	V4       \        P                  ! W'^R
7       VP                  R4       RRR4       EK,  	  R#   + '       g   i     EKB  ; i)z,Add the target field to each preset mapping.ra   FNZkeyboardz@
# Broken mapping:
# No target can handle all specified keycodesz:Changing target of mapping for "%s" in preset "%s" to "%s"Trc   zAdding targets for "%s"rd   re   )rT   rf   rg   rX   rh   rr   ru   r   r]   rN   rO   ri   rj   )r8   rQ   rR   changedrk   rt   r`   rY      &       r.   rA   ZMigrations._add_target   s4   (,(8(8(:$F*D11 0 5 5 77G/	:??AGGIfd++**62>'F!( #H H  P	 !)39+C0+  J. fc""d5v>		*;

4  #"E );D #""s   1AEEc           	     s2   V P                  4        EFl  w  r\        V\        4      '       d   K  RVP                  4       9  d   K5  RpVR,          P	                  4       P                  4        F  w  rE\        P                  ! V^ ,          4      '       g   K*  V^ ,          p\        P                  ! RRV^ ,          4      V^ &   We^ ,          8X  d   Kd  T;'       g    We^ ,          8g  p\        P                  ! RVVV^ ,          4       WRR,          V&   K  	  V'       g   EK  \        VR4      ;_uu_ 4       p\        P                  ! RV4       \        P                  ! W'^R7       VP                  R	4       R
R
R
4       EKo  	  R
#   + '       g   i     EK  ; i)zIConditional macros should use an "else" parameter instead of "otherwise".ra   Fzotherwise\s*=\s*zelse=z0Changing mapping for "%s" in preset "%s" to "%s"rc   z#Changing otherwise to else for "%s"rd   re   N)rT   rf   rg   rX   rh   rr   r   rp   reZsubr   r]   rN   rO   ri   rj   )r8   rQ   rR   rv   rk   rt   Zsymbol_beforerY   rw   r.   rB   ZMigrations._otherwise_to_else  sF   (,(8(8(:$F*D11 0 5 5 77G/	:??AGGI--fQi88 &q	FF#6Kq	 1I-!??]Qi%?F1I	 4:+C0'  J* fc""dA6J		*;

4  #"A );@ #""s   4AFFc               s     V ^8  d   QhRRRR/# )r1   combination_stringr"   rH   r   r'   r3   r4   r.   r5   r6   E  s     ) )"%)	)r-   c                	s    . pVP                  R 4       FI  pVP                  R4      w  rEpVP                  R\        V4      R\        V4      R\        V4      /4       KK  	  \        V4      # )Z+rb   typecodeanalog_threshold)ZsplitZappendr$   r   )r8   ry   ZconfigsZ	event_strZtype_r{   r|   s   &&     r.   _input_combination_from_stringZ)Migrations._input_combination_from_stringE  sm     +11#6I,5OOC,@)E)NNCJCI&,<(= 7  ((r-   c               r0   )r1   rH   ZNoner'   r3   r4   r.   r5   r6   U  s     H# H#	H#r-   c           	     s 
   V P                  4        EF  w  r\        V\        4      '       d   K  \        V\        4      pRVP                  4       9   dx   VR,          P                  4        F\  w  rE\        P                  ! RVV4        V P                  V4      p\	        TT^,          T^ ,          R7      pTP                  T4       K^  	  RVP                  4       9   Ed   RVR,          P                  4       9   Ed   VR,          R,          pVP                  R4      pVP                  R4      p	VP                  R	4      p
V
'       d
   V
^d,          p
VP                  R
4      pVP                  R4      pVP                  R4      pRRRRR\        RR/pVR8X  d   VP                  4       pVP                  4       p\!        \#        \$        \&        R7      .4      VR&   \!        \#        \$        \(        R7      .4      VR&   \*        VR&   \,        VR&   \/        R/ VB p\/        R/ VB pV
'       d   V
Vn        V
Vn        VP                  V4       VP                  V4       V	R8X  d   VP                  4       pVP                  4       p\!        \#        \$        \2        R7      .4      VR&   \!        \#        \$        \4        R7      .4      VR&   \*        VR&   \,        VR&   \/        R/ VB p\/        R/ VB pV
'       d   V
Vn        V
Vn        VP                  V4       VP                  V4       VR8X  d   VP                  4       pVP                  4       p\!        \#        \$        \&        R7      .4      VR&   \!        \#        \$        \(        R7      .4      VR&   \6        VR&   \8        VR&   \/        R/ VB p\/        R/ VB pV'       d   VVn        V'       d   VVn        VP                  V4       VP                  V4       V	R8X  d   VP                  4       pVP                  4       p\!        \#        \$        \2        R7      .4      VR&   \!        \#        \$        \4        R7      .4      VR&   \6        VR&   \8        VR&   \/        R/ VB p\/        R/ VB pV'       d   VVn        V'       d   VVn        VP                  V4       VP                  V4       VP;                  4        EK  	  R#   \         d    \        P                  ! RT4        EK  i ; i)zkConvert preset.json
from {key: [symbol, target]}
to [{input_combination: ..., output_symbol: symbol, ...}]
ra   z'migrating from "%s: %s" to mapping dictz5unable to migrate mapping with invalid combination %s)r!   r#   Zoutput_symbolZgamepadZjoystickleft_purposeright_purposepointer_speednon_linearityx_scroll_speedy_scroll_speedr!   Nr#   ro   r%   r&   )rz   r{   Zwheelr'   )rT   rf   rg   r   r   rX   rr   r   r]   r}   Z
ValueErrorerrorZaddrq   r
   rh   r   r   r	   r   r   r   r   r   Zgainr   r   r   r   Zsave)r8   Zold_preset_pathZ
old_presetZmigrated_presetZcombinationZsymbol_targetra   Zjoystick_dictr~   r   r   r   r   r   ZcfgZx_configZy_configZ	mapping_xZ	mapping_ys   &                  r.   rD   Z*Migrations._convert_to_individual_mappingsU  s    ,0+;+;+='O*d++$_i@OJOO--2<Y2G2M2M2O.KKKA#%
!&*&I&I+&V (*5&3A&6&3A&6G
 $''0) 3P. Z__..*Y"7"<"<">> *9 5j A,00@ - 1 1/ B - 1 1/ B !S(M - 1 1/ B!.!2!23C!D!.!2!23C!D (#W!6!4	  7*"xxzH"xxzH4D$&u=>5H01 5E$&u=>5H01 /4H]+.3H]+ ' 3( 3I ' 3( 3I$)6	)6	#''	2#''	2 G+"xxzH"xxzH4D$&v>?5H01 5E$&v>?5H01 /4H]+.3H]+ ' 3( 3I ' 3( 3I$)6	)6	#''	2#''	27*"xxzH"xxzH4D$&u=>5H01 5E$&u=>5H01 /@H]+.>H]+ ' 3( 3I ' 3( 3I%)7	%)7	#''	2#''	2 G+"xxzH"xxzH4D$&v>?5H01 5E$&v>?5H01 /@H]+.>H]+ ' 3( 3I ' 3( 3I%)7	%)7	#''	2#''	2  "A ,> & !S' !!s   	S&&"TTc                s^   \         P                  P                  \        P                  ! 4       4      '       d   R# \         P                  P                  \        P                  R4      p\         P                  P                  \         P                  P                  VR4      4      '       dX   \        P                  ! RV\        P                  ! 4       4       \        P                  ! V\        P                  ! 4       4       R# \         P                  P                  \        P                  R4      p\         P                  P                  V4      '       dX   \        P                  ! RV\        P                  ! 4       4       \        P                  ! V\        P                  ! 4       4       R# R# )zJMove the beta config to the v2 path, or copy the v1 config to the v2 path.Nz.config/input-remapperrU   zcopying all from %s to %sz&.config/input-remapper/beta_1.6.0-betazmoving %s to %s)rJ   rK   rL   r   rW   rV   r   rl   r   debugrm   Zcopytreern   )r8   Zold_pathZ	beta_pathr_   r.   r;   ZMigrations._copy_to_v2  s    77>>)//122  77<<	0HI77>>"'',,x?@@ LL4h	@U@U@WXOOHi&;&;&=> GGLLNND
	 77>>)$$ LL*Iy7L7L7NOKK	9#8#8#:; %r-   c                s     \         P                  ! \        P                   R24       \         P                  ! R4       \         P                  ! R4       R#   \         d,   p\
        P                  ! R\        T4      4        Rp?R# Rp?ii ; i)z9We will try to rely on journalctl for this in the future.z/.log/input-remapperz/var/log/input-remapperz/var/log/input-remapper-controlz(Failed to remove deprecated logfiles: %sN)r   Zremover   rl   Z	Exceptionr   r   r"   )r8   r   rF   r.   rC   ZMigrations._remove_logs  sf    		//CDE67>? 	LLCSZP	s   AA B" BBr7   N)r(   r)   r*   r+   r9   rG   rT   r<   r>   r?   r@   rE   r:   ru   rA   rB   r}   rD   r;   rC   r,   r'   r-   r.   r/   r/   D   sX    - #D0&4.%2.B*'!R%!N) H#T<8	r-   r/   )6Z__doc__Z
__future__r    rh   rO   rJ   rx   rm   Zpathlibr   Ztypingr   r   r   r   r   r   Zevdev.ecodesr   r	   r
   r   r   r   r   r   r   r   r   Z	packagingr   Z"inputremapper.configs.input_configr   r   Z%inputremapper.configs.keyboard_layoutr   Zinputremapper.configs.mappingr   r   Zinputremapper.configs.pathsr   Zinputremapper.configs.presetr   Z&inputremapper.injection.global_uinputsr   Z$inputremapper.injection.macros.parser   Zinputremapper.logging.loggerr   r   Zinputremapper.userr   r    r/   r'   r-   r.   <module>r      ss   (
 #   	 	   C C     L A < 1 / @ 7 8 (Y @ @r-   