Пример #1
0
def exec_command(*args, **kwargs):
    result = {"out": None, "err": None, "returncode": None}

    default = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    default.update(kwargs)
    kwargs = default

    p = subprocess.Popen(*args, **kwargs)
    try:
        result["out"], result["err"] = p.communicate()
        result["returncode"] = p.returncode
    except KeyboardInterrupt:
        raise exception.AbortedByUser()
    finally:
        for s in ("stdout", "stderr"):
            if isinstance(kwargs[s], AsyncPipeBase):
                kwargs[s].close()

    for s in ("stdout", "stderr"):
        if isinstance(kwargs[s], AsyncPipeBase):
            result[s[3:]] = kwargs[s].get_buffer()

    for k, v in result.items():
        if PY2 and isinstance(v, unicode):  # pylint: disable=undefined-variable
            result[k] = v.encode()
        elif not PY2 and isinstance(result[k], bytes):
            try:
                result[k] = result[k].decode(get_locale_encoding()
                                             or get_filesystem_encoding())
            except UnicodeDecodeError:
                result[k] = result[k].decode("latin-1")
        if v and isinstance(v, string_types):
            result[k] = result[k].strip()

    return result
Пример #2
0
def exec_command(*args, **kwargs):
    result = {"out": None, "err": None, "returncode": None}

    default = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    default.update(kwargs)
    kwargs = default

    p = subprocess.Popen(*args, **kwargs)
    try:
        result['out'], result['err'] = p.communicate()
        result['returncode'] = p.returncode
    except KeyboardInterrupt:
        raise exception.AbortedByUser()
    finally:
        for s in ("stdout", "stderr"):
            if isinstance(kwargs[s], AsyncPipe):
                kwargs[s].close()

    for s in ("stdout", "stderr"):
        if isinstance(kwargs[s], AsyncPipe):
            result[s[3:]] = "\n".join(kwargs[s].get_buffer())

    for k, v in result.iteritems():
        if v and isinstance(v, basestring):
            result[k].strip()

    return result
Пример #3
0
def exec_command(*args, **kwargs):
    result = {"out": None, "err": None, "returncode": None}

    default = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    default.update(kwargs)
    kwargs = default

    p = subprocess.Popen(*args, **kwargs)
    try:
        result['out'], result['err'] = p.communicate()
        result['returncode'] = p.returncode
    except KeyboardInterrupt:
        raise exception.AbortedByUser()
    finally:
        for s in ("stdout", "stderr"):
            if isinstance(kwargs[s], AsyncPipeBase):
                kwargs[s].close()

    for s in ("stdout", "stderr"):
        if isinstance(kwargs[s], AsyncPipeBase):
            result[s[3:]] = kwargs[s].get_buffer()

    for k, v in result.items():
        if isinstance(result[k], bytes):
            try:
                result[k] = result[k].decode(sys.getdefaultencoding())
            except UnicodeDecodeError:
                result[k] = result[k].decode("latin-1")
        if v and isinstance(v, string_types):
            result[k] = result[k].strip()

    return result
Пример #4
0
def exec_command(*args, **kwargs):
    result = {
        "out": None,
        "err": None,
        "returncode": None
    }

    tempPath = tempfile.gettempdir() + os.sep + "w2bInAuxiliary.w2b" # [JORGE_GARCIA] modified for non console in windows
    with open(tempPath, "w"):
        pass


    default = dict(
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        stdin=open(tempPath, "r"),  # [JORGE_GARCIA] modified for non console in windows
        shell=system() == "Windows"
    )
    default.update(kwargs)
    kwargs = default

    p = subprocess.Popen(*args, **kwargs)
    try:
        result['out'], result['err'] = p.communicate()
        result['returncode'] = p.returncode
    except KeyboardInterrupt:
        raise exception.AbortedByUser()
    finally:
        for s in ("stdout", "stderr"):
            if isinstance(kwargs[s], AsyncPipe):
                kwargs[s].close()

    for s in ("stdout", "stderr"):
        if isinstance(kwargs[s], AsyncPipe):
            result[s[3:]] = "\n".join(kwargs[s].get_buffer())

    for k, v in result.iteritems():
        if v and isinstance(v, basestring):
            result[k].strip()

    return result
Пример #5
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")
Пример #6
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")
Пример #7
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"
    )