Example #1
0
def cli(
        ctx,  # pylint: disable=R0913
        project_dir,
        board,
        ide,
        project_option,
        env_prefix,
        silent):

    if not silent:
        if project_dir == getcwd():
            click.secho("\nThe current working directory",
                        fg="yellow",
                        nl=False)
            click.secho(" %s " % project_dir, fg="cyan", nl=False)
            click.secho(
                "will be used for project.\n"
                "You can specify another project directory via\n"
                "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
                fg="yellow")
            click.echo("")

        click.echo("The next files/directories have been created in %s" %
                   click.style(project_dir, fg="cyan"))
        click.echo("%s - Project Configuration File" %
                   click.style("platformio.ini", fg="cyan"))
        click.echo("%s - Put your source files here" %
                   click.style("src", fg="cyan"))
        click.echo("%s - Put here project specific (private) libraries" %
                   click.style("lib", fg="cyan"))

    init_base_project(project_dir)

    if board:
        fill_project_envs(ctx, project_dir, board, project_option, env_prefix,
                          ide is not None)

    if ide:
        env_name = get_best_envname(project_dir, board)
        if not env_name:
            raise exception.BoardNotDefined()
        pg = ProjectGenerator(project_dir, ide, env_name)
        pg.generate()

    if not silent:
        click.secho(
            "\nProject has been successfully initialized!\nUseful commands:\n"
            "`platformio run` - process/build project from the current "
            "directory\n"
            "`platformio run --target upload` or `platformio run -t upload` "
            "- upload firmware to embedded board\n"
            "`platformio run --target clean` - clean project (remove compiled "
            "files)\n"
            "`platformio run --help` - additional information",
            fg="green")
Example #2
0
def cli(
        ctx,  # pylint: disable=R0913
        project_dir,
        board,
        ide,
        project_option,
        env_prefix,
        silent):

    if not silent:
        if project_dir == getcwd():
            click.secho(
                "\nThe current working directory", fg="yellow", nl=False)
            click.secho(" %s " % project_dir, fg="cyan", nl=False)
            click.secho(
                "will be used for project.\n"
                "You can specify another project directory via\n"
                "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
                fg="yellow")
            click.echo("")

        click.echo("The next files/directories have been created in %s" %
                   click.style(project_dir, fg="cyan"))
        click.echo("%s - Project Configuration File" % click.style(
            "platformio.ini", fg="cyan"))
        click.echo(
            "%s - Put your source files here" % click.style("src", fg="cyan"))
        click.echo("%s - Put here project specific (private) libraries" %
                   click.style("lib", fg="cyan"))

    init_base_project(project_dir)

    if board:
        fill_project_envs(ctx, project_dir, board, project_option, env_prefix,
                          ide is not None)

    if ide:
        env_name = get_best_envname(project_dir, board)
        if not env_name:
            raise exception.BoardNotDefined()
        pg = ProjectGenerator(project_dir, ide, env_name)
        pg.generate()

    if not silent:
        click.secho(
            "\nProject has been successfully initialized!\nUseful commands:\n"
            "`platformio run` - process/build project from the current "
            "directory\n"
            "`platformio run --target upload` or `platformio run -t upload` "
            "- upload firmware to embedded board\n"
            "`platformio run --target clean` - clean project (remove compiled "
            "files)\n"
            "`platformio run --help` - additional information",
            fg="green")
def measure_caller(calller_id):
    calller_id = str(calller_id)[:20].lower()
    event = {
        "category": "Caller",
        "action": "Misc",
        "label": calller_id
    }
    if calller_id in (["atom", "vim"] + ProjectGenerator.get_supported_ides()):
        event['action'] = "IDE"
    on_event(**event)
Example #4
0
 def init(self, board, framework, project_dir):
     assert project_dir
     state = AppRPC.load_state()
     if not isdir(project_dir):
         os.makedirs(project_dir)
     args = ["init", "--board", board]
     if framework:
         args.extend(["--project-option", "framework = %s" % framework])
     if (state['storage']['coreCaller'] and state['storage']['coreCaller']
             in ProjectGenerator.get_supported_ides()):
         args.extend(["--ide", state['storage']['coreCaller']])
     d = PIOCoreRPC.call(args, options={"cwd": project_dir})
     d.addCallback(self._generate_project_main, project_dir, framework)
     return d
Example #5
0
 async def init(self, board, framework, project_dir):
     assert project_dir
     state = AppRPC.load_state()
     if not os.path.isdir(project_dir):
         os.makedirs(project_dir)
     args = ["init", "--board", board]
     if framework:
         args.extend(["--project-option", "framework = %s" % framework])
     if (state["storage"]["coreCaller"] and state["storage"]["coreCaller"]
             in ProjectGenerator.get_supported_ides()):
         args.extend(["--ide", state["storage"]["coreCaller"]])
     await PIOCoreRPC.call(args,
                           options={
                               "cwd": project_dir,
                               "force_subprocess": True
                           })
     return self._generate_project_main(project_dir, framework)
Example #6
0
    async def import_arduino(self, board, use_arduino_libs,
                             arduino_project_dir):
        board = str(board)
        # don't import PIO Project
        if is_platformio_project(arduino_project_dir):
            return arduino_project_dir

        is_arduino_project = any([
            os.path.isfile(
                os.path.join(
                    arduino_project_dir,
                    "%s.%s" % (os.path.basename(arduino_project_dir), ext),
                )) for ext in ("ino", "pde")
        ])
        if not is_arduino_project:
            raise jsonrpc.exceptions.JSONRPCDispatchException(
                code=4000,
                message="Not an Arduino project: %s" % arduino_project_dir)

        state = AppRPC.load_state()
        project_dir = os.path.join(state["storage"]["projectsDir"],
                                   time.strftime("%y%m%d-%H%M%S-") + board)
        if not os.path.isdir(project_dir):
            os.makedirs(project_dir)
        args = ["init", "--board", board]
        args.extend(["--project-option", "framework = arduino"])
        if use_arduino_libs:
            args.extend([
                "--project-option",
                "lib_extra_dirs = ~/Documents/Arduino/libraries"
            ])
        if (state["storage"]["coreCaller"] and state["storage"]["coreCaller"]
                in ProjectGenerator.get_supported_ides()):
            args.extend(["--ide", state["storage"]["coreCaller"]])
        await PIOCoreRPC.call(args,
                              options={
                                  "cwd": project_dir,
                                  "force_subprocess": True
                              })
        with fs.cd(project_dir):
            config = ProjectConfig()
            src_dir = config.get_optional_dir("src")
            if os.path.isdir(src_dir):
                fs.rmtree(src_dir)
            shutil.copytree(arduino_project_dir, src_dir, symlinks=True)
        return project_dir
Example #7
0
    def import_pio(project_dir):
        if not project_dir or not is_platformio_project(project_dir):
            raise jsonrpc.exceptions.JSONRPCDispatchException(
                code=4001,
                message="Not an PlatformIO project: %s" % project_dir)
        new_project_dir = join(
            AppRPC.load_state()['storage']['projectsDir'],
            time.strftime("%y%m%d-%H%M%S-") + basename(project_dir))
        shutil.copytree(project_dir, new_project_dir)

        state = AppRPC.load_state()
        args = ["init"]
        if (state['storage']['coreCaller'] and state['storage']['coreCaller']
                in ProjectGenerator.get_supported_ides()):
            args.extend(["--ide", state['storage']['coreCaller']])
        d = PIOCoreRPC.call(args, options={"cwd": new_project_dir})
        d.addCallback(lambda _: new_project_dir)
        return d
Example #8
0
    def import_arduino(self, board, use_arduino_libs, arduino_project_dir):
        board = str(board)
        if arduino_project_dir and PY2:
            arduino_project_dir = arduino_project_dir.encode(
                get_filesystem_encoding())
        # don't import PIO Project
        if is_platformio_project(arduino_project_dir):
            return arduino_project_dir

        is_arduino_project = any([
            os.path.isfile(
                os.path.join(
                    arduino_project_dir,
                    "%s.%s" % (os.path.basename(arduino_project_dir), ext),
                )) for ext in ("ino", "pde")
        ])
        if not is_arduino_project:
            raise jsonrpc.exceptions.JSONRPCDispatchException(
                code=4000,
                message="Not an Arduino project: %s" % arduino_project_dir)

        state = AppRPC.load_state()
        project_dir = os.path.join(state["storage"]["projectsDir"],
                                   time.strftime("%y%m%d-%H%M%S-") + board)
        if not os.path.isdir(project_dir):
            os.makedirs(project_dir)
        args = ["init", "--board", board]
        args.extend(["--project-option", "framework = arduino"])
        if use_arduino_libs:
            args.extend([
                "--project-option",
                "lib_extra_dirs = ~/Documents/Arduino/libraries"
            ])
        if (state["storage"]["coreCaller"] and state["storage"]["coreCaller"]
                in ProjectGenerator.get_supported_ides()):
            args.extend(["--ide", state["storage"]["coreCaller"]])
        d = PIOCoreRPC.call(args,
                            options={
                                "cwd": project_dir,
                                "force_subprocess": True
                            })
        d.addCallback(self._finalize_arduino_import, project_dir,
                      arduino_project_dir)
        return d
Example #9
0
    async def import_pio(project_dir):
        if not project_dir or not is_platformio_project(project_dir):
            raise JSONRPC20DispatchException(
                code=4001,
                message="Not an PlatformIO project: %s" % project_dir)
        new_project_dir = os.path.join(
            AppRPC.load_state()["storage"]["projectsDir"],
            time.strftime("%y%m%d-%H%M%S-") + os.path.basename(project_dir),
        )
        shutil.copytree(project_dir, new_project_dir, symlinks=True)

        state = AppRPC.load_state()
        args = ["init"]
        if (state["storage"]["coreCaller"] and state["storage"]["coreCaller"]
                in ProjectGenerator.get_supported_ides()):
            args.extend(["--ide", state["storage"]["coreCaller"]])
        await PIOCoreRPC.call(args,
                              options={
                                  "cwd": new_project_dir,
                                  "force_subprocess": True
                              })
        return new_project_dir
Example #10
0
def cli(
        ctx,  # pylint: disable=R0913
        project_dir,
        board,
        ide,
        project_option,
        env_prefix):

    if project_dir == getcwd():
        click.secho("\nThe current working directory", fg="yellow", nl=False)
        click.secho(" %s " % project_dir, fg="cyan", nl=False)
        click.secho(
            "will be used for project.\n"
            "You can specify another project directory via\n"
            "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
            fg="yellow")
        click.echo("")

    click.echo("The next files/directories have been created in %s" %
               click.style(
                   project_dir, fg="cyan"))
    click.echo("%s - Project Configuration File" % click.style(
        "platformio.ini", fg="cyan"))
    click.echo("%s - Put your source files here" % click.style(
        "src", fg="cyan"))
    click.echo("%s - Put here project specific (private) libraries" %
               click.style(
                   "lib", fg="cyan"))

    init_base_project(project_dir)

    if board:
        fill_project_envs(ctx, project_dir, board, project_option, env_prefix,
                          ide is not None)

    if ide:
        if not board:
            board = get_first_board(project_dir)
            if board:
                board = [board]
        if not board:
            raise exception.BoardNotDefined()
        if len(board) > 1:
            click.secho(
                "Warning! You have initialised project with more than 1 board"
                " for the specified IDE.\n"
                "However, the IDE features (code autocompletion, syntax "
                "linter) have been configured for the first board '%s' from "
                "your list '%s'." % (board[0], ", ".join(board)),
                fg="yellow")
        pg = ProjectGenerator(project_dir, ide, board[0])
        pg.generate()

    click.secho(
        "\nProject has been successfully initialized!\nUseful commands:\n"
        "`platformio run` - process/build project from the current "
        "directory\n"
        "`platformio run --target upload` or `platformio run -t upload` "
        "- upload firmware to embedded board\n"
        "`platformio run --target clean` - clean project (remove compiled "
        "files)\n"
        "`platformio run --help` - additional information",
        fg="green")
Example #11
0
def cli(project_dir, board, ide, disable_auto_uploading, env_prefix):

    # ask about auto-uploading
    if board and app.get_setting("enable_prompts"):
        disable_auto_uploading = not click.confirm(
            "Would you like to enable firmware auto-uploading when project "
            "is successfully built using `platformio run` command? \n"
            "Don't forget that you can upload firmware manually using "
            "`platformio run --target upload` command."
        )
        click.echo("")

    if project_dir == getcwd():
        click.secho("\nThe current working directory", fg="yellow", nl=False)
        click.secho(" %s " % project_dir, fg="cyan", nl=False)
        click.secho(
            "will be used for project.\n"
            "You can specify another project directory via\n"
            "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
            fg="yellow"
        )
        click.echo("")

    click.echo("The next files/directories will be created in %s" %
               click.style(project_dir, fg="cyan"))
    click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" %
               click.style("platformio.ini", fg="cyan"))
    click.echo("%s - Put your source code here" %
               click.style("src", fg="cyan"))
    click.echo("%s - Put here project specific or 3-rd party libraries" %
               click.style("lib", fg="cyan"))

    if (app.get_setting("enable_prompts") and
            not click.confirm("Do you want to continue?")):
        raise exception.AbortedByUser()

    project_file = join(project_dir, "platformio.ini")
    src_dir = join(project_dir, "src")
    lib_dir = join(project_dir, "lib")

    for d in (src_dir, lib_dir):
        if not isdir(d):
            makedirs(d)

    if not isfile(project_file):
        copyfile(join(get_source_dir(), "projectconftpl.ini"),
                 project_file)

    if board:
        fill_project_envs(
            project_file, board, disable_auto_uploading, env_prefix)

    if ide:
        pg = ProjectGenerator(project_dir, ide, board[0] if board else None)
        pg.generate()

    click.secho(
        "\nProject has been successfully initialized!\nUseful commands:\n"
        "`platformio run` - process/build project from the current "
        "directory\n"
        "`platformio run --target upload` or `platformio run -t upload` "
        "- upload firmware to embedded board\n"
        "`platformio run --target clean` - clean project (remove compiled "
        "files)",
        fg="green"
    )
Example #12
0
def cli(project_dir, board, ide, disable_auto_uploading, env_prefix):

    # ask about auto-uploading
    if board and app.get_setting("enable_prompts"):
        disable_auto_uploading = not click.confirm(
            "Would you like to enable firmware auto-uploading when project "
            "is successfully built using `platformio run` command? \n"
            "Don't forget that you can upload firmware manually using "
            "`platformio run --target upload` command.")
        click.echo("")

    if project_dir == getcwd():
        click.secho("\nThe current working directory", fg="yellow", nl=False)
        click.secho(" %s " % project_dir, fg="cyan", nl=False)
        click.secho(
            "will be used for project.\n"
            "You can specify another project directory via\n"
            "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
            fg="yellow")
        click.echo("")

    click.echo("The next files/directories will be created in %s" %
               click.style(project_dir, fg="cyan"))
    click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" %
               click.style("platformio.ini", fg="cyan"))
    click.echo("%s - Put your source code here" %
               click.style("src", fg="cyan"))
    click.echo("%s - Put here project specific or 3-rd party libraries" %
               click.style("lib", fg="cyan"))

    if (app.get_setting("enable_prompts")
            and not click.confirm("Do you want to continue?")):
        raise exception.AbortedByUser()

    project_file = join(project_dir, "platformio.ini")
    src_dir = join(project_dir, "src")
    lib_dir = join(project_dir, "lib")

    for d in (src_dir, lib_dir):
        if not isdir(d):
            makedirs(d)

    if not isfile(project_file):
        copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file)

    if board:
        fill_project_envs(project_file, board, disable_auto_uploading,
                          env_prefix)

    if ide:
        pg = ProjectGenerator(project_dir, ide)
        pg.generate()

    click.secho(
        "\nProject has been successfully initialized!\nUseful commands:\n"
        "`platformio run` - process/build project from the current "
        "directory\n"
        "`platformio run --target upload` or `platformio run -t upload` "
        "- upload firmware to embedded board\n"
        "`platformio run --target clean` - clean project (remove compiled "
        "files)",
        fg="green")
Example #13
0
def measure_caller(calller_id):
    calller_id = str(calller_id)[:20].lower()
    event = {"category": "Caller", "action": "Misc", "label": calller_id}
    if calller_id in (["atom", "vim"] + ProjectGenerator.get_supported_ides()):
        event['action'] = "IDE"
    on_event(**event)
Example #14
0
def cli(ctx, project_dir, board, ide,  # pylint: disable=R0913
        enable_auto_uploading, env_prefix):

    if project_dir == getcwd():
        click.secho("\nThe current working directory", fg="yellow", nl=False)
        click.secho(" %s " % project_dir, fg="cyan", nl=False)
        click.secho(
            "will be used for project.\n"
            "You can specify another project directory via\n"
            "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
            fg="yellow"
        )
        click.echo("")

    click.echo("The next files/directories will be created in %s" %
               click.style(project_dir, fg="cyan"))
    click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" %
               click.style("platformio.ini", fg="cyan"))
    click.echo("%s - Put your source files here" %
               click.style("src", fg="cyan"))
    click.echo("%s - Put here project specific (private) libraries" %
               click.style("lib", fg="cyan"))

    if (app.get_setting("enable_prompts") and
            not click.confirm("Do you want to continue?")):
        raise exception.AbortedByUser()

    project_file = join(project_dir, "platformio.ini")
    src_dir = join(project_dir, "src")
    lib_dir = join(project_dir, "lib")

    for d in (src_dir, lib_dir):
        if not isdir(d):
            makedirs(d)

    init_lib_readme(lib_dir)
    init_ci_conf(project_dir)
    init_cvs_ignore(project_dir)

    if not isfile(project_file):
        copyfile(join(get_source_dir(), "projectconftpl.ini"),
                 project_file)

    if board:
        fill_project_envs(
            ctx, project_file, board, enable_auto_uploading, env_prefix,
            ide is not None
        )

    if ide:
        if not board:
            raise exception.BoardNotDefined()
        if len(board) > 1:
            click.secho(
                "Warning! You have initialised project with more than 1 board"
                " for the specified IDE.\n"
                "However, the IDE features (code autocompletion, syntax lint)"
                " have been configured for the first board '%s' from your list"
                " '%s'." % (board[0], ", ".join(board)),
                fg="yellow"
            )
        pg = ProjectGenerator(
            project_dir, ide, board[0])
        pg.generate()

    click.secho(
        "\nProject has been successfully initialized!\nUseful commands:\n"
        "`platformio run` - process/build project from the current "
        "directory\n"
        "`platformio run --target upload` or `platformio run -t upload` "
        "- upload firmware to embedded board\n"
        "`platformio run --target clean` - clean project (remove compiled "
        "files)\n"
        "`platformio run --help` - additional information",
        fg="green"
    )
Example #15
0
        assert not unknown_boards
        return value
    except AssertionError:
        raise click.BadParameter(
            "%s. Please search for the board types using "
            "`platformio boards` command" % ", ".join(unknown_boards))


@click.command("init", short_help="Initialize new PlatformIO based project")
@click.option("--project-dir", "-d", default=getcwd,
              type=click.Path(exists=True, file_okay=False, dir_okay=True,
                              writable=True, resolve_path=True))
@click.option("--board", "-b", multiple=True, metavar="TYPE",
              callback=validate_boards)
@click.option("--ide",
              type=click.Choice(ProjectGenerator.get_supported_ides()))
@click.option("--enable-auto-uploading", is_flag=True)
@click.option("--env-prefix", default="")
@click.pass_context
def cli(ctx, project_dir, board, ide,  # pylint: disable=R0913
        enable_auto_uploading, env_prefix):

    if project_dir == getcwd():
        click.secho("\nThe current working directory", fg="yellow", nl=False)
        click.secho(" %s " % project_dir, fg="cyan", nl=False)
        click.secho(
            "will be used for project.\n"
            "You can specify another project directory via\n"
            "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
            fg="yellow"
        )
Example #16
0
def cli(
        ctx,
        project_dir,
        board,
        ide,  # pylint: disable=R0913
        disable_auto_uploading,
        env_prefix):

    # ask about auto-uploading
    if board and app.get_setting("enable_prompts"):
        disable_auto_uploading = not click.confirm(
            "Would you like to enable firmware auto-uploading when project "
            "is successfully built using `platformio run` command? \n"
            "Don't forget that you can upload firmware manually using "
            "`platformio run --target upload` command.")
        click.echo("")

    if project_dir == getcwd():
        click.secho("\nThe current working directory", fg="yellow", nl=False)
        click.secho(" %s " % project_dir, fg="cyan", nl=False)
        click.secho(
            "will be used for project.\n"
            "You can specify another project directory via\n"
            "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
            fg="yellow")
        click.echo("")

    click.echo("The next files/directories will be created in %s" %
               click.style(project_dir, fg="cyan"))
    click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" %
               click.style("platformio.ini", fg="cyan"))
    click.echo("%s - Put your source files here" %
               click.style("src", fg="cyan"))
    click.echo("%s - Put here project specific (private) libraries" %
               click.style("lib", fg="cyan"))

    if (app.get_setting("enable_prompts")
            and not click.confirm("Do you want to continue?")):
        raise exception.AbortedByUser()

    project_file = join(project_dir, "platformio.ini")
    src_dir = join(project_dir, "src")
    lib_dir = join(project_dir, "lib")

    for d in (src_dir, lib_dir):
        if not isdir(d):
            makedirs(d)

    if not isfile(join(lib_dir, "readme.txt")):
        with open(join(lib_dir, "readme.txt"), "w") as f:
            f.write("""
This directory is intended for the project specific (private) libraries.
PlatformIO will compile them to static libraries and link to executable file.

The source code of each library should be placed in separate directory, like
"lib/private_lib/[here are source files]".

For example, see how can be organised `Foo` and `Bar` libraries:

|--lib
|  |--Bar
|  |  |--docs
|  |  |--examples
|  |  |--src
|  |     |- Bar.c
|  |     |- Bar.h
|  |--Foo
|  |  |- Foo.c
|  |  |- Foo.h
|  |- readme.txt --> THIS FILE
|- platformio.ini
|--src
   |- main.c

Then in `src/main.c` you should use:

#include <Foo.h>
#include <Bar.h>

// rest H/C/CPP code

PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.

See additional options for PlatformIO Library Dependency Finder `lib_*`:

http://docs.platformio.org/en/latest/projectconf.html#lib-install

""")

    if not isfile(project_file):
        copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file)

    if board:
        fill_project_envs(ctx, project_file, board, disable_auto_uploading,
                          env_prefix)

    if ide:
        pg = ProjectGenerator(project_dir, ide, board[0] if board else None)
        pg.generate()

    click.secho(
        "\nProject has been successfully initialized!\nUseful commands:\n"
        "`platformio run` - process/build project from the current "
        "directory\n"
        "`platformio run --target upload` or `platformio run -t upload` "
        "- upload firmware to embedded board\n"
        "`platformio run --target clean` - clean project (remove compiled "
        "files)",
        fg="green")
Example #17
0
def cli(
        ctx,  # pylint: disable=R0913
        project_dir,
        board,
        ide,
        project_option,
        env_prefix,
        silent):
    if not silent:
        if project_dir == getcwd():
            click.secho("\nThe current working directory",
                        fg="yellow",
                        nl=False)
            click.secho(" %s " % project_dir, fg="cyan", nl=False)
            click.secho("will be used for the project.", fg="yellow")
            click.echo("")

        click.echo("The next files/directories have been created in %s" %
                   click.style(project_dir, fg="cyan"))
        click.echo("%s - Put project header files here" %
                   click.style("include", fg="cyan"))
        click.echo("%s - Put here project specific (private) libraries" %
                   click.style("lib", fg="cyan"))
        click.echo("%s - Put project source files here" %
                   click.style("src", fg="cyan"))
        click.echo("%s - Project Configuration File" %
                   click.style("platformio.ini", fg="cyan"))

    is_new_project = not is_platformio_project(project_dir)
    if is_new_project:
        init_base_project(project_dir)

    if board:
        fill_project_envs(ctx, project_dir, board, project_option, env_prefix,
                          ide is not None)

    if ide:
        pg = ProjectGenerator(project_dir, ide, board)
        pg.generate()

    if is_new_project:
        init_ci_conf(project_dir)
        init_cvs_ignore(project_dir)

    if silent:
        return

    if ide:
        click.secho(
            "\nProject has been successfully %s including configuration files "
            "for `%s` IDE." %
            ("initialized" if is_new_project else "updated", ide),
            fg="green")
    else:
        click.secho(
            "\nProject has been successfully %s! Useful commands:\n"
            "`pio run` - process/build project from the current directory\n"
            "`pio run --target upload` or `pio run -t upload` "
            "- upload firmware to a target\n"
            "`pio run --target clean` - clean project (remove compiled files)"
            "\n`pio run --help` - additional information" %
            ("initialized" if is_new_project else "updated"),
            fg="green")
Example #18
0
def cli(ctx, project_dir, board, ide,  # pylint: disable=R0913
        disable_auto_uploading, env_prefix):

    # ask about auto-uploading
    if board and app.get_setting("enable_prompts"):
        disable_auto_uploading = not click.confirm(
            "Would you like to enable firmware auto-uploading when project "
            "is successfully built using `platformio run` command? \n"
            "Don't forget that you can upload firmware manually using "
            "`platformio run --target upload` command."
        )
        click.echo("")

    if project_dir == getcwd():
        click.secho("\nThe current working directory", fg="yellow", nl=False)
        click.secho(" %s " % project_dir, fg="cyan", nl=False)
        click.secho(
            "will be used for project.\n"
            "You can specify another project directory via\n"
            "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
            fg="yellow"
        )
        click.echo("")

    click.echo("The next files/directories will be created in %s" %
               click.style(project_dir, fg="cyan"))
    click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" %
               click.style("platformio.ini", fg="cyan"))
    click.echo("%s - Put your source files here" %
               click.style("src", fg="cyan"))
    click.echo("%s - Put here project specific (private) libraries" %
               click.style("lib", fg="cyan"))

    if (app.get_setting("enable_prompts") and
            not click.confirm("Do you want to continue?")):
        raise exception.AbortedByUser()

    project_file = join(project_dir, "platformio.ini")
    src_dir = join(project_dir, "src")
    lib_dir = join(project_dir, "lib")

    for d in (src_dir, lib_dir):
        if not isdir(d):
            makedirs(d)

    if not isfile(join(lib_dir, "readme.txt")):
        with open(join(lib_dir, "readme.txt"), "w") as f:
            f.write("""
This directory is intended for the project specific (private) libraries.
PlatformIO will compile them to static libraries and link to executable file.

The source code of each library should be placed in separate directory, like
"lib/private_lib/[here are source files]".

For example, see how can be organised `Foo` and `Bar` libraries:

|--lib
|  |--Bar
|  |  |--docs
|  |  |--examples
|  |  |--src
|  |     |- Bar.c
|  |     |- Bar.h
|  |--Foo
|  |  |- Foo.c
|  |  |- Foo.h
|  |- readme.txt --> THIS FILE
|- platformio.ini
|--src
   |- main.c

Then in `src/main.c` you should use:

#include <Foo.h>
#include <Bar.h>

// rest H/C/CPP code

PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.

See additional options for PlatformIO Library Dependency Finder `lib_*`:

http://docs.platformio.org/en/latest/projectconf.html#lib-install

""")

    if not isfile(project_file):
        copyfile(join(get_source_dir(), "projectconftpl.ini"),
                 project_file)

    if board:
        fill_project_envs(
            ctx, project_file, board, disable_auto_uploading, env_prefix)

    if ide:
        pg = ProjectGenerator(project_dir, ide, board[0] if board else None)
        pg.generate()

    click.secho(
        "\nProject has been successfully initialized!\nUseful commands:\n"
        "`platformio run` - process/build project from the current "
        "directory\n"
        "`platformio run --target upload` or `platformio run -t upload` "
        "- upload firmware to embedded board\n"
        "`platformio run --target clean` - clean project (remove compiled "
        "files)",
        fg="green"
    )
Example #19
0
def cli(
        ctx,  # pylint: disable=R0913
        project_dir,
        board,
        ide,
        project_option,
        env_prefix,
        silent):

    if not silent:
        if project_dir == getcwd():
            click.secho(
                "\nThe current working directory", fg="yellow", nl=False)
            click.secho(" %s " % project_dir, fg="cyan", nl=False)
            click.secho("will be used for the project.", fg="yellow")
            click.echo("")

        click.echo("The next files/directories have been created in %s" %
                   click.style(project_dir, fg="cyan"))
        click.echo("%s - Put project header files here" % click.style(
            "include", fg="cyan"))
        click.echo("%s - Put here project specific (private) libraries" %
                   click.style("lib", fg="cyan"))
        click.echo("%s - Put project source files here" % click.style(
            "src", fg="cyan"))
        click.echo("%s - Project Configuration File" % click.style(
            "platformio.ini", fg="cyan"))

    is_new_project = not util.is_platformio_project(project_dir)
    init_base_project(project_dir)

    if board:
        fill_project_envs(ctx, project_dir, board, project_option, env_prefix,
                          ide is not None)

    if ide:
        env_name = get_best_envname(project_dir, board)
        if not env_name:
            raise exception.BoardNotDefined()
        pg = ProjectGenerator(project_dir, ide, env_name)
        pg.generate()

    if is_new_project:
        init_ci_conf(project_dir)
        init_cvs_ignore(project_dir)

    if silent:
        return

    if ide:
        click.secho(
            "\nProject has been successfully %s including configuration files "
            "for `%s` IDE." % ("initialized" if is_new_project else "updated",
                               ide),
            fg="green")
    else:
        click.secho(
            "\nProject has been successfully %s! Useful commands:\n"
            "`pio run` - process/build project from the current directory\n"
            "`pio run --target upload` or `pio run -t upload` "
            "- upload firmware to a target\n"
            "`pio run --target clean` - clean project (remove compiled files)"
            "\n`pio run --help` - additional information" %
            ("initialized" if is_new_project else "updated"),
            fg="green")
Example #20
0
               short_help="Initialize PlatformIO project or update existing")
@click.option("--project-dir",
              "-d",
              default=getcwd,
              type=click.Path(exists=True,
                              file_okay=False,
                              dir_okay=True,
                              writable=True,
                              resolve_path=True))
@click.option("-b",
              "--board",
              multiple=True,
              metavar="ID",
              callback=validate_boards)
@click.option("--ide",
              type=click.Choice(ProjectGenerator.get_supported_ides()))
@click.option("-O", "--project-option", multiple=True)
@click.option("--env-prefix", default="")
@click.option("-s", "--silent", is_flag=True)
@click.pass_context
def cli(
        ctx,  # pylint: disable=R0913
        project_dir,
        board,
        ide,
        project_option,
        env_prefix,
        silent):

    if not silent:
        if project_dir == getcwd():
Example #21
0
def cli(ctx, project_dir, board, ide,  # pylint: disable=R0913
        enable_auto_uploading, env_prefix):

    if project_dir == getcwd():
        click.secho("\nThe current working directory", fg="yellow", nl=False)
        click.secho(" %s " % project_dir, fg="cyan", nl=False)
        click.secho(
            "will be used for project.\n"
            "You can specify another project directory via\n"
            "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
            fg="yellow"
        )
        click.echo("")

    click.echo("The next files/directories will be created in %s" %
               click.style(project_dir, fg="cyan"))
    click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" %
               click.style("platformio.ini", fg="cyan"))
    click.echo("%s - Put your source files here" %
               click.style("src", fg="cyan"))
    click.echo("%s - Put here project specific (private) libraries" %
               click.style("lib", fg="cyan"))

    if (app.get_setting("enable_prompts") and
            not click.confirm("Do you want to continue?")):
        raise exception.AbortedByUser()

    project_file = join(project_dir, "platformio.ini")
    src_dir = join(project_dir, "src")
    lib_dir = join(project_dir, "lib")

    for d in (src_dir, lib_dir):
        if not isdir(d):
            makedirs(d)

    init_lib_readme(lib_dir)
    init_ci_conf(project_dir)
    init_cvs_ignore(project_dir)

    if not isfile(project_file):
        copyfile(join(get_source_dir(), "projectconftpl.ini"),
                 project_file)

    if board:
        fill_project_envs(
            ctx, project_file, board, enable_auto_uploading, env_prefix,
            ide is not None
        )

    if ide:
        if not board:
            raise exception.BoardNotDefined()
        if len(board) > 1:
            click.secho(
                "Warning! You have initialised project with more than 1 board"
                " for the specified IDE.\n"
                "However, the IDE features (code autocompletion, syntax lint)"
                " have been configured for the first board '%s' from your list"
                " '%s'." % (board[0], ", ".join(board)),
                fg="yellow"
            )
        pg = ProjectGenerator(
            project_dir, ide, board[0])
        pg.generate()

    click.secho(
        "\nProject has been successfully initialized!\nUseful commands:\n"
        "`platformio run` - process/build project from the current "
        "directory\n"
        "`platformio run --target upload` or `platformio run -t upload` "
        "- upload firmware to embedded board\n"
        "`platformio run --target clean` - clean project (remove compiled "
        "files)\n"
        "`platformio run --help` - additional information",
        fg="green"
    )
Example #22
0
                "command" % id_
            )
    return value


@click.command("init", short_help="Initialize PlatformIO project or update existing")
@click.option(
    "--project-dir",
    "-d",
    default=getcwd,
    type=click.Path(
        exists=True, file_okay=False, dir_okay=True, writable=True, resolve_path=True
    ),
)
@click.option("-b", "--board", multiple=True, metavar="ID", callback=validate_boards)
@click.option("--ide", type=click.Choice(ProjectGenerator.get_supported_ides()))
@click.option("-O", "--project-option", multiple=True)
@click.option("--env-prefix", default="")
@click.option("-s", "--silent", is_flag=True)
@click.pass_context
def cli(
    ctx,  # pylint: disable=R0913
    project_dir,
    board,
    ide,
    project_option,
    env_prefix,
    silent,
):
    if not silent:
        if project_dir == getcwd():
Example #23
0
def cli(
        ctx,  # pylint: disable=R0913
        project_dir,
        board,
        ide,
        project_option,
        env_prefix):

    if project_dir == getcwd():
        click.secho("\nThe current working directory", fg="yellow", nl=False)
        click.secho(" %s " % project_dir, fg="cyan", nl=False)
        click.secho(
            "will be used for project.\n"
            "You can specify another project directory via\n"
            "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
            fg="yellow")
        click.echo("")

    click.echo("The next files/directories have been created in %s" %
               click.style(project_dir, fg="cyan"))
    click.echo("%s - Project Configuration File" %
               click.style("platformio.ini", fg="cyan"))
    click.echo("%s - Put your source files here" %
               click.style("src", fg="cyan"))
    click.echo("%s - Put here project specific (private) libraries" %
               click.style("lib", fg="cyan"))

    init_base_project(project_dir)

    if board:
        fill_project_envs(ctx, project_dir, board, project_option, env_prefix,
                          ide is not None)

    if ide:
        if not board:
            board = get_first_board(project_dir)
            if board:
                board = [board]
        if not board:
            raise exception.BoardNotDefined()
        if len(board) > 1:
            click.secho(
                "Warning! You have initialised project with more than 1 board"
                " for the specified IDE.\n"
                "However, the IDE features (code autocompletion, syntax "
                "linter) have been configured for the first board '%s' from "
                "your list '%s'." % (board[0], ", ".join(board)),
                fg="yellow")
        pg = ProjectGenerator(project_dir, ide, board[0])
        pg.generate()

    click.secho(
        "\nProject has been successfully initialized!\nUseful commands:\n"
        "`platformio run` - process/build project from the current "
        "directory\n"
        "`platformio run --target upload` or `platformio run -t upload` "
        "- upload firmware to embedded board\n"
        "`platformio run --target clean` - clean project (remove compiled "
        "files)\n"
        "`platformio run --help` - additional information",
        fg="green")
Example #24
0
def project_init(
    ctx,  # pylint: disable=R0913
    project_dir,
    board,
    ide,
    environment,
    project_option,
    env_prefix,
    silent,
):
    if not silent:
        if project_dir == os.getcwd():
            click.secho("\nThe current working directory ",
                        fg="yellow",
                        nl=False)
            try:
                click.secho(project_dir, fg="cyan", nl=False)
            except UnicodeEncodeError:
                click.secho(json.dumps(project_dir), fg="cyan", nl=False)
            click.secho(" will be used for the project.", fg="yellow")
            click.echo("")

        click.echo("The next files/directories have been created in ",
                   nl=False)
        try:
            click.secho(project_dir, fg="cyan")
        except UnicodeEncodeError:
            click.secho(json.dumps(project_dir), fg="cyan")
        click.echo("%s - Put project header files here" %
                   click.style("include", fg="cyan"))
        click.echo("%s - Put here project specific (private) libraries" %
                   click.style("lib", fg="cyan"))
        click.echo("%s - Put project source files here" %
                   click.style("src", fg="cyan"))
        click.echo("%s - Project Configuration File" %
                   click.style("platformio.ini", fg="cyan"))

    is_new_project = not is_platformio_project(project_dir)
    if is_new_project:
        init_base_project(project_dir)

    if environment:
        update_project_env(project_dir, environment, project_option)
    elif board:
        update_board_envs(ctx, project_dir, board, project_option, env_prefix,
                          ide is not None)

    if ide:
        with fs.cd(project_dir):
            config = ProjectConfig.get_instance(
                os.path.join(project_dir, "platformio.ini"))
        config.validate()
        pg = ProjectGenerator(config, environment
                              or get_best_envname(config, board), ide)
        pg.generate()

    if is_new_project:
        init_cvs_ignore(project_dir)

    if silent:
        return

    if ide:
        click.secho(
            "\nProject has been successfully %s including configuration files "
            "for `%s` IDE." %
            ("initialized" if is_new_project else "updated", ide),
            fg="green",
        )
    else:
        click.secho(
            "\nProject has been successfully %s! Useful commands:\n"
            "`pio run` - process/build project from the current directory\n"
            "`pio run --target upload` or `pio run -t upload` "
            "- upload firmware to a target\n"
            "`pio run --target clean` - clean project (remove compiled files)"
            "\n`pio run --help` - additional information" %
            ("initialized" if is_new_project else "updated"),
            fg="green",
        )