Ejemplo n.º 1
0
def main():
    """Setup the environment before dispatching to the entrypoint.
    """
    # Warn if they use an outdated python version
    if sys.version_info < (3, 6):
        print(
            'Warning: Your Python version is out of date! Some subcommands may not work!'
        )
        print('Please upgrade to Python 3.6 or later.')

    # Environment setup
    import qmk_cli
    milc.cli.version = qmk_cli.__version__
    qmk_firmware = find_qmk_firmware()
    os.environ['QMK_HOME'] = str(qmk_firmware)
    os.environ['ORIG_CWD'] = os.getcwd()

    # Import the subcommand modules
    import qmk_cli.subcommands

    if qmk_firmware.exists():
        os.chdir(str(qmk_firmware))
        sys.path.append(str(qmk_firmware / 'lib' / 'python'))
        import qmk.cli

    # Call the entrypoint
    milc.cli()
Ejemplo n.º 2
0
def main():
    """Setup the environment before dispatching to the entrypoint.
    """
    # Warn if they use an outdated python version
    if sys.version_info < (3, 6):
        print(
            'Warning: Your Python version is out of date! Some subcommands may not work!'
        )
        print('Please upgrade to Python 3.6 or later.')

    if 'windows' in platform.platform().lower():
        if 'mingw64' not in sys.executable or 'mingw64' not in os.environ.get(
                'MSYSTEM_PREFIX', ''):
            print('Warning: It seems you are not using the MINGW64 terminal.')
            print(
                'While the MSYS one can work, too, we recommend/support you start "MSYS2 MinGW 64-bit".\n'
            )

    # Environment setup
    import qmk_cli
    milc.cli.version = qmk_cli.__version__
    qmk_firmware = find_qmk_firmware()
    os.environ['QMK_HOME'] = str(qmk_firmware)
    os.environ['ORIG_CWD'] = os.getcwd()

    # Import the subcommand modules
    import qmk_cli.subcommands

    if qmk_firmware.exists():
        os.chdir(str(qmk_firmware))
        sys.path.append(str(qmk_firmware / 'lib' / 'python'))
        try:
            import qmk.cli
        except ImportError:
            if qmk_firmware.name != 'qmk_firmware':
                print(
                    'Warning: %s does not end in "qmk_firmware". Do you need to set QMK_HOME to "%s/qmk_firmware"?'
                    % (qmk_firmware, qmk_firmware))

            print('Error: %s is too old or not set up correctly!' %
                  qmk_firmware)
            print(
                'Please update it or remove it completely before continuing.')
            sys.exit(1)

    # Call the entrypoint
    return_code = milc.cli()

    if return_code is False:
        exit(1)

    elif return_code is not True and isinstance(return_code, int):
        if return_code < 0 or return_code > 255:
            milc.cli.log.error('Invalid return_code: %d', return_code)
            exit(255)

        exit(return_code)

    exit(0)
Ejemplo n.º 3
0
def main():
    """Setup the environment before dispatching to the entrypoint.
    """
    # Environment setup
    qmk_firmware = find_qmk_firmware()
    os.environ['QMK_HOME'] = str(qmk_firmware)
    os.environ['ORIG_CWD'] = os.getcwd()

    # Import the subcommand modules
    import qmk_cli.subcommands

    if qmk_firmware.exists():
        os.chdir(str(qmk_firmware))
        sys.path.append(str(qmk_firmware / 'lib' / 'python'))
        import qmk.cli

    # Call the entrypoint
    milc.cli()
Ejemplo n.º 4
0
def main():
    """Setup the environment before dispatching to the entrypoint.
    """
    # Warn if they use an outdated python version
    if sys.version_info < (3, 7):
        print(
            'Warning: Your Python version is out of date! Some subcommands may not work!'
        )
        print('Please upgrade to Python 3.7 or later.')

    if 'windows' in platform().lower():
        msystem = os.environ.get('MSYSTEM', '')

        if 'mingw64' not in sys.executable or 'MINGW64' not in msystem:
            print('ERROR: It seems you are not using the MINGW64 terminal.')
            print(
                'Please close this terminal and open a new MSYS2 MinGW 64-bit terminal.'
            )
            print('Python: %s, MSYSTEM: %s' % (sys.executable, msystem))
            exit(1)

    # Environment setup
    import qmk_cli
    milc.cli.version = qmk_cli.__version__
    qmk_firmware = find_qmk_firmware()
    os.environ['QMK_HOME'] = str(qmk_firmware)
    os.environ['ORIG_CWD'] = os.getcwd()

    import qmk_cli.subcommands

    # Check out and initialize the qmk_firmware environment
    if is_qmk_firmware(qmk_firmware):
        # All subcommands are run relative to the qmk_firmware root to make it easier to use the right copy of qmk_firmware.
        os.chdir(str(qmk_firmware))

        # Check to make sure we have all the requirements
        broken_modules, broken_dev_modules = broken_module_imports()
        msg_install = 'Please run `python3 -m pip install -r %s` to install required python dependencies.'

        if broken_modules:
            if yesno('Would you like to install the required Python modules?'):
                run_cmd(sys.executable, '-m', 'pip', 'install', '-r',
                        'requirements.txt')
            else:
                print()
                print(msg_install %
                      (os.environ['QMK_HOME'] + '/requirements.txt', ))
                print()
                exit(1)

        if broken_dev_modules:
            if yesno(
                    'Would you like to install the required developer Python modules?'
            ):
                run_cmd(sys.executable, '-m', 'pip', 'install', '-r',
                        'requirements.txt')
            else:
                print()
                print(msg_install %
                      (os.environ['QMK_HOME'] + '/requirements-dev.txt', ))
                print(
                    'You can also turn off developer mode: qmk config user.developer=None'
                )
                print()
                exit(1)

        # Environment looks good, include the qmk_firmware subcommands
        sys.path.append(str(qmk_firmware / 'lib/python'))

        try:
            import qmk.cli  # noqa

        except ImportError as e:
            if qmk_firmware.name != 'qmk_firmware':
                print(
                    'Warning: %s does not end in "qmk_firmware". Do you need to set QMK_HOME to "%s/qmk_firmware"?'
                    % (qmk_firmware, qmk_firmware))

            print('Error: %s: %s', (e.__class__.__name__, e))
            print_exc()
            sys.exit(1)

    # Call the entrypoint
    return_code = milc.cli()

    if return_code is False:
        exit(1)

    elif return_code is not True and isinstance(return_code, int):
        if return_code < 0 or return_code > 255:
            milc.cli.log.error('Invalid return_code: %d', return_code)
            exit(255)

        exit(return_code)

    exit(0)
Ejemplo n.º 5
0
def main():
    """Setup the environment before dispatching to the entrypoint.
    """
    # Warn if they use an outdated python version
    if sys.version_info < (3, 7):
        print(
            'Warning: Your Python version is out of date! Some subcommands may not work!'
        )
        print('Please upgrade to Python 3.7 or later.')

    if 'windows' in platform().lower():
        msystem = os.environ.get('MSYSTEM', '')

        if 'mingw64' not in sys.executable or 'MINGW64' not in msystem:
            print('ERROR: It seems you are not using the MINGW64 terminal.')
            print(
                'Please close this terminal and open a new MSYS2 MinGW 64-bit terminal.'
            )
            print('Python: %s, MSYSTEM: %s' % (sys.executable, msystem))
            exit(1)

    # Environment setup
    qmk_firmware = find_qmk_firmware()
    os.environ['QMK_HOME'] = str(qmk_firmware)
    os.environ['ORIG_CWD'] = os.getcwd()

    import qmk_cli.subcommands

    # Check out and initialize the qmk_firmware environment
    if is_qmk_firmware(qmk_firmware):
        # All subcommands are run relative to the qmk_firmware root to make it easier to use the right copy of qmk_firmware.
        os.chdir(str(qmk_firmware))
        sys.path.append(str(qmk_firmware / 'lib/python'))

        try:
            import qmk.cli  # noqa

        except ImportError as e:
            if qmk_firmware.name != 'qmk_firmware':
                print(
                    'Warning: %s does not end in "qmk_firmware". Do you need to set QMK_HOME to "%s/qmk_firmware"?'
                    % (qmk_firmware, qmk_firmware))

            print('Error: %s: %s', (e.__class__.__name__, e))
            print_exc()
            sys.exit(1)

    # Call the entrypoint
    return_code = milc.cli()

    if return_code is False:
        exit(1)

    elif return_code is not True and isinstance(return_code, int):
        if return_code < 0 or return_code > 255:
            milc.cli.log.error('Invalid return_code: %d', return_code)
            exit(255)

        exit(return_code)

    exit(0)
Ejemplo n.º 6
0
              '--host',
              arg_only=True,
              default='127.0.0.1',
              help='IP to listen on.')
@cli.argument('-p',
              '--port',
              arg_only=True,
              default=8937,
              type=int,
              help='Port number to use.')
@cli.entrypoint('Run a local webserver.')
def docs(cli):
    """Spin up a local HTTPServer instance.
    """
    with http.server.HTTPServer((cli.args.host, cli.args.port),
                                http.server.SimpleHTTPRequestHandler) as httpd:
        cli.log.info("Serving QMK docs at http://%s:%d/", cli.args.host,
                     cli.args.port)
        cli.log.info("Press Control+C to exit.")

        try:
            httpd.serve_forever()
        except KeyboardInterrupt:
            cli.log.info("Stopping HTTP server...")
        finally:
            httpd.shutdown()


if __name__ == '__main__':
    cli()