Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cli.log.info('QMK Doctor is checking your environment.')
# Make sure the basic CLI tools we need are available and can be executed.
binaries = ['dfu-programmer', 'avrdude', 'dfu-util', 'avr-gcc', 'arm-none-eabi-gcc']
binaries += glob('bin/qmk-*')
ok = True
for binary in binaries:
res = shutil.which(binary)
if res is None:
cli.log.error("{fg_red}QMK can't find %s in your path.", binary)
ok = False
else:
try:
subprocess.run([binary, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=5, check=True)
cli.log.info('Found {fg_cyan}%s', binary)
except subprocess.CalledProcessError:
cli.log.error("{fg_red}Can't run `%s --version`", binary)
ok = False
# Determine our OS and run platform specific tests
OS = platform.system()
if OS == "Darwin":
cli.log.info("Detected {fg_cyan}macOS.")
elif OS == "Linux":
cli.log.info("Detected {fg_cyan}Linux.")
if shutil.which('systemctl'):
mm_check = subprocess.run(['systemctl', 'list-unit-files'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10, universal_newlines=True)
if mm_check.returncode == 0:
mm = False
def docs(cli):
"""Spin up a local HTTPServer instance for the QMK docs.
"""
os.chdir('docs')
with http.server.HTTPServer(('', cli.config.docs.port), http.server.SimpleHTTPRequestHandler) as httpd:
cli.log.info("Serving QMK docs at http://localhost:%d/", cli.config.docs.port)
cli.log.info("Press Control+C to exit.")
try:
httpd.serve_forever()
except KeyboardInterrupt:
cli.log.info("Stopping HTTP server...")
finally:
httpd.shutdown()
def pyformat(cli):
"""Format python code according to QMK's style.
"""
try:
subprocess.run(['yapf', '-vv', '-ri', 'bin/qmk', 'lib/python'], check=True)
cli.log.info('Successfully formatted the python code in `bin/qmk` and `lib/python`.')
except subprocess.CalledProcessError:
cli.log.error('Error formatting python code!')
height=kle.rows,
layouts={'LAYOUT': {
'layout': 'LAYOUT_JSON_HERE'
}},
)
# Initialize keyboard with json encoded from ordered dict
keyboard = json.dumps(keyboard, indent=4, separators=(', ', ': '), sort_keys=False, cls=CustomJSONEncoder)
# Initialize layout with kle2qmk from converter module
layout = json.dumps(kle2qmk(kle), separators=(', ', ':'), cls=CustomJSONEncoder)
# Replace layout in keyboard json
keyboard = keyboard.replace('"LAYOUT_JSON_HERE"', layout)
# Write our info.json
file = open(str(out_path) + "/info.json", "w")
file.write(keyboard)
file.close()
cli.log.info('Wrote out {fg_cyan}%s/info.json', str(out_path))
cli.echo('usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]')
print_bootloader_help()
return False
elif cli.args.keymap and not cli.args.keyboard:
# If only a keymap was given but no keyboard, suggest listing keyboards
cli.echo('usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]')
cli.log.error('run \'qmk list_keyboards\' to find out the supported keyboards')
return False
elif cli.args.filename:
# Get keymap path to log info
user_keymap = parse_configurator_json(cli.args.filename)
keymap_path = qmk.path.keymap(user_keymap['keyboard'])
cli.log.info('Creating {fg_cyan}%s{style_reset_all} keymap in {fg_cyan}%s', user_keymap['keymap'], keymap_path)
# Convert the JSON into a C file and write it to disk.
command = compile_configurator_json(user_keymap, cli.args.bootloader)
cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap'])
elif cli.args.keyboard and cli.args.keymap:
# Generate the make command for a specific keyboard/keymap.
command = create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, cli.args.bootloader)
else:
cli.echo('usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]')
cli.log.error('You must supply a configurator export or both `--keyboard` and `--keymap`. You can also specify a bootloader with --bootloader. Use --bootloaders to list the available bootloaders.')
return False
cli.log.info('Flashing keymap with {fg_cyan}%s\n\n', ' '.join(command))
if mm:
cli.log.warn("{bg_yellow}Detected ModemManager. Please disable it if you are using a Pro-Micro.")
else:
cli.log.error('{bg_red}Could not run `systemctl list-unit-files`:')
cli.log.error(mm_check.stderr)
else:
cli.log.warn("Can't find systemctl to check for ModemManager.")
else:
cli.log.info("Assuming {fg_cyan}Windows.")
# Report a summary of our findings to the user
if ok:
cli.log.info('{fg_green}QMK is ready to go')
else:
cli.log.info('{fg_yellow}Problems detected, please fix these problems before proceeding.')
# FIXME(skullydazed): Link to a document about troubleshooting, or discord or something
else:
cli.log.error('{bg_red}Could not run `systemctl list-unit-files`:')
cli.log.error(mm_check.stderr)
else:
cli.log.warn("Can't find systemctl to check for ModemManager.")
else:
cli.log.info("Assuming {fg_cyan}Windows.")
# Report a summary of our findings to the user
if ok:
cli.log.info('{fg_green}QMK is ready to go')
else:
cli.log.info('{fg_yellow}Problems detected, please fix these problems before proceeding.')
# FIXME(skullydazed): Link to a document about troubleshooting, or discord or something