From dac83d6164a0e04b301cf703ea312d896fca32e4 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 30 Jul 2014 22:40:11 +0300 Subject: [PATCH] Refactored "base" paltform --- platformio/commands/install.py | 2 +- platformio/commands/list.py | 2 +- platformio/commands/run.py | 2 +- platformio/commands/search.py | 2 +- platformio/commands/show.py | 4 +- platformio/commands/uninstall.py | 2 +- platformio/commands/update.py | 2 +- platformio/platforms/atmelavr.py | 2 +- platformio/platforms/{_base.py => base.py} | 47 +++++++++++++++++----- platformio/platforms/timsp430.py | 2 +- platformio/platforms/titiva.py | 2 +- 11 files changed, 47 insertions(+), 22 deletions(-) rename platformio/platforms/{_base.py => base.py} (61%) diff --git a/platformio/commands/install.py b/platformio/commands/install.py index 09f75500..56cb6e3f 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("install", short_help="Install new platforms") diff --git a/platformio/commands/list.py b/platformio/commands/list.py index 699d2fb0..990429bf 100644 --- a/platformio/commands/list.py +++ b/platformio/commands/list.py @@ -9,7 +9,7 @@ from platformio.pkgmanager import PackageManager @command("list", short_help="List installed platforms") def cli(): - for name, pkgs in PackageManager.get_installed().iteritems(): + for name, pkgs in PackageManager.get_installed().items(): echo("{name:<20} with packages: {pkgs}".format( name=style(name, fg="cyan"), pkgs=", ".join(pkgs.keys()) diff --git a/platformio/commands/run.py b/platformio/commands/run.py index 104eaf6b..4422c1d0 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -5,7 +5,7 @@ from click import command, echo, option, secho, style from platformio.exception import (InvalidEnvName, ProjectEnvsNotAvaialable, UndefinedEnvPlatform, UnknownEnvNames) -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 index 9990b488..2457b05e 100644 --- a/platformio/commands/search.py +++ b/platformio/commands/search.py @@ -3,7 +3,7 @@ from click import argument, command, echo, style -from platformio.platforms._base import PlatformFactory +from platformio.platforms.base import PlatformFactory from platformio.util import get_platforms diff --git a/platformio/commands/show.py b/platformio/commands/show.py index 9ae904c9..da4c552f 100644 --- a/platformio/commands/show.py +++ b/platformio/commands/show.py @@ -7,7 +7,7 @@ from click import argument, command, echo, style from platformio.exception import PlatformNotInstalledYet from platformio.pkgmanager import PackageManager -from platformio.platforms._base import PlatformFactory +from platformio.platforms.base import PlatformFactory @command("show", short_help="Show details about an installed platforms") @@ -22,7 +22,7 @@ def cli(platform): info=p.get_short_info())) pm = PackageManager(platform) - for name, data in pm.get_installed(platform).iteritems(): + for name, data in pm.get_installed(platform).items(): echo("----------") echo("Package: %s" % style(name, fg="yellow")) echo("Location: %s" % join(pm.get_platform_dir(), data['path'])) diff --git a/platformio/commands/uninstall.py b/platformio/commands/uninstall.py index b7ecb0c4..72765911 100644 --- a/platformio/commands/uninstall.py +++ b/platformio/commands/uninstall.py @@ -5,7 +5,7 @@ from click import argument, command, secho from platformio.exception import PlatformNotInstalledYet from platformio.pkgmanager import PackageManager -from platformio.platforms._base import PlatformFactory +from platformio.platforms.base import PlatformFactory @command("uninstall", short_help="Uninstall platforms") diff --git a/platformio/commands/update.py b/platformio/commands/update.py index 6bd2432d..8fad8523 100644 --- a/platformio/commands/update.py +++ b/platformio/commands/update.py @@ -4,7 +4,7 @@ from click import command, echo, style from platformio.pkgmanager import PackageManager -from platformio.platforms._base import PlatformFactory +from platformio.platforms.base import PlatformFactory @command("update", short_help="Update installed platforms") diff --git a/platformio/platforms/atmelavr.py b/platformio/platforms/atmelavr.py index 676cb010..2e2971f6 100644 --- a/platformio/platforms/atmelavr.py +++ b/platformio/platforms/atmelavr.py @@ -3,7 +3,7 @@ from os.path import join -from platformio.platforms._base import BasePlatform +from platformio.platforms.base import BasePlatform class AtmelavrPlatform(BasePlatform): diff --git a/platformio/platforms/_base.py b/platformio/platforms/base.py similarity index 61% rename from platformio/platforms/_base.py rename to platformio/platforms/base.py index fc92a733..afda73ed 100644 --- a/platformio/platforms/_base.py +++ b/platformio/platforms/base.py @@ -40,30 +40,55 @@ class BasePlatform(object): else: raise NotImplementedError() - def install(self, with_packages, without_packages): - requirements = [] - pm = PackageManager(self.get_name()) + def get_pkgname_by_alias(self, alias): + for name, opts in self.PACKAGES.items(): + if opts.get("alias", None) == alias: + return name + return None - upkgs = set(with_packages + without_packages) + def install(self, with_packages, without_packages, skip_default_packages): + with_packages = set(with_packages) + without_packages = set(without_packages) + + upkgs = with_packages | without_packages ppkgs = set(self.PACKAGES.keys()) - if not upkgs.issubset(ppkgs): - raise UnknownPackage(", ".join(upkgs - ppkgs)) + unknown = upkgs - ppkgs + if unknown: + _unknown = unknown.copy() + # maybe aliases + for alias in unknown: + pkgname = self.get_pkgname_by_alias(alias) + if pkgname not in self.PACKAGES: + continue + if alias in with_packages: + with_packages.discard(alias) + with_packages.add(pkgname) + if alias in without_packages: + without_packages.discard(alias) + without_packages.add(pkgname) + _unknown.discard(alias) - for name, opts in self.PACKAGES.iteritems(): + if _unknown: + raise UnknownPackage(", ".join(_unknown)) + + requirements = [] + for name, opts in self.PACKAGES.items(): if name in without_packages: continue - elif name in with_packages or opts["default"]: - requirements.append((name, opts["path"])) + elif (name in with_packages or (not skip_default_packages and + opts['default'])): + requirements.append((name, opts['path'])) + pm = PackageManager(self.get_name()) for (package, path) in requirements: pm.install(package, path) - return True + return len(requirements) def uninstall(self): platform = self.get_name() pm = PackageManager(platform) - for package, data in pm.get_installed(platform).iteritems(): + for package, data in pm.get_installed(platform).items(): pm.uninstall(package, data['path']) pm.unregister_platform(platform) diff --git a/platformio/platforms/timsp430.py b/platformio/platforms/timsp430.py index 34a859b5..03966eae 100644 --- a/platformio/platforms/timsp430.py +++ b/platformio/platforms/timsp430.py @@ -3,7 +3,7 @@ from os.path import join -from platformio.platforms._base import BasePlatform +from platformio.platforms.base import BasePlatform class Timsp430Platform(BasePlatform): diff --git a/platformio/platforms/titiva.py b/platformio/platforms/titiva.py index ecdba125..cee2709b 100644 --- a/platformio/platforms/titiva.py +++ b/platformio/platforms/titiva.py @@ -3,7 +3,7 @@ from os.path import join -from platformio.platforms._base import BasePlatform +from platformio.platforms.base import BasePlatform class TitivaPlatform(BasePlatform):