diff mbox series

[v4l-utils] lircd2toml: add option to keep lirc codes as they are

Message ID 20200614120848.26428-1-sean@mess.org (mailing list archive)
State New, archived
Headers show
Series [v4l-utils] lircd2toml: add option to keep lirc codes as they are | expand

Commit Message

Sean Young June 14, 2020, 12:08 p.m. UTC
When keymaps are only used for sending, they do not have to look like
KEY_*. Keeping the existing lirc names might be preferable.

Signed-off-by: Sean Young <sean@mess.org>
---
 contrib/lircd2toml.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/contrib/lircd2toml.py b/contrib/lircd2toml.py
index ba4b14ec..897ad765 100755
--- a/contrib/lircd2toml.py
+++ b/contrib/lircd2toml.py
@@ -13,10 +13,11 @@  import math
 import argparse
 
 class LircdParser:
-    def __init__(self, filename, encoding):
+    def __init__(self, filename, encoding, rename):
         self.lineno=0
         self.filename=filename
         self.encoding=encoding
+        self.rename=rename
 
     def getline(self):
         while True:
@@ -126,7 +127,7 @@  class LircdParser:
             k = a.pop(0)
             if k == 'end':
                 return codes
-            if not k.startswith('KEY_'):
+            if self.rename and not k.startswith('KEY_'):
                 k = 'KEY_' + k.upper()
             for s in a:
                 if s[0] == '#':
@@ -153,7 +154,7 @@  class LircdParser:
                 if codes:
                     raw_codes.append({ 'keycode': name, 'raw': codes })
                 name = line.split(maxsplit=2)[1]
-                if not name.startswith('KEY_'):
+                if self.rename and not name.startswith('KEY_'):
                     name = 'KEY_' + name.upper()
                 codes = []
             elif a[0] == 'end':
@@ -642,12 +643,14 @@  can be include with the package.""")
 parser.add_argument('input', metavar='INPUT', help='lircd.conf file')
 parser.add_argument('-o', '--output', metavar='OUTPUT', help='toml output file')
 parser.add_argument('--encoding', default='utf-8-sig', help='Encoding of lircd.conf')
+parser.add_argument('--preserve-codes', const=False, default=True,
+    dest='rename', action='store_const', help='Do not rename codes to KEY_*')
 
 args = parser.parse_args()
 
 remoteNo=1
 tomls=[]
-remotes=LircdParser(args.input, args.encoding).parse()
+remotes=LircdParser(args.input, args.encoding, args.rename).parse()
 if remotes == None:
     sys.exit(1)
 for remote in remotes: