summaryrefslogtreecommitdiff
path: root/lib/python/qmk
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk')
-rw-r--r--lib/python/qmk/cli/config.py116
-rw-r--r--lib/python/qmk/cli/json/__init__.py5
-rwxr-xr-xlib/python/qmk/cli/json/keymap.py16
-rw-r--r--lib/python/qmk/os_helpers/linux/__init__.py11
-rw-r--r--lib/python/qmk/path.py1
-rw-r--r--lib/python/qmk/tests/onekey_export.json6
6 files changed, 154 insertions, 1 deletions
diff --git a/lib/python/qmk/cli/config.py b/lib/python/qmk/cli/config.py
new file mode 100644
index 0000000000..e17d8bb9ba
--- /dev/null
+++ b/lib/python/qmk/cli/config.py
@@ -0,0 +1,116 @@
+"""Read and write configuration settings
+"""
+from milc import cli
+
+
+def print_config(section, key):
+ """Print a single config setting to stdout.
+ """
+ cli.echo('%s.%s{fg_cyan}={fg_reset}%s', section, key, cli.config[section][key])
+
+
+def show_config():
+ """Print the current configuration to stdout.
+ """
+ for section in cli.config:
+ for key in cli.config[section]:
+ print_config(section, key)
+
+
+def parse_config_token(config_token):
+ """Split a user-supplied configuration-token into its components.
+ """
+ section = option = value = None
+
+ if '=' in config_token and '.' not in config_token:
+ cli.log.error('Invalid configuration token, the key must be of the form <section>.<option>: %s', config_token)
+ return section, option, value
+
+ # Separate the key (<section>.<option>) from the value
+ if '=' in config_token:
+ key, value = config_token.split('=')
+ else:
+ key = config_token
+
+ # Extract the section and option from the key
+ if '.' in key:
+ section, option = key.split('.', 1)
+ else:
+ section = key
+
+ return section, option, value
+
+
+def set_config(section, option, value):
+ """Set a config key in the running config.
+ """
+ log_string = '%s.%s{fg_cyan}:{fg_reset} %s {fg_cyan}->{fg_reset} %s'
+ if cli.args.read_only:
+ log_string += ' {fg_red}(change not written)'
+
+ cli.echo(log_string, section, option, cli.config[section][option], value)
+
+ if not cli.args.read_only:
+ if value == 'None':
+ del cli.config[section][option]
+ else:
+ cli.config[section][option] = value
+
+
+@cli.argument('-ro', '--read-only', arg_only=True, action='store_true', help='Operate in read-only mode.')
+@cli.argument('configs', nargs='*', arg_only=True, help='Configuration options to read or write.')
+@cli.subcommand("Read and write configuration settings.")
+def config(cli):
+ """Read and write config settings.
+
+ This script iterates over the config_tokens supplied as argument. Each config_token has the following form:
+
+ section[.key][=value]
+
+ If only a section (EG 'compile') is supplied all keys for that section will be displayed.
+
+ If section.key is supplied the value for that single key will be displayed.
+
+ If section.key=value is supplied the value for that single key will be set.
+
+ If section.key=None is supplied the key will be deleted.
+
+ No validation is done to ensure that the supplied section.key is actually used by qmk scripts.
+ """
+ if not cli.args.configs:
+ return show_config()
+
+ # Process config_tokens
+ save_config = False
+
+ for argument in cli.args.configs:
+ # Split on space in case they quoted multiple config tokens
+ for config_token in argument.split(' '):
+ section, option, value = parse_config_token(config_token)
+
+ # Validation
+ if option and '.' in option:
+ cli.log.error('Config keys may not have more than one period! "%s" is not valid.', config_token)
+ return False
+
+ # Do what the user wants
+ if section and option and value:
+ # Write a configuration option
+ set_config(section, option, value)
+ if not cli.args.read_only:
+ save_config = True
+
+ elif section and option:
+ # Display a single key
+ print_config(section, option)
+
+ elif section:
+ # Display an entire section
+ for key in cli.config[section]:
+ print_config(section, key)
+
+ # Ending actions
+ if save_config:
+ cli.save_config()
+
+ return True
diff --git a/lib/python/qmk/cli/json/__init__.py b/lib/python/qmk/cli/json/__init__.py
new file mode 100644
index 0000000000..f4ebfc45b4
--- /dev/null
+++ b/lib/python/qmk/cli/json/__init__.py
@@ -0,0 +1,5 @@
+"""QMK CLI JSON Subcommands
+
+We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup.
+"""
+from . import keymap
diff --git a/lib/python/qmk/cli/json/keymap.py b/lib/python/qmk/cli/json/keymap.py
new file mode 100755
index 0000000000..2af9faaa72
--- /dev/null
+++ b/lib/python/qmk/cli/json/keymap.py
@@ -0,0 +1,16 @@
+"""Generate a keymap.c from a configurator export.
+"""
+from pathlib import Path
+
+from milc import cli
+
+
+@cli.argument('-o', '--output', arg_only=True, type=Path, help='File to write to')
+@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
+@cli.argument('filename', arg_only=True, help='Configurator JSON file')
+@cli.subcommand('Creates a keymap.c from a QMK Configurator export.', hidden=True)
+def json_keymap(cli):
+ """Renamed to `qmk json2c`.
+ """
+ cli.log.error('This command has been renamed to `qmk json2c`.')
+ return False
diff --git a/lib/python/qmk/os_helpers/linux/__init__.py b/lib/python/qmk/os_helpers/linux/__init__.py
index 008654ab0f..de38f1d609 100644
--- a/lib/python/qmk/os_helpers/linux/__init__.py
+++ b/lib/python/qmk/os_helpers/linux/__init__.py
@@ -47,7 +47,10 @@ def check_udev_rules():
_udev_rule("03eb", "2ff3"), # ATmega16U4
_udev_rule("03eb", "2ff4"), # ATmega32U4
_udev_rule("03eb", "2ff9"), # AT90USB64
+<<<<<<< HEAD
+=======
_udev_rule("03eb", "2ffa"), # AT90USB162
+>>>>>>> 0.12.52~1
_udev_rule("03eb", "2ffb") # AT90USB128
},
'kiibohd': {_udev_rule("1c11", "b007")},
@@ -94,7 +97,11 @@ def check_udev_rules():
# Collect all rules from the config files
for rule_file in udev_rules:
+<<<<<<< HEAD
+ for line in rule_file.read_text().split('\n'):
+=======
for line in rule_file.read_text(encoding='utf-8').split('\n'):
+>>>>>>> 0.12.52~1
line = line.strip()
if not line.startswith("#") and len(line):
current_rules.add(line)
@@ -131,7 +138,11 @@ def check_modem_manager():
"""
if check_systemd():
+<<<<<<< HEAD
+ mm_check = run(["systemctl", "--quiet", "is-active", "ModemManager.service"], timeout=10)
+=======
mm_check = cli.run(["systemctl", "--quiet", "is-active", "ModemManager.service"], timeout=10)
+>>>>>>> 0.12.52~1
if mm_check.returncode == 0:
return True
else:
diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py
index 72bae59273..2aa1916f55 100644
--- a/lib/python/qmk/path.py
+++ b/lib/python/qmk/path.py
@@ -15,7 +15,6 @@ def is_keyboard(keyboard_name):
if keyboard_name:
keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name
rules_mk = keyboard_path / 'rules.mk'
-
return rules_mk.exists()
diff --git a/lib/python/qmk/tests/onekey_export.json b/lib/python/qmk/tests/onekey_export.json
new file mode 100644
index 0000000000..95f0a980fe
--- /dev/null
+++ b/lib/python/qmk/tests/onekey_export.json
@@ -0,0 +1,6 @@
+{
+ "keyboard":"handwired/onekey/pytest",
+ "keymap":"pytest_unittest",
+ "layout":"LAYOUT",
+ "layers":[["KC_A"]]
+}