diff --git a/platformio/commands/init.py b/platformio/commands/init.py new file mode 100644 index 00000000..10e3670a --- /dev/null +++ b/platformio/commands/init.py @@ -0,0 +1,30 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +from os import makedirs +from os.path import isdir, isfile, join +from shutil import copyfile + +from click import command, secho + +from platformio.exception import ProjectInitialized +from platformio.util import get_source_dir + + +@command("init", short_help="Initialize new platformio based project") +def cli(): + + if isfile("platformio.ini") and isdir("src"): + raise ProjectInitialized() + for d in (".pioenvs", "libs", "src"): + if not isdir(d): + makedirs(d) + if not isfile("platformio.ini"): + copyfile(join(get_source_dir(), "projectconftpl.ini"), + "platformio.ini") + secho("Project successfully initialized.\n" + "Please put your source code to `src` directory, " + "external libraries to `libs` and " + "setup environments in `platformio.ini` file.\n" + "Then process project with `platformio run` command.", + fg="green") diff --git a/platformio/commands/run.py b/platformio/commands/run.py index 9ba9a408..5b90a7e6 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -3,17 +3,21 @@ from click import command, echo, option, secho, style -from platformio.exception import UndefinedEnvPlatform +from platformio.exception import ProjecEnvsNotAvaialable, UndefinedEnvPlatform from platformio.platforms.base import PlatformFactory from platformio.util import get_project_config @command("run", short_help="Process project environments") -@option("--environment", "-e", multiple=True) -@option("--target", "-t", multiple=True) +@option("--environment", "-e", multiple=True, metavar="") +@option("--target", "-t", multiple=True, metavar="") def cli(environment, target): config = get_project_config() + + if not config.sections(): + raise ProjecEnvsNotAvaialable() + for section in config.sections(): if section[:4] != "env:": continue diff --git a/platformio/exception.py b/platformio/exception.py index a068a915..1be8a52e 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -73,3 +73,14 @@ class UndefinedEnvPlatform(PlatformioException): class UnsupportedArchiveType(PlatformioException): MESSAGE = "Can not unpack file '%s'" + + +class ProjectInitialized(PlatformioException): + + MESSAGE = ("Project is already initialized. " + "Process it with `platformio run` command") + + +class ProjecEnvsNotAvaialable(PlatformioException): + + MESSAGE = "Please setup environments in `platformio.ini` file." diff --git a/platformio/projectconftpl.ini b/platformio/projectconftpl.ini new file mode 100644 index 00000000..c4ffe2d4 --- /dev/null +++ b/platformio/projectconftpl.ini @@ -0,0 +1,65 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +# Please uncomment (remove "#" sign from the beginning of the line) any +# environments which are fit to your project +# +# And replace all values that match with "%..._HERE%" by real data + + +# Simple and base environment +#[env:mybaseenv] +#platform = %INSTALLED_PLATFORM_NAME_HERE% + +# +# Atmel AVR based board +# +#[env:myatmelavr_board] +#platform = atmelavr +#board_mcu = %MICROCONTROLLER_TYPE_HERE% # for example -> atmega168 +#board_f_cpu = %PROCESSOR_FREQUENCY_HERE% # for example -> 16000000L +#upload_port = %UPLOAD_PORT_HERE% # for example (Mac/Linux) -> /dev/ttyUSB0 +#upload_port = %UPLOAD_PORT_HERE% # for example (Windows) -> COM3 +#upload_protocol = %UPLOAD_PROTOCOL_HERE% # for example -> arduino +#upload_speed = %UPLOAD_PROTOCOL_HERE% # for example -> 19200 +#targets = %DEFAULT_TARGETS_HERE% # for auto-upload use -> upload + +# +# Atmel AVR based board + Arduino Wiring Framework +# +#[env:myarduino_board] +#platform = atmelavr +#framework = arduino +#board = %BOARD_HERE% # for example -> pro16MHzatmega168 +#upload_port = %UPLOAD_PORT_HERE% # for example (Mac/Linux) -> /dev/ttyUSB0 +#upload_port = %UPLOAD_PORT_HERE% # for example (Windows) -> COM3 +#targets = %DEFAULT_TARGETS_HERE% # for auto-upload use -> upload + +# +# TI MSP430 based board +# +#[env:mytimso430_board] +#platform = timsp430 +#board_mcu = %MICROCONTROLLER_TYPE_HERE% # for example -> msp430g2553 +#board_f_cpu = %PROCESSOR_FREQUENCY_HERE% # for example -> 16000000L +#upload_protocol = %UPLOAD_PROTOCOL_HERE% # for example -> rf2500 +#targets = %DEFAULT_TARGETS_HERE% # for auto-upload use -> upload + +# +# TI MSP430 based board + Energia Wiring Framework +# +#[env:myarduino_board] +#platform = timsp430 +#framework = energia +#board = %BOARD_HERE% # for example -> lpmsp430g2553 +#upload_protocol = %UPLOAD_PROTOCOL_HERE% # for example -> rf2500 +#targets = %DEFAULT_TARGETS_HERE% # for auto-upload use -> upload + +# +# TI TIVA C ARM based board + Energia Wiring Framework +# +#[env:mytitiva_board] +#platform = titiva +#framework = energia +#board = %BOARD_HERE% # for example -> lplm4f120h5qr +#targets = %DEFAULT_TARGETS_HERE% # for auto-upload use -> upload