Use stderr stream to write errors instead env.Exi()

This commit is contained in:
Ivan Kravets
2016-08-26 14:39:23 +03:00
parent c637729eae
commit 054790d161
6 changed files with 51 additions and 28 deletions

View File

@ -203,7 +203,7 @@ class LibBuilderBase(object): # pylint: disable=too-many-instance-attributes
sys.stderr.write(
"Error: Could not find `%s` dependency for `%s` "
"library\n" % (item['name'], self.name))
self.env.Exit(2)
self.env.Exit(1)
def _validate_search_paths(self, search_paths=None):
if not search_paths:

View File

@ -16,6 +16,7 @@ from __future__ import absolute_import
import atexit
import re
import sys
from glob import glob
from os import environ, remove
from os.path import isfile, join
@ -250,8 +251,10 @@ def GetActualLDScript(env):
return path
if script:
env.Exit("Error: Could not find '%s' LD script in LDPATH '%s'" %
(script, env.subst("$LIBPATH")))
sys.stderr.write(
"Error: Could not find '%s' LD script in LDPATH '%s'\n" %
(script, env.subst("$LIBPATH")))
env.Exit(1)
return None

View File

@ -14,6 +14,7 @@
from __future__ import absolute_import
import sys
from os.path import isdir, isfile, join
from SCons.Script import COMMAND_LINE_TARGETS
@ -43,7 +44,8 @@ def BoardConfig(env, board=None):
try:
config = p.board_config(board if board else env['BOARD'])
except exception.UnknownBoard as e:
env.Exit("Error: %s" % str(e))
sys.stderr.write("Error: %s\n" % str(e))
env.Exit(1)
return config

View File

@ -15,6 +15,7 @@
from __future__ import absolute_import
import atexit
import sys
from os import remove
from os.path import isdir, isfile, join, sep
from string import Template
@ -82,9 +83,10 @@ def ProcessTest(env):
def GenerateOutputReplacement(env, destination_dir):
if not isdir(env.subst(destination_dir)):
env.Exit(
"Error: Test folder doesn't exist. Please put your test suite "
'to \"test\" folder in project\'s root directory.')
sys.stderr.write(
"Error: Test folder does not exist. Please put your test suite "
"to \"test\" folder in project's root directory.\n")
env.Exit(1)
TEMPLATECPP = """
# include <$framework>
@ -127,8 +129,10 @@ void output_complete(void)
else:
framework = env.subst("$PIOFRAMEWORK").lower()
if framework not in FRAMEWORK_PARAMETERS:
env.Exit("Error: %s framework doesn't support testing feature!" %
framework)
sys.stderr.write(
"Error: %s framework doesn't support testing feature!\n" %
framework)
env.Exit(1)
else:
data = Template(TEMPLATECPP).substitute(FRAMEWORK_PARAMETERS[
framework])

View File

@ -14,6 +14,7 @@
from __future__ import absolute_import
import sys
from os import environ
from os.path import isfile, join
from platform import system
@ -71,10 +72,11 @@ def WaitForNewSerialPort(env, before):
break
if not new_port:
env.Exit("Error: Couldn't find a board on the selected port. "
"Check that you have the correct port selected. "
"If it is correct, try pressing the board's reset "
"button after initiating the upload.")
sys.stderr.write("Error: Couldn't find a board on the selected port. "
"Check that you have the correct port selected. "
"If it is correct, try pressing the board's reset "
"button after initiating the upload.\n")
env.Exit(1)
return new_port
@ -116,7 +118,7 @@ def AutodetectUploadPort(*args, **kwargs): # pylint: disable=unused-argument
else:
if (system() == "Linux" and
not isfile("/etc/udev/99-platformio-udev.rules")):
print(
sys.stderr.write(
"\nWarning! Please install `99-platformio-udev.rules` and "
"check that your board's PID and VID are listed in the rules."
"\n https://raw.githubusercontent.com/platformio/platformio"
@ -126,10 +128,12 @@ def AutodetectUploadPort(*args, **kwargs): # pylint: disable=unused-argument
if env.subst("$UPLOAD_PORT"):
print env.subst("Auto-detected: $UPLOAD_PORT")
else:
env.Exit("Error: Please specify `upload_port` for environment or use "
"global `--upload-port` option.\n"
"For some development platforms this can be a USB flash "
"drive (i.e. /media/<user>/<device name>)\n")
sys.stderr.write(
"Error: Please specify `upload_port` for environment or use "
"global `--upload-port` option.\n"
"For some development platforms this can be a USB flash "
"drive (i.e. /media/<user>/<device name>)\n")
env.Exit(1)
def UploadToDisk(_, target, source, env): # pylint: disable=W0613,W0621
@ -141,8 +145,8 @@ def UploadToDisk(_, target, source, env): # pylint: disable=W0613,W0621
continue
copyfile(fpath, join(
env.subst("$UPLOAD_PORT"), "%s.%s" % (progname, ext)))
print("Firmware has been successfully uploaded.\n"
"(Some boards may require manual hard reset)")
print "Firmware has been successfully uploaded.\n"\
"(Some boards may require manual hard reset)"
def CheckUploadSize(_, target, source, env): # pylint: disable=W0613,W0621
@ -166,8 +170,10 @@ def CheckUploadSize(_, target, source, env): # pylint: disable=W0613,W0621
used_size = int(values[0]) + int(values[1])
if used_size > max_size:
env.Exit("Error: The program size (%d bytes) is greater "
"than maximum allowed (%s bytes)" % (used_size, max_size))
sys.stderr.write("Error: The program size (%d bytes) is greater "
"than maximum allowed (%s bytes)\n" %
(used_size, max_size))
env.Exit(1)
def exists(_):

View File

@ -15,6 +15,7 @@
from __future__ import absolute_import
import re
import sys
from glob import glob
from os import sep, walk
from os.path import basename, dirname, isdir, join, realpath
@ -87,8 +88,10 @@ def BuildProgram(env):
env.Append(PIOBUILDFILES=env.ProcessTest())
if not env['PIOBUILDFILES'] and not COMMAND_LINE_TARGETS:
env.Exit("Error: Nothing to build. Please put your source code files "
"to '%s' folder" % env.subst("$PROJECTSRC_DIR"))
sys.stderr.write(
"Error: Nothing to build. Please put your source code files "
"to '%s' folder\n" % env.subst("$PROJECTSRC_DIR"))
env.Exit(1)
program = env.Program(
join("$BUILD_DIR", env.subst("$PROGNAME")), env['PIOBUILDFILES'])
@ -230,15 +233,18 @@ def BuildFrameworks(env, frameworks):
return
if "BOARD" not in env:
env.Exit("Please specify `board` in `platformio.ini` to use "
"with '%s' framework" % ", ".join(frameworks))
sys.stderr.write("Please specify `board` in `platformio.ini` to use "
"with '%s' framework\n" % ", ".join(frameworks))
env.Exit(1)
board_frameworks = env.BoardConfig().get("frameworks", [])
if frameworks == ["platformio"]:
if board_frameworks:
frameworks.insert(0, board_frameworks[0])
else:
env.Exit("Error: Please specify `board` in `platformio.ini`")
sys.stderr.write(
"Error: Please specify `board` in `platformio.ini`\n")
env.Exit(1)
for f in frameworks:
if f in ("arduino", "energia"):
@ -247,7 +253,9 @@ def BuildFrameworks(env, frameworks):
if f in board_frameworks:
SConscript(env.GetFrameworkScript(f))
else:
env.Exit("Error: This board doesn't support %s framework!" % f)
sys.stderr.write(
"Error: This board doesn't support %s framework!\n" % f)
env.Exit(1)
def BuildLibrary(env, variant_dir, src_dir, src_filter=None):