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( sys.stderr.write(
"Error: Could not find `%s` dependency for `%s` " "Error: Could not find `%s` dependency for `%s` "
"library\n" % (item['name'], self.name)) "library\n" % (item['name'], self.name))
self.env.Exit(2) self.env.Exit(1)
def _validate_search_paths(self, search_paths=None): def _validate_search_paths(self, search_paths=None):
if not search_paths: if not search_paths:

View File

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

View File

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

View File

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

View File

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

View File

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