From caf6746e893260a1428dda45dd4e81052dc105dc Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 3 Dec 2014 14:18:22 +0200 Subject: [PATCH] Fix "OSError: [Errno 2] No such file or directory" when PlatformIO isn't installed properly --- HISTORY.rst | 8 ++++++++ platformio/commands/init.py | 2 +- platformio/exception.py | 12 +++++++++++- platformio/platforms/base.py | 32 +++++++++++++++++--------------- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index e9e35f69..5282886e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,14 @@ Release History =============== +0.9.1 (2014-12-03) +------------------ + +* Fixed "*OSError: [Errno 2] No such file or directory*" when PlatformIO isn't + installed properly +* Fixed example for `Eclipse IDE with Tiva board `_ + (`issue #32 `_) + 0.9.0 (2014-12-01) ------------------ diff --git a/platformio/commands/init.py b/platformio/commands/init.py index 8c540e54..9d9abcf3 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -29,7 +29,7 @@ def cli(project_dir): click.secho( "will be used for the new project.\n" "You can specify another project directory via\n" - "`platformio init -d %PATH_TO_PROJECT_DIR%` command.\n", + "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.\n", fg="yellow" ) diff --git a/platformio/exception.py b/platformio/exception.py index 4afc69ee..34c635fe 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -26,7 +26,8 @@ class PlatformNotInstalledYet(PlatformioException): class UnknownCLICommand(PlatformioException): - MESSAGE = "Unknown command '%s'" + MESSAGE = ("Unknown command '%s'. Please use `platformio --help`" + " to see all available commands") class UnknownPackage(PlatformioException): @@ -144,3 +145,12 @@ class InvalidSettingValue(PlatformioException): class UpgraderFailed(PlatformioException): MESSAGE = "An error occurred while upgrading PlatformIO" + + +class SConsNotInstalled(PlatformioException): + + MESSAGE = ( + "The `scons` tool isn't installed properly. " + "Please use official installation procedure: " + "http://docs.platformio.ikravets.com/en/latest/installation.html" + ) diff --git a/platformio/platforms/base.py b/platformio/platforms/base.py index 03ef4b38..5197e1d0 100644 --- a/platformio/platforms/base.py +++ b/platformio/platforms/base.py @@ -5,9 +5,8 @@ from imp import load_source from os import listdir from os.path import isdir, isfile, join +from platformio import exception from platformio.app import get_state_item, set_state_item -from platformio.exception import (BuildScriptNotFound, PlatformNotInstalledYet, - UnknownPackage, UnknownPlatform) from platformio.pkgmanager import PackageManager from platformio.util import exec_command, get_home_dir, get_source_dir @@ -25,7 +24,7 @@ class PlatformFactory(object): module = load_source( "platformio.platforms.%s" % name, path) except ImportError: - raise UnknownPlatform(name) + raise exception.UnknownPlatform(name) return module @classmethod @@ -47,7 +46,7 @@ class PlatformFactory(object): ) if isplatform: platforms[name] = path - except UnknownPlatform: + except exception.UnknownPlatform: pass if not installed: @@ -63,7 +62,7 @@ class PlatformFactory(object): def newPlatform(cls, name): platforms = cls.get_platforms() if name not in platforms: - raise UnknownPlatform(name) + raise exception.UnknownPlatform(name) _instance = getattr( cls.load_module(name, platforms[name]), @@ -123,7 +122,7 @@ class BasePlatform(object): upkgs = with_packages | without_packages ppkgs = set(self.get_packages().keys()) if not upkgs.issubset(ppkgs): - raise UnknownPackage(", ".join(upkgs - ppkgs)) + raise exception.UnknownPackage(", ".join(upkgs - ppkgs)) requirements = [] for name, opts in self.get_packages().items(): @@ -151,7 +150,7 @@ class BasePlatform(object): installed=True).keys() if platform not in installed_platforms: - raise PlatformNotInstalledYet(platform) + raise exception.PlatformNotInstalledYet(platform) deppkgs = set() for item in installed_platforms: @@ -191,7 +190,7 @@ class BasePlatform(object): installed_packages = PackageManager.get_installed() if self.get_name() not in installed_platforms: - raise PlatformNotInstalledYet(self.get_name()) + raise exception.PlatformNotInstalledYet(self.get_name()) if "clean" in targets: targets.remove("clean") @@ -205,20 +204,23 @@ class BasePlatform(object): continue _, path = v.split("=", 2) if not isfile(path): - raise BuildScriptNotFound(path) + raise exception.BuildScriptNotFound(path) - # append aliases of installed packages + # append aliases of the installed packages for name, options in self.get_packages().items(): if name not in installed_packages: continue variables.append( "PIOPACKAGE_%s=%s" % (options['alias'].upper(), name)) - result = exec_command([ - "scons", - "-Q", - "-f", join(get_source_dir(), "builder", "main.py") - ] + variables + targets) + try: + result = exec_command([ + "scons", + "-Q", + "-f", join(get_source_dir(), "builder", "main.py") + ] + variables + targets) + except OSError: + raise exception.SConsNotInstalled() return self.after_run(result)