From c254a3490cd40775524f185c8145a9e01988510e Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 4 Sep 2015 20:35:56 +0300 Subject: [PATCH] Fix path for Windows-based projects --- platformio/__main__.py | 7 ++----- platformio/ide/projectgenerator.py | 12 +++++++++--- .../eclipse/.settings/org.eclipse.cdt.core.prefs.tpl | 4 ++-- .../tpls/sublimetext/platformio.sublime-project.tpl | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/platformio/__main__.py b/platformio/__main__.py index 33a2391d..d6674297 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -75,12 +75,9 @@ def main(): try: requests.packages.urllib3.disable_warnings() except AttributeError: - click.secho( + raise exception.PlatformioException( "Invalid installation of Python `requests` package`. See " - "< https://github.com/platformio/platformio/issues/252 >", - fg="red", err=True - ) - return 1 + "< https://github.com/platformio/platformio/issues/252 >") cli(None, None, None) except Exception as e: # pylint: disable=W0703 diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index b694620d..b92ccffc 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -3,6 +3,7 @@ import json import os +import re from os.path import abspath, basename, expanduser, isdir, join, relpath import bottle @@ -88,7 +89,7 @@ class ProjectGenerator(object): continue _relpath = root.replace(tpls_dir, "") if _relpath.startswith(os.sep): - _relpath = _relpath[len(os.sep):] + _relpath = _relpath[1:] tpls.append((_relpath, join(root, f))) return tpls @@ -119,7 +120,12 @@ class ProjectGenerator(object): "user_home_dir": abspath(expanduser("~")), "project_dir": self.project_dir, "systype": util.get_systype(), - "platformio_path": util.where_is_program("platformio"), + "platformio_path": self._fix_os_path( + util.where_is_program("platformio")), "env_pathsep": os.pathsep, - "env_path": os.getenv("PATH") + "env_path": self._fix_os_path(os.getenv("PATH")) }) + + @staticmethod + def _fix_os_path(path): + return re.sub(r"[\\]+", "\\\\", path) diff --git a/platformio/ide/tpls/eclipse/.settings/org.eclipse.cdt.core.prefs.tpl b/platformio/ide/tpls/eclipse/.settings/org.eclipse.cdt.core.prefs.tpl index e7858ef9..92bd1fde 100644 --- a/platformio/ide/tpls/eclipse/.settings/org.eclipse.cdt.core.prefs.tpl +++ b/platformio/ide/tpls/eclipse/.settings/org.eclipse.cdt.core.prefs.tpl @@ -1,6 +1,6 @@ eclipse.preferences.version=1 -environment/project/0.910961921/PATH/delimiter=\{{env_pathsep}} +environment/project/0.910961921/PATH/delimiter={{env_pathsep.replace(":", "\\:")}} environment/project/0.910961921/PATH/operation=replace -environment/project/0.910961921/PATH/value={{env_path.replace(env_pathsep, "\\%s" % env_pathsep)}} +environment/project/0.910961921/PATH/value={{env_path.replace(":", "\\:")}} environment/project/0.910961921/append=true environment/project/0.910961921/appendContributed=false diff --git a/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl b/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl index f668f73d..4a3a1ada 100644 --- a/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl +++ b/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl @@ -8,7 +8,7 @@ "-f", "-c", "sublimetext", "run" ], - "path": "{{env_path}}" + "path": "{{env_path}}", "name": "PlatformIO", "variants": [