forked from platformio/platformio-core
Replace os.path.abspath by realpath
This commit is contained in:
@ -17,7 +17,7 @@ import hashlib
|
|||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
from os import environ, getenv, listdir, remove
|
from os import environ, getenv, listdir, remove
|
||||||
from os.path import abspath, dirname, isdir, isfile, join
|
from os.path import dirname, isdir, isfile, join, realpath
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@ -34,7 +34,7 @@ from platformio.project.helpers import (
|
|||||||
|
|
||||||
def projects_dir_validate(projects_dir):
|
def projects_dir_validate(projects_dir):
|
||||||
assert isdir(projects_dir)
|
assert isdir(projects_dir)
|
||||||
return abspath(projects_dir)
|
return realpath(projects_dir)
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_SETTINGS = {
|
DEFAULT_SETTINGS = {
|
||||||
|
@ -14,9 +14,8 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import os
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from os import environ
|
|
||||||
from os.path import abspath, isfile, join
|
|
||||||
|
|
||||||
from SCons.Defaults import processDefines # pylint: disable=import-error
|
from SCons.Defaults import processDefines # pylint: disable=import-error
|
||||||
|
|
||||||
@ -42,10 +41,10 @@ def _dump_includes(env):
|
|||||||
continue
|
continue
|
||||||
toolchain_dir = glob_escape(p.get_package_dir(name))
|
toolchain_dir = glob_escape(p.get_package_dir(name))
|
||||||
toolchain_incglobs = [
|
toolchain_incglobs = [
|
||||||
join(toolchain_dir, "*", "include*"),
|
os.path.join(toolchain_dir, "*", "include*"),
|
||||||
join(toolchain_dir, "*", "include", "c++", "*"),
|
os.path.join(toolchain_dir, "*", "include", "c++", "*"),
|
||||||
join(toolchain_dir, "*", "include", "c++", "*", "*-*-*"),
|
os.path.join(toolchain_dir, "*", "include", "c++", "*", "*-*-*"),
|
||||||
join(toolchain_dir, "lib", "gcc", "*", "*", "include*"),
|
os.path.join(toolchain_dir, "lib", "gcc", "*", "*", "include*"),
|
||||||
]
|
]
|
||||||
for g in toolchain_incglobs:
|
for g in toolchain_incglobs:
|
||||||
includes.extend(glob(g))
|
includes.extend(glob(g))
|
||||||
@ -59,8 +58,9 @@ def _dump_includes(env):
|
|||||||
# remove duplicates
|
# remove duplicates
|
||||||
result = []
|
result = []
|
||||||
for item in includes:
|
for item in includes:
|
||||||
|
item = os.path.realpath(item)
|
||||||
if item not in result:
|
if item not in result:
|
||||||
result.append(abspath(item))
|
result.append(item)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ def _dump_includes(env):
|
|||||||
def _get_gcc_defines(env):
|
def _get_gcc_defines(env):
|
||||||
items = []
|
items = []
|
||||||
try:
|
try:
|
||||||
sysenv = environ.copy()
|
sysenv = os.environ.copy()
|
||||||
sysenv["PATH"] = str(env["ENV"]["PATH"])
|
sysenv["PATH"] = str(env["ENV"]["PATH"])
|
||||||
result = exec_command(
|
result = exec_command(
|
||||||
"echo | %s -dM -E -" % env.subst("$CC"), env=sysenv, shell=True
|
"echo | %s -dM -E -" % env.subst("$CC"), env=sysenv, shell=True
|
||||||
@ -119,7 +119,7 @@ def _dump_defines(env):
|
|||||||
def _get_svd_path(env):
|
def _get_svd_path(env):
|
||||||
svd_path = env.GetProjectOption("debug_svd_path")
|
svd_path = env.GetProjectOption("debug_svd_path")
|
||||||
if svd_path:
|
if svd_path:
|
||||||
return abspath(svd_path)
|
return os.path.realpath(svd_path)
|
||||||
|
|
||||||
if "BOARD" not in env:
|
if "BOARD" not in env:
|
||||||
return None
|
return None
|
||||||
@ -129,12 +129,12 @@ def _get_svd_path(env):
|
|||||||
except (AssertionError, KeyError):
|
except (AssertionError, KeyError):
|
||||||
return None
|
return None
|
||||||
# custom path to SVD file
|
# custom path to SVD file
|
||||||
if isfile(svd_path):
|
if os.path.isfile(svd_path):
|
||||||
return svd_path
|
return svd_path
|
||||||
# default file from ./platform/misc/svd folder
|
# default file from ./platform/misc/svd folder
|
||||||
p = env.PioPlatform()
|
p = env.PioPlatform()
|
||||||
if isfile(join(p.get_dir(), "misc", "svd", svd_path)):
|
if os.path.isfile(os.path.join(p.get_dir(), "misc", "svd", svd_path)):
|
||||||
return abspath(join(p.get_dir(), "misc", "svd", svd_path))
|
return os.path.realpath(os.path.join(p.get_dir(), "misc", "svd", svd_path))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from os.path import abspath, relpath
|
import os
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ class DefectItem(object):
|
|||||||
self.id = id
|
self.id = id
|
||||||
self.file = file
|
self.file = file
|
||||||
if file.startswith(get_project_dir()):
|
if file.startswith(get_project_dir()):
|
||||||
self.file = relpath(file, get_project_dir())
|
self.file = os.path.relpath(file, get_project_dir())
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
defect_color = None
|
defect_color = None
|
||||||
@ -86,7 +86,7 @@ class DefectItem(object):
|
|||||||
"severity": self.SEVERITY_LABELS[self.severity],
|
"severity": self.SEVERITY_LABELS[self.severity],
|
||||||
"category": self.category,
|
"category": self.category,
|
||||||
"message": self.message,
|
"message": self.message,
|
||||||
"file": abspath(self.file),
|
"file": os.path.realpath(self.file),
|
||||||
"line": self.line,
|
"line": self.line,
|
||||||
"column": self.column,
|
"column": self.column,
|
||||||
"callstack": self.callstack,
|
"callstack": self.callstack,
|
||||||
|
@ -132,7 +132,7 @@ class CheckToolBase(object): # pylint: disable=too-many-instance-attributes
|
|||||||
def _add_file(path):
|
def _add_file(path):
|
||||||
if not path.endswith(allowed_extensions):
|
if not path.endswith(allowed_extensions):
|
||||||
return
|
return
|
||||||
result.append(os.path.abspath(path))
|
result.append(os.path.realpath(path))
|
||||||
|
|
||||||
for pattern in self.options["patterns"]:
|
for pattern in self.options["patterns"]:
|
||||||
for item in glob.glob(pattern):
|
for item in glob.glob(pattern):
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from os import getenv, makedirs, remove
|
from os import getenv, makedirs, remove
|
||||||
from os.path import abspath, basename, isdir, isfile, join
|
from os.path import basename, isdir, isfile, join, realpath
|
||||||
from shutil import copyfile, copytree
|
from shutil import copyfile, copytree
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ def validate_path(ctx, param, value): # pylint: disable=unused-argument
|
|||||||
for i, p in enumerate(value):
|
for i, p in enumerate(value):
|
||||||
if p.startswith("~"):
|
if p.startswith("~"):
|
||||||
value[i] = fs.expanduser(p)
|
value[i] = fs.expanduser(p)
|
||||||
value[i] = abspath(value[i])
|
value[i] = realpath(value[i])
|
||||||
if not glob(value[i]):
|
if not glob(value[i]):
|
||||||
invalid_path = p
|
invalid_path = p
|
||||||
break
|
break
|
||||||
@ -158,7 +158,7 @@ def _exclude_contents(dst_dir, patterns):
|
|||||||
for p in patterns:
|
for p in patterns:
|
||||||
contents += glob(join(glob_escape(dst_dir), p))
|
contents += glob(join(glob_escape(dst_dir), p))
|
||||||
for path in contents:
|
for path in contents:
|
||||||
path = abspath(path)
|
path = realpath(path)
|
||||||
if isdir(path):
|
if isdir(path):
|
||||||
fs.rmtree(path)
|
fs.rmtree(path)
|
||||||
elif isfile(path):
|
elif isfile(path):
|
||||||
|
@ -18,7 +18,7 @@ import re
|
|||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
from os.path import abspath, basename, dirname, isdir, join, splitext
|
from os.path import basename, dirname, isdir, join, realpath, splitext
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
|
|
||||||
from twisted.internet import protocol # pylint: disable=import-error
|
from twisted.internet import protocol # pylint: disable=import-error
|
||||||
@ -108,7 +108,7 @@ class GDBClient(BaseProcess): # pylint: disable=too-many-instance-attributes
|
|||||||
def _get_data_dir(gdb_path):
|
def _get_data_dir(gdb_path):
|
||||||
if "msp430" in gdb_path:
|
if "msp430" in gdb_path:
|
||||||
return None
|
return None
|
||||||
gdb_data_dir = abspath(join(dirname(gdb_path), "..", "share", "gdb"))
|
gdb_data_dir = realpath(join(dirname(gdb_path), "..", "share", "gdb"))
|
||||||
return gdb_data_dir if isdir(gdb_data_dir) else None
|
return gdb_data_dir if isdir(gdb_data_dir) else None
|
||||||
|
|
||||||
def generate_pioinit(self, dst_dir, patterns):
|
def generate_pioinit(self, dst_dir, patterns):
|
||||||
|
@ -40,7 +40,7 @@ class cd(object):
|
|||||||
|
|
||||||
|
|
||||||
def get_source_dir():
|
def get_source_dir():
|
||||||
curpath = os.path.abspath(__file__)
|
curpath = os.path.realpath(__file__)
|
||||||
if not os.path.isfile(curpath):
|
if not os.path.isfile(curpath):
|
||||||
for p in sys.path:
|
for p in sys.path:
|
||||||
if os.path.isfile(os.path.join(p, __file__)):
|
if os.path.isfile(os.path.join(p, __file__)):
|
||||||
@ -117,7 +117,7 @@ def ensure_udev_rules():
|
|||||||
if not any(os.path.isfile(p) for p in installed_rules):
|
if not any(os.path.isfile(p) for p in installed_rules):
|
||||||
raise exception.MissedUdevRules
|
raise exception.MissedUdevRules
|
||||||
|
|
||||||
origin_path = os.path.abspath(
|
origin_path = os.path.realpath(
|
||||||
os.path.join(get_source_dir(), "..", "scripts", "99-platformio-udev.rules")
|
os.path.join(get_source_dir(), "..", "scripts", "99-platformio-udev.rules")
|
||||||
)
|
)
|
||||||
if not os.path.isfile(origin_path):
|
if not os.path.isfile(origin_path):
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from os.path import abspath, basename, isdir, isfile, join, relpath
|
from os.path import basename, isdir, isfile, join, realpath, relpath
|
||||||
|
|
||||||
import bottle
|
import bottle
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ class ProjectGenerator(object):
|
|||||||
"project_name": basename(self.project_dir),
|
"project_name": basename(self.project_dir),
|
||||||
"project_dir": self.project_dir,
|
"project_dir": self.project_dir,
|
||||||
"env_name": self.env_name,
|
"env_name": self.env_name,
|
||||||
"user_home_dir": abspath(fs.expanduser("~")),
|
"user_home_dir": realpath(fs.expanduser("~")),
|
||||||
"platformio_path": sys.argv[0]
|
"platformio_path": sys.argv[0]
|
||||||
if isfile(sys.argv[0])
|
if isfile(sys.argv[0])
|
||||||
else where_is_program("platformio"),
|
else where_is_program("platformio"),
|
||||||
|
@ -12,8 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from os import remove
|
import os
|
||||||
from os.path import abspath, exists, getmtime
|
|
||||||
from time import sleep, time
|
from time import sleep, time
|
||||||
|
|
||||||
from platformio import exception
|
from platformio import exception
|
||||||
@ -45,15 +44,15 @@ class LockFile(object):
|
|||||||
def __init__(self, path, timeout=LOCKFILE_TIMEOUT, delay=LOCKFILE_DELAY):
|
def __init__(self, path, timeout=LOCKFILE_TIMEOUT, delay=LOCKFILE_DELAY):
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.delay = delay
|
self.delay = delay
|
||||||
self._lock_path = abspath(path) + ".lock"
|
self._lock_path = os.path.realpath(path) + ".lock"
|
||||||
self._fp = None
|
self._fp = None
|
||||||
|
|
||||||
def _lock(self):
|
def _lock(self):
|
||||||
if not LOCKFILE_CURRENT_INTERFACE and exists(self._lock_path):
|
if not LOCKFILE_CURRENT_INTERFACE and os.path.exists(self._lock_path):
|
||||||
# remove stale lock
|
# remove stale lock
|
||||||
if time() - getmtime(self._lock_path) > 10:
|
if time() - os.path.getmtime(self._lock_path) > 10:
|
||||||
try:
|
try:
|
||||||
remove(self._lock_path)
|
os.remove(self._lock_path)
|
||||||
except: # pylint: disable=bare-except
|
except: # pylint: disable=bare-except
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@ -93,9 +92,9 @@ class LockFile(object):
|
|||||||
|
|
||||||
def release(self):
|
def release(self):
|
||||||
self._unlock()
|
self._unlock()
|
||||||
if exists(self._lock_path):
|
if os.path.exists(self._lock_path):
|
||||||
try:
|
try:
|
||||||
remove(self._lock_path)
|
os.remove(self._lock_path)
|
||||||
except: # pylint: disable=bare-except
|
except: # pylint: disable=bare-except
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
from os.path import abspath, basename, getsize, isdir, isfile, islink, join
|
from os.path import basename, getsize, isdir, isfile, islink, join, realpath
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
|
|
||||||
import click
|
import click
|
||||||
@ -423,7 +423,7 @@ class PkgInstallerMixin(object):
|
|||||||
|
|
||||||
def get_package_by_dir(self, pkg_dir):
|
def get_package_by_dir(self, pkg_dir):
|
||||||
for manifest in self.get_installed():
|
for manifest in self.get_installed():
|
||||||
if manifest["__pkg_dir"] == abspath(pkg_dir):
|
if manifest["__pkg_dir"] == realpath(pkg_dir):
|
||||||
return manifest
|
return manifest
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user