diff --git a/.isort.cfg b/.isort.cfg index 72280366..3dbd6d91 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -1,3 +1,3 @@ [settings] line_length=79 -known_third_party=click,requests,serial,SCons,pytest +known_third_party=click,requests,serial,SCons,pytest,bottle diff --git a/platformio/__init__.py b/platformio/__init__.py index ffc095fc..9e004963 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (2, 0, "0.dev2") +VERSION = (2, 0, "0.dev3") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/commands/init.py b/platformio/commands/init.py index a77d753a..229a1c23 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -8,6 +8,7 @@ from shutil import copyfile import click from platformio import app, exception +from platformio.ide.projectgenerator import ProjectGenerator from platformio.util import get_boards, get_source_dir @@ -28,9 +29,11 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613 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("--disable-auto-uploading", is_flag=True) @click.option("--env-prefix", default="autogen_") -def cli(project_dir, board, disable_auto_uploading, env_prefix): +def cli(project_dir, board, ide, disable_auto_uploading, env_prefix): # ask about auto-uploading if board and app.get_setting("enable_prompts"): @@ -82,6 +85,10 @@ def cli(project_dir, board, disable_auto_uploading, env_prefix): 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 " diff --git a/platformio/ide/__init__.py b/platformio/ide/__init__.py new file mode 100644 index 00000000..ca6f0304 --- /dev/null +++ b/platformio/ide/__init__.py @@ -0,0 +1,2 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py new file mode 100644 index 00000000..3ce36a6b --- /dev/null +++ b/platformio/ide/projectgenerator.py @@ -0,0 +1,63 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +from glob import glob +from os import listdir +from os.path import basename, isdir, join + +import bottle + +from platformio import util + + +class ProjectGenerator(object): + + def __init__(self, project_dir, ide): + self.project_dir = project_dir + self.ide = ide + self._tplvars = self._gather_tplvars() + + @staticmethod + def get_supported_ides(): + tpls_dir = join(util.get_source_dir(), "ide", "tpls") + return [d for d in listdir(tpls_dir) + if isdir(join(tpls_dir, d))] + + @staticmethod + def get_project_env(): + data = {} + config = util.get_project_config() + for section in config.sections(): + if not section.startswith("env:"): + continue + for k, v in config.items(section): + data[k] = v + return data + + def get_project_name(self): + return basename(self.project_dir) + + def get_tpls(self): + tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide) + return glob(join(tpls_dir, ".*.tpl")) + glob(join(tpls_dir, "*.tpl")) + + def generate(self): + for tpl_path in self.get_tpls(): + file_name = basename(tpl_path)[:-4] + with open(join(self.project_dir, file_name), "w") as f: + f.write(self._render_tpl(tpl_path)) + + def _render_tpl(self, tpl_path): + content = "" + with open(tpl_path) as f: + content = f.read() + return bottle.template(content, **self._tplvars) + + def _gather_tplvars(self): + data = self.get_project_env() + + data.update({ + "project_name": self.get_project_name() + }) + + return data diff --git a/platformio/ide/tpls/eclipse/.cproject.tpl b/platformio/ide/tpls/eclipse/.cproject.tpl new file mode 100644 index 00000000..7ed43a49 --- /dev/null +++ b/platformio/ide/tpls/eclipse/.cproject.tpl @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platformio/ide/tpls/eclipse/.project.tpl b/platformio/ide/tpls/eclipse/.project.tpl new file mode 100644 index 00000000..ac49f548 --- /dev/null +++ b/platformio/ide/tpls/eclipse/.project.tpl @@ -0,0 +1,27 @@ + + + {{project_name}} + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/platformio/ide/tpls/qtcreator/platformio.pro.tpl b/platformio/ide/tpls/qtcreator/platformio.pro.tpl new file mode 100644 index 00000000..22188cd8 --- /dev/null +++ b/platformio/ide/tpls/qtcreator/platformio.pro.tpl @@ -0,0 +1,19 @@ +win32 { + HOMEDIR += $$(USERPROFILE) +} +else { + HOMEDIR += $$(PWD) +} + +INCLUDEPATH += "$$HOMEDIR/.platformio/packages/framework-arduinoavr/cores/arduino" +INCLUDEPATH += "$$HOMEDIR/.platformio/packages/toolchain-atmelavr/avr/include" + +win32:INCLUDEPATH ~= s,/,\\,g + +# DEFINES += __AVR_ATmega328__ + +OTHER_FILES += \ + platformio.ini + +SOURCES += \ + src/main.c diff --git a/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl b/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl new file mode 100644 index 00000000..8054bd59 --- /dev/null +++ b/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl @@ -0,0 +1,45 @@ +{ + "build_systems": + [ + { + "cmd": + [ + "platformio", + "run" + ], + "name": "{{project_name}}", + "variants": + [ + { + "cmd": + [ + "platformio", + "--force", + "run", + "--target", + "clean" + ], + "name": "Clean" + }, + { + "cmd": + [ + "platformio", + "--force", + "run", + "--target", + "upload" + ], + "name": "Upload" + } + ], + "working_dir": "${project_path:${folder}}" + } + ], + "folders": + [ + { + "path": "." + } + ] +} diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl b/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl new file mode 100644 index 00000000..87bc92f6 --- /dev/null +++ b/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl @@ -0,0 +1,29 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {cad450ef-1a84-42d4-a5b5-a1736b8833d3} + + + + + + + + + Source Files\src + + + \ No newline at end of file diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl b/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl new file mode 100644 index 00000000..4da8da32 --- /dev/null +++ b/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl @@ -0,0 +1,62 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {0FA9C3A8-452B-41EF-A418-9102B170F49F} + MakeFileProj + + + + Makefile + true + v120 + + + Makefile + false + v120 + + + + + + + + + + + + + platformio --force run + platformio --force run --target clean + WIN32;_DEBUG;$(NMakePreprocessorDefinitions) + $(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\toolchain-atmelavr\avr\include;$(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\framework-arduinoavr\cores\arduino;$(NMakeIncludeSearchPath) + + + platformio run + platformio run -t clean + WIN32;NDEBUG;$(NMakePreprocessorDefinitions) + $(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\toolchain-atmelavr\avr\include;$(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\framework-arduinoavr\cores\arduino;$(NMakeIncludeSearchPath) + + + + + + + + + + + + + + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 6a5ccae6..a540932f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +bottle=0.12.8 click==3.3 colorama==0.3.3 pyserial==2.7 diff --git a/setup.py b/setup.py index 9a01f68c..41b5a586 100644 --- a/setup.py +++ b/setup.py @@ -18,13 +18,21 @@ setup( url=__url__, license=__license__, install_requires=[ + "bottle", "click>=3.0", "pyserial", "requests>=2.4.0", # "SCons" ] + (["colorama"] if system() == "Windows" else []), packages=find_packages(), - package_data={"platformio": ["projectconftpl.ini", "boards/*.json"]}, + package_data={ + "platformio": [ + "projectconftpl.ini", + "boards/*.json", + "ide/tpls/*/.*.tpl", + "ide/tpls/*/*.tpl" + ] + }, entry_points={ "console_scripts": [ "platformio = platformio.__main__:main"