From 19822ff08fa73b1d781e8cf08e15f30736a5cc4d Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 16 Mar 2015 14:15:57 +0200 Subject: [PATCH] Introduce platform names --- platformio/commands/search.py | 10 ++--- platformio/commands/show.py | 2 +- platformio/platforms/atmelavr.py | 3 ++ platformio/platforms/atmelsam.py | 3 ++ platformio/platforms/base.py | 51 +++++++++++++----------- platformio/platforms/freescalekinetis.py | 3 ++ platformio/platforms/nordicnrf51.py | 3 ++ platformio/platforms/nxplpc.py | 3 ++ platformio/platforms/ststm32.py | 3 ++ platformio/platforms/teensy.py | 3 ++ platformio/platforms/timsp430.py | 3 ++ platformio/platforms/titiva.py | 3 ++ tests/commands/test_boards.py | 4 +- tests/commands/test_search.py | 2 +- 14 files changed, 63 insertions(+), 33 deletions(-) diff --git a/platformio/commands/search.py b/platformio/commands/search.py index e46e0bb0..d3b7d69a 100644 --- a/platformio/commands/search.py +++ b/platformio/commands/search.py @@ -18,18 +18,18 @@ def cli(query, json_output): platforms.sort() for platform in platforms: p = PlatformFactory.newPlatform(platform) - name = p.get_name() + type_ = p.get_type() description = p.get_description() if query == "all": query = "" - search_data = "%s %s %s" % (name, description, p.get_packages()) + search_data = "%s %s %s" % (type_, description, p.get_packages()) if query and query.lower() not in search_data.lower(): continue data.append({ - "name": name, + "type": type_, "description": description, "packages": p.get_packages() }) @@ -38,9 +38,9 @@ def cli(query, json_output): click.echo(json.dumps(data)) else: for item in data: - click.secho(item['name'], fg="cyan", nl=False) + click.secho(item['type'], fg="cyan", nl=False) click.echo(" (available packages: %s)" % ", ".join( p.get_packages().keys())) - click.secho("-" * len(item['name']), fg="cyan") + click.secho("-" * len(item['type']), fg="cyan") click.echo(item['description']) click.echo() diff --git a/platformio/commands/show.py b/platformio/commands/show.py index ae9106f2..f0913ff9 100644 --- a/platformio/commands/show.py +++ b/platformio/commands/show.py @@ -30,7 +30,7 @@ def cli(ctx, platform): p = PlatformFactory.newPlatform(platform) click.echo("{name:<20} - {description} [ {url} ]".format( - name=click.style(p.get_name(), fg="cyan"), + name=click.style(p.get_type(), fg="cyan"), description=p.get_description(), url=p.get_vendor_url())) installed_packages = PackageManager.get_installed() diff --git a/platformio/platforms/atmelavr.py b/platformio/platforms/atmelavr.py index 6ca3e0f4..9c7bc243 100644 --- a/platformio/platforms/atmelavr.py +++ b/platformio/platforms/atmelavr.py @@ -37,6 +37,9 @@ class AtmelavrPlatform(BasePlatform): } } + def get_name(self): + return "Atmel AVR" + def on_run_err(self, line): # pylint: disable=R0201 # fix STDERR "flash written" for avrdude if "avrdude" in line: diff --git a/platformio/platforms/atmelsam.py b/platformio/platforms/atmelsam.py index aacb03a1..e11d98a4 100644 --- a/platformio/platforms/atmelsam.py +++ b/platformio/platforms/atmelsam.py @@ -34,3 +34,6 @@ class AtmelsamPlatform(BasePlatform): "default": True } } + + def get_name(self): + return "Atmel SAM" diff --git a/platformio/platforms/base.py b/platformio/platforms/base.py index eadad863..0a5c4da6 100644 --- a/platformio/platforms/base.py +++ b/platformio/platforms/base.py @@ -100,17 +100,17 @@ def get_packages(): class PlatformFactory(object): @staticmethod - def get_clsname(name): - return "%sPlatform" % name.title() + def get_clsname(type_): + return "%sPlatform" % type_.title() @staticmethod - def load_module(name, path): + def load_module(type_, path): module = None try: module = load_source( - "platformio.platforms.%s" % name, path) + "platformio.platforms.%s" % type_, path) except ImportError: - raise exception.UnknownPlatform(name) + raise exception.UnknownPlatform(type_) return module @classmethod @@ -123,15 +123,15 @@ class PlatformFactory(object): for p in listdir(pdir): if p in ("__init__.py", "base.py") or not p.endswith(".py"): continue - name = p[:-3] + type_ = p[:-3] path = join(pdir, p) try: isplatform = hasattr( - cls.load_module(name, path), - cls.get_clsname(name) + cls.load_module(type_, path), + cls.get_clsname(type_) ) if isplatform: - platforms[name] = path + platforms[type_] = path except exception.UnknownPlatform: pass @@ -139,20 +139,20 @@ class PlatformFactory(object): return platforms installed_platforms = {} - for name in get_state_item("installed_platforms", []): - if name in platforms: - installed_platforms[name] = platforms[name] + for type_ in get_state_item("installed_platforms", []): + if type_ in platforms: + installed_platforms[type_] = platforms[type_] return installed_platforms @classmethod - def newPlatform(cls, name): + def newPlatform(cls, type_): platforms = cls.get_platforms() - if name not in platforms: - raise exception.UnknownPlatform(name) + if type_ not in platforms: + raise exception.UnknownPlatform(type_) _instance = getattr( - cls.load_module(name, platforms[name]), - cls.get_clsname(name) + cls.load_module(type_, platforms[type_]), + cls.get_clsname(type_) )() assert isinstance(_instance, BasePlatform) return _instance @@ -166,12 +166,15 @@ class BasePlatform(object): def __init__(self): self._found_error = False - def get_name(self): + def get_type(self): return self.__class__.__name__[:-8].lower() + def get_name(self): + return self.get_type().title() + def get_build_script(self): builtin = join(util.get_source_dir(), "builder", "scripts", "%s.py" % - self.get_name()) + self.get_type()) if isfile(builtin): return builtin raise NotImplementedError() @@ -235,14 +238,14 @@ class BasePlatform(object): # register installed platform data = get_state_item("installed_platforms", []) - if self.get_name() not in data: - data.append(self.get_name()) + if self.get_type() not in data: + data.append(self.get_type()) set_state_item("installed_platforms", data) return len(requirements) def uninstall(self): - platform = self.get_name() + platform = self.get_type() installed_platforms = PlatformFactory.get_platforms( installed=True).keys() @@ -286,8 +289,8 @@ class BasePlatform(object): installed=True).keys() installed_packages = PackageManager.get_installed() - if self.get_name() not in installed_platforms: - raise exception.PlatformNotInstalledYet(self.get_name()) + if self.get_type() not in installed_platforms: + raise exception.PlatformNotInstalledYet(self.get_type()) if "clean" in targets: targets.remove("clean") diff --git a/platformio/platforms/freescalekinetis.py b/platformio/platforms/freescalekinetis.py index 61106fea..56239f17 100644 --- a/platformio/platforms/freescalekinetis.py +++ b/platformio/platforms/freescalekinetis.py @@ -26,3 +26,6 @@ class FreescalekinetisPlatform(BasePlatform): "default": True } } + + def get_name(self): + return "Freescale Kinetis" diff --git a/platformio/platforms/nordicnrf51.py b/platformio/platforms/nordicnrf51.py index 975b4ce4..e3a09a0d 100644 --- a/platformio/platforms/nordicnrf51.py +++ b/platformio/platforms/nordicnrf51.py @@ -28,3 +28,6 @@ class Nordicnrf51Platform(BasePlatform): "default": True } } + + def get_name(self): + return "Nordic nRF51" diff --git a/platformio/platforms/nxplpc.py b/platformio/platforms/nxplpc.py index 4da1334f..b165731f 100644 --- a/platformio/platforms/nxplpc.py +++ b/platformio/platforms/nxplpc.py @@ -28,3 +28,6 @@ class NxplpcPlatform(BasePlatform): "default": True } } + + def get_name(self): + return "NXP LPC" diff --git a/platformio/platforms/ststm32.py b/platformio/platforms/ststm32.py index a33947f1..2f09fb21 100644 --- a/platformio/platforms/ststm32.py +++ b/platformio/platforms/ststm32.py @@ -49,3 +49,6 @@ class Ststm32Platform(BasePlatform): "default": True } } + + def get_name(self): + return "ST STM32" diff --git a/platformio/platforms/teensy.py b/platformio/platforms/teensy.py index 648c1c3f..cc79c3ee 100644 --- a/platformio/platforms/teensy.py +++ b/platformio/platforms/teensy.py @@ -41,6 +41,9 @@ class TeensyPlatform(BasePlatform): } } + def get_name(self): + return "Teensy" + def run(self, variables, targets): for v in variables: if "BOARD=" not in v: diff --git a/platformio/platforms/timsp430.py b/platformio/platforms/timsp430.py index a15b5fd1..48fe652e 100644 --- a/platformio/platforms/timsp430.py +++ b/platformio/platforms/timsp430.py @@ -31,3 +31,6 @@ class Timsp430Platform(BasePlatform): "default": True } } + + def get_name(self): + return "TI MSP430" diff --git a/platformio/platforms/titiva.py b/platformio/platforms/titiva.py index ed14d2da..defd6709 100644 --- a/platformio/platforms/titiva.py +++ b/platformio/platforms/titiva.py @@ -39,3 +39,6 @@ class TitivaPlatform(BasePlatform): "default": True } } + + def get_name(self): + return "TI TIVA" diff --git a/tests/commands/test_boards.py b/tests/commands/test_boards.py index dfeef591..4a96d2e5 100644 --- a/tests/commands/test_boards.py +++ b/tests/commands/test_boards.py @@ -34,9 +34,9 @@ def test_board_options(platformio_setup, clirunner, validate_cliresult): search_result = json.loads(result.output) assert isinstance(search_result, list) assert len(search_result) - platforms = [item['name'] for item in search_result] + platforms = [item['type'] for item in search_result] - for name, opts in util.get_boards().iteritems(): + for _, opts in util.get_boards().iteritems(): assert required_opts.issubset(set(opts)) assert opts['platform'] in platforms diff --git a/tests/commands/test_search.py b/tests/commands/test_search.py index 8864d7b9..4179f1b2 100644 --- a/tests/commands/test_search.py +++ b/tests/commands/test_search.py @@ -12,7 +12,7 @@ def test_search_json_output(clirunner, validate_cliresult): search_result = json.loads(result.output) assert isinstance(search_result, list) assert len(search_result) - platforms = [item['name'] for item in search_result] + platforms = [item['type'] for item in search_result] assert "atmelsam" in platforms