From bdfe849c9743068b3779ea4eff01ff572554dac8 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 12 Jun 2014 23:29:47 +0300 Subject: [PATCH] Implemented "platformio search" command --- README.rst | 13 ++++++------ platformio/commands/install.py | 2 +- platformio/commands/run.py | 2 +- platformio/commands/search.py | 23 ++++++++++++++++++++++ platformio/platforms/{base.py => _base.py} | 7 +++++++ platformio/platforms/atmelavr.py | 6 +++++- platformio/platforms/timsp430.py | 6 +++++- platformio/platforms/titiva.py | 6 +++++- platformio/util.py | 15 +++++++++++--- 9 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 platformio/commands/search.py rename platformio/platforms/{base.py => _base.py} (90%) diff --git a/README.rst b/README.rst index 476fd9c6..e9564b8e 100644 --- a/README.rst +++ b/README.rst @@ -55,8 +55,8 @@ Quickstart # Install platformio $ pip install platformio && pip install --egg scons - # Print availalbe development platforms for installing - $ platformio search + # Print all availalbe development platforms for installing + $ platformio search all # Install new development platform $ platformio install SomePlatform @@ -137,14 +137,15 @@ To print all available commands and options: ``platformio search`` ~~~~~~~~~~~~~~~~~~~~~ -Search for available development platforms: +Search for development platforms: .. code-block:: bash - $ platformio search "Query" + # Print all available development platforms + $ platformio search all -You can leave search "Query" as empty. In this case ``platformio`` will print -all available platforms. + # Filter platforms by "Query" + $ platformio search "Query" ``platformio install`` diff --git a/platformio/commands/install.py b/platformio/commands/install.py index 52f1ac89..5db7f031 100644 --- a/platformio/commands/install.py +++ b/platformio/commands/install.py @@ -3,7 +3,7 @@ from click import argument, command, option, secho -from platformio.platforms.base import PlatformFactory +from platformio.platforms._base import PlatformFactory @command("run", short_help="Install new platforms") diff --git a/platformio/commands/run.py b/platformio/commands/run.py index 5b90a7e6..8c1c470c 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -4,7 +4,7 @@ from click import command, echo, option, secho, style from platformio.exception import ProjecEnvsNotAvaialable, UndefinedEnvPlatform -from platformio.platforms.base import PlatformFactory +from platformio.platforms._base import PlatformFactory from platformio.util import get_project_config diff --git a/platformio/commands/search.py b/platformio/commands/search.py new file mode 100644 index 00000000..9990b488 --- /dev/null +++ b/platformio/commands/search.py @@ -0,0 +1,23 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +from click import argument, command, echo, style + +from platformio.platforms._base import PlatformFactory +from platformio.util import get_platforms + + +@command("search", short_help="Search for development platforms") +@argument("query") +def cli(query): + for platform in get_platforms(): + p = PlatformFactory().newPlatform(platform) + name = p.get_name() + shinfo = p.get_short_info() + + search_data = "%s %s" % (name, shinfo) + if query != "all" and query.lower() not in search_data.lower(): + continue + + echo("{name:<20} - {info}".format(name=style(name, fg="cyan"), + info=shinfo)) diff --git a/platformio/platforms/base.py b/platformio/platforms/_base.py similarity index 90% rename from platformio/platforms/base.py rename to platformio/platforms/_base.py index b387c3a9..26787edf 100644 --- a/platformio/platforms/base.py +++ b/platformio/platforms/_base.py @@ -34,6 +34,13 @@ class BasePlatform(object): def get_name(self): raise NotImplementedError() + def get_short_info(self): + if self.__doc__: + doclines = [l.strip() for l in self.__doc__.splitlines()] + return " ".join(doclines).strip() + else: + raise NotImplementedError() + def install(self, with_packages, without_packages): requirements = [] pm = PackageManager(self.get_name()) diff --git a/platformio/platforms/atmelavr.py b/platformio/platforms/atmelavr.py index b8c0a919..907761b7 100644 --- a/platformio/platforms/atmelavr.py +++ b/platformio/platforms/atmelavr.py @@ -3,10 +3,14 @@ from os.path import join -from platformio.platforms.base import BasePlatform +from platformio.platforms._base import BasePlatform class AtmelavrPlatform(BasePlatform): + """ + An embedded platform for Atmel AVR microcontrollers + (with Arduino Framework) + """ PACKAGES = { diff --git a/platformio/platforms/timsp430.py b/platformio/platforms/timsp430.py index daa8ed8e..f815dbf3 100644 --- a/platformio/platforms/timsp430.py +++ b/platformio/platforms/timsp430.py @@ -3,10 +3,14 @@ from os.path import join -from platformio.platforms.base import BasePlatform +from platformio.platforms._base import BasePlatform class Timsp430Platform(BasePlatform): + """ + An embedded platform for TI MSP430 microcontrollers + (with Energia Framework) + """ PACKAGES = { diff --git a/platformio/platforms/titiva.py b/platformio/platforms/titiva.py index b385fd25..ecdba125 100644 --- a/platformio/platforms/titiva.py +++ b/platformio/platforms/titiva.py @@ -3,10 +3,14 @@ from os.path import join -from platformio.platforms.base import BasePlatform +from platformio.platforms._base import BasePlatform class TitivaPlatform(BasePlatform): + """ + An embedded platform for TI TIVA C ARM microcontrollers + (with Energia Framework) + """ PACKAGES = { diff --git a/platformio/util.py b/platformio/util.py index d9e3416a..87168a6f 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -from os import getcwd, utime +from os import getcwd, listdir, utime from os.path import dirname, expanduser, isfile, join, realpath from platform import architecture, system from subprocess import PIPE, Popen @@ -14,6 +14,10 @@ except ImportError: from ConfigParser import ConfigParser +def get_system(): + return (system() + architecture()[0][:-3]).lower() + + def get_home_dir(): return expanduser("~/.platformio") @@ -35,8 +39,13 @@ def get_project_config(): return cp -def get_system(): - return (system() + architecture()[0][:-3]).lower() +def get_platforms(): + platforms = [] + for p in listdir(join(get_source_dir(), "platforms")): + if p.startswith("_") or not p.endswith(".py"): + continue + platforms.append(p[:-3]) + return platforms def change_filemtime(path, time):