Move "to_unix_path" helper to FS module

This commit is contained in:
Ivan Kravets
2019-08-27 20:21:53 +03:00
parent 98ec287797
commit 8037bef847
2 changed files with 11 additions and 12 deletions

View File

@ -23,7 +23,7 @@ from glob import glob
import click import click
from platformio import exception from platformio import exception
from platformio.compat import get_file_contents, glob_escape from platformio.compat import WINDOWS, get_file_contents, glob_escape
class cd(object): class cd(object):
@ -146,6 +146,12 @@ def match_src_files(src_dir, src_filter=None, src_exts=None):
return sorted(list(matches)) return sorted(list(matches))
def to_unix_path(path):
if not WINDOWS or not path:
return path
return re.sub(r"[\\]+", "/", path)
def rmtree(path): def rmtree(path):
def _onerror(func, path, __): def _onerror(func, path, __):

View File

@ -14,14 +14,13 @@
import codecs import codecs
import os import os
import re
import sys import sys
from os.path import abspath, basename, expanduser, isdir, isfile, join, relpath from os.path import abspath, basename, expanduser, isdir, isfile, join, relpath
import bottle import bottle
from platformio import fs, util from platformio import fs, util
from platformio.compat import WINDOWS, get_file_contents from platformio.compat import get_file_contents
from platformio.proc import where_is_program from platformio.proc import where_is_program
from platformio.project.config import ProjectConfig from platformio.project.config import ProjectConfig
from platformio.project.helpers import (get_project_lib_dir, from platformio.project.helpers import (get_project_lib_dir,
@ -98,21 +97,15 @@ class ProjectGenerator(object):
for key, value in tpl_vars.items(): for key, value in tpl_vars.items():
if key.endswith(("_path", "_dir")): if key.endswith(("_path", "_dir")):
tpl_vars[key] = self.to_unix_path(value) tpl_vars[key] = fs.to_unix_path(value)
for key in ("includes", "src_files", "libsource_dirs"): for key in ("includes", "src_files", "libsource_dirs"):
if key not in tpl_vars: if key not in tpl_vars:
continue continue
tpl_vars[key] = [self.to_unix_path(inc) for inc in tpl_vars[key]] tpl_vars[key] = [fs.to_unix_path(inc) for inc in tpl_vars[key]]
tpl_vars['to_unix_path'] = self.to_unix_path tpl_vars['to_unix_path'] = fs.to_unix_path
return tpl_vars return tpl_vars
@staticmethod
def to_unix_path(path):
if not WINDOWS or not path:
return path
return re.sub(r"[\\]+", "/", path)
def get_src_files(self): def get_src_files(self):
result = [] result = []
with fs.cd(self.project_dir): with fs.cd(self.project_dir):