Handle "OSError: [Errno 13] Permission denied" for PlatformIO installer script

This commit is contained in:
Ivan Kravets
2015-07-21 17:51:33 +03:00
parent 5a91d0bf1b
commit b79a79d423
2 changed files with 33 additions and 10 deletions

View File

@@ -7,6 +7,8 @@ Release History
* Disable project auto-clean while building/uploading firmware using * Disable project auto-clean while building/uploading firmware using
`platformio run --disable-auto-clean <http://docs.platformio.org/en/latest/userguide/cmd_run.html#cmdoption--disable-auto-clean>`_ option `platformio run --disable-auto-clean <http://docs.platformio.org/en/latest/userguide/cmd_run.html#cmdoption--disable-auto-clean>`_ option
(`issue #255 <https://github.com/platformio/platformio/issues/255>`_) (`issue #255 <https://github.com/platformio/platformio/issues/255>`_)
* Handle "OSError: [Errno 13] Permission denied" for PlatformIO installer script
(`issue #254 <https://github.com/platformio/platformio/issues/254>`_)
2.2.1 (2015-07-17) 2.2.1 (2015-07-17)
------------------ ------------------

View File

@@ -9,7 +9,7 @@ from tempfile import NamedTemporaryFile
CURINTERPRETER_PATH = os.path.normpath(sys.executable) CURINTERPRETER_PATH = os.path.normpath(sys.executable)
IS_WINDOWS = system() == "Windows" IS_WINDOWS = system().lower() == "windows"
def fix_winpython_pathenv(): def fix_winpython_pathenv():
@@ -61,12 +61,12 @@ def exec_command(*args, **kwargs):
out, err = p.communicate() out, err = p.communicate()
if p.returncode != 0: if p.returncode != 0:
raise Exception(err) raise Exception("\n".join([out, err]))
return out return out
def exec_python_cmd(args): def exec_python_cmd(args):
return exec_command([CURINTERPRETER_PATH] + args, shell=IS_WINDOWS).strip() return exec_command([CURINTERPRETER_PATH] + args).strip()
def install_pip(): def install_pip():
@@ -89,8 +89,7 @@ def install_pip():
def install_pypi_packages(packages): def install_pypi_packages(packages):
for pipargs in packages: for pipargs in packages:
print (exec_python_cmd([ print (exec_python_cmd([
"-m", "-m", "pip.__main__" if sys.version_info < (2, 7, 0) else "pip",
"pip.__main__" if sys.version_info < (2, 7, 0) else "pip",
"install", "-U"] + pipargs)) "install", "-U"] + pipargs))
@@ -110,14 +109,27 @@ def main():
is_error = False is_error = False
for s in steps: for s in steps:
if is_error:
break
print ("\n==> %s ..." % s[0]) print ("\n==> %s ..." % s[0])
try: try:
s[1](*s[2]) s[1](*s[2])
print ("[SUCCESS]") print ("[SUCCESS]")
except Exception, e: except Exception, e:
is_error = True is_error = True
print (e) print (str(e))
print ("[FAILURE]") print ("[FAILURE]")
if "Permission denied" in str(e) and not IS_WINDOWS:
print ("""
-----------------
Permission denied
-----------------
You need the `sudo` permission to install Python packages. Try
$ sudo python -c "$(curl -fsSL
https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"
""")
if is_error: if is_error:
print ("The installation process has been FAILED!\n" print ("The installation process has been FAILED!\n"
@@ -129,16 +141,25 @@ def main():
"successfully FINISHED! <==\n") "successfully FINISHED! <==\n")
try: try:
print (exec_command("platformio", shell=IS_WINDOWS)) print (exec_command("platformio"))
except: except:
try: try:
print (exec_python_cmd([ print (exec_python_cmd([
"-m", "-m",
"platformio.__main__" if sys.version_info < (2, 7, 0) else "platformio.__main__" if sys.version_info < (2, 7, 0) else
"platformio"])) "platformio"]))
finally: except:
print ("\n Please RESTART your Terminal Application and run " pass
"`platformio --help` command.") finally:
print ("""
----------------------------------------
Please RESTART your Terminal Application
----------------------------------------
Then run `platformio --help` command.
""")
if __name__ == "__main__": if __name__ == "__main__":