Fix "OSError: [Errno 2] No such file or directory" when PlatformIO isn't installed properly

This commit is contained in:
Ivan Kravets
2014-12-03 14:18:22 +02:00
parent f1f6817615
commit caf6746e89
4 changed files with 37 additions and 17 deletions

View File

@ -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 <https://github.com/ivankravets/platformio/tree/develop/examples/ide-eclipse>`_
(`issue #32 <https://github.com/ivankravets/platformio/issues/32>`_)
0.9.0 (2014-12-01)
------------------

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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)