File indexing completed on 2024-05-12 17:07:15

0001 #!/usr/bin/env python3
0002 #
0003 #  SPDX-FileCopyrightText: 2021 Carson Black <uhhadd@gmail.com>
0004 #
0005 #  SPDX-License-Identifier: LGPL-2.0-or-later
0006 #
0007 
0008 # 5.21.0 botched the migration by accidentally turning enabled to disabled and disabled to enabled.
0009 # We have two choices here: we can either break key repeat for users that manually intervened
0010 # and enabled key repeat by inverting the value, or we can enable key repeat for users that didn't
0011 # have it enabled and fix users that had their key repeat disabled. Only one of those sentences
0012 # contains the word "break" so we go with the one without the word "break" ;)
0013 # Enabling key repeat for users who disabled it is less breaking than disabling key repeat for
0014 # users who enabled it.
0015 
0016 #
0017 # And that brings us to the code.
0018 #
0019 # We'll need to import sys in order to read stdin, which is how we receive
0020 # the old input file to look for it.
0021 #
0022 import sys
0023 
0024 #
0025 # After that, we'll need to declare ourselves a variable to hold the contents
0026 # of the config file we read in from stdin.
0027 #
0028 
0029 content: str = sys.stdin.read()
0030 
0031 #
0032 # That brings us to checking for the presence of the old script's effects on the underlying system:
0033 # kconfig files are annotated with a section containing all of the config scripts that have ran
0034 # on them.
0035 #
0036 # They're of the form filename.upd:migration_name.
0037 #
0038 if "kcminputrc_repeat.upd:kcminputrc_migrate_repeat_value" in content:
0039     #
0040     # Now we check for the presence of a disabled key repeat in the config file contents. For 5.21.0, this
0041     # was changed from a 0-1-2 ternary to an English-language nothing/repeat/accent.
0042     # The config script for migrating ternary to English-language is why we're in this
0043     # mess in the first place. We migrated 0 (enabled) -> nothing and 2 (disabled) -> repeat.
0044     #
0045     if "KeyRepeat=nothing" in content:
0046         #
0047         # Now we print the command instructing the kconfig updater to delete this field.
0048         # A deleted field essentially means "use the default" which in this case means
0049         # "enable key repeat." We delete instead of reassigning to "repeat" because
0050         # we would prefer to have a deleted field act as our "default" value.
0051         #
0052         print("# DELETE [Keyboard]KeyRepeat")
0053 
0054     #
0055     # Since we created the Tmp group as a temporary way of conveying to this script what migrations
0056     # were applied to the config file, we want to clean it up, as it serves no other purpose.
0057     #
0058     # We instruct KConfig to delete the Tmp group in the config file.
0059     #
0060     print("# DELETEGROUP Tmp")