예제 #1
0
파일: setup.py 프로젝트: qmk/qmk_cli
def setup(cli):
    """Guide the user through setting up their QMK environment.
    """
    clone_prompt = 'Would you like to clone {fg_cyan}%s{fg_reset} to {fg_cyan}%s{fg_reset}?' % (
        cli.args.fork, shlex.quote(str(cli.args.home)))
    home_prompt = 'Would you like to set {fg_cyan}%s{fg_reset} as your QMK home?' % (
        shlex.quote(str(cli.args.home)), )

    # Sanity checks
    if cli.args.yes and cli.args.no:
        cli.log.error("Can't use both --yes and --no at the same time.")
        exit(1)

    # Check on qmk_firmware, and if it doesn't exist offer to check it out.
    if is_qmk_firmware(cli.args.home):
        cli.log.info('Found qmk_firmware at %s.', str(cli.args.home))

    elif cli.args.home.exists():
        path_str = str(cli.args.home)

        if cli.args.home.name != 'qmk_firmware':
            cli.log.warning(
                'Warning: %s does not end in "qmk_firmware". Did you mean to use "--home %s/qmk_firmware"?'
                % (path_str, path_str))

        cli.log.error("Path '%s' exists but is not a qmk_firmware clone!",
                      path_str)
        exit(1)

    else:
        cli.log.error('Could not find qmk_firmware!')
        if yesno(clone_prompt):
            git_url = '/'.join((cli.config.setup.baseurl, cli.args.fork))

            if git_clone(git_url, cli.args.home, cli.config.setup.branch):
                git_upstream(cli.args.home)
            else:
                exit(1)

    # Offer to set `user.qmk_home` for them.
    if str(cli.args.home) != os.environ['QMK_HOME'] and yesno(home_prompt):
        cli.config['user']['qmk_home'] = str(cli.args.home.absolute())
        cli.config_source['user']['qmk_home'] = 'config_file'
        cli.write_config_option('user', 'qmk_home')

    # Run `qmk doctor` to check the rest of the environment out
    color = '--color' if cli.config.general.color else '--no-color'
    unicode = '--unicode' if cli.config.general.unicode else '--no-unicode'
    doctor_command = [Path(sys.argv[0]).as_posix(), color, unicode, 'doctor']

    if cli.args.no:
        doctor_command.append('--no')

    if cli.args.yes:
        doctor_command.append('--yes')

    cli.run(doctor_command, stdin=None, capture_output=False)
예제 #2
0
파일: clone.py 프로젝트: zvecr/qmk_cli
def clone(cli):
    if not cli.args.destination:
        cli.args.destination = os.path.join(os.environ['ORIG_CWD'],
                                            default_fork.split('/')[-1])

    qmk_firmware = Path(cli.args.destination)
    git_url = '/'.join((cli.config.clone.baseurl, cli.args.fork))

    if qmk_firmware.exists():
        cli.log.error('Destination already exists: %s', cli.args.destination)
        exit(1)

    return git_clone(git_url, cli.args.destination, cli.config.clone.branch)
예제 #3
0
파일: setup.py 프로젝트: zhangaz1/qmk_cli
def setup(cli):
    """Guide the user through setting up their QMK environment.
    """
    clone_prompt = 'Would you like to clone {fg_cyan}%s{fg_reset} to {fg_cyan}%s{fg_reset}?' % (
        cli.args.fork, shlex.quote(str(cli.args.home)))
    home_prompt = 'Would you like to set {fg_cyan}%s{fg_reset} as your QMK home?' % (
        shlex.quote(str(cli.args.home)), )

    # Sanity checks
    if cli.args.yes and cli.args.no:
        cli.log.error("Can't use both --yes and --no at the same time.")
        exit(1)

    # Check on qmk_firmware, and if it doesn't exist offer to check it out.
    if (cli.args.home / 'Makefile').exists():
        cli.log.info('Found qmk_firmware at %s.', str(cli.args.home))
    else:
        cli.log.error('Could not find qmk_firmware!')
        if yesno(clone_prompt):
            git_url = '/'.join((cli.config.setup.baseurl, cli.args.fork))

            if git_clone(git_url, cli.args.home, cli.config.setup.branch):
                git_upstream(cli.args.home)
            else:
                exit(1)

    # Offer to set `user.qmk_home` for them.
    if cli.args.home != Path(os.environ['QMK_HOME']) and yesno(home_prompt):
        cli.config['user']['qmk_home'] = str(cli.args.home.absolute())
        cli.write_config_option('user', 'qmk_home')

    # Run `qmk_firmware/bin/qmk doctor` to check the rest of the environment out
    qmk_bin = cli.args.home / 'bin/qmk'
    doctor_cmd = [sys.executable, qmk_bin.as_posix(), 'doctor']

    if cli.args.yes:
        doctor_cmd.append('--yes')

    if cli.args.no:
        doctor_cmd.append('--no')

    subprocess.run(doctor_cmd)