Implemented "platform init" command; minor fixes

This commit is contained in:
Ivan Kravets
2014-06-12 21:17:45 +03:00
parent 9636124eea
commit 5511cff3a5
4 changed files with 113 additions and 3 deletions

View File

@@ -0,0 +1,30 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# 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")

View File

@@ -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="<environment>")
@option("--target", "-t", multiple=True, metavar="<target>")
def cli(environment, target):
config = get_project_config()
if not config.sections():
raise ProjecEnvsNotAvaialable()
for section in config.sections():
if section[:4] != "env:":
continue

View File

@@ -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."

View File

@@ -0,0 +1,65 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# 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