Replace os.path.abspath by realpath

This commit is contained in:
Ivan Kravets
2019-11-15 16:02:15 +02:00
parent fbdcbf17c7
commit 6809da0353
10 changed files with 36 additions and 37 deletions

View File

@ -17,7 +17,7 @@ import hashlib
import os
import uuid
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
import requests
@ -34,7 +34,7 @@ from platformio.project.helpers import (
def projects_dir_validate(projects_dir):
assert isdir(projects_dir)
return abspath(projects_dir)
return realpath(projects_dir)
DEFAULT_SETTINGS = {

View File

@ -14,9 +14,8 @@
from __future__ import absolute_import
import os
from glob import glob
from os import environ
from os.path import abspath, isfile, join
from SCons.Defaults import processDefines # pylint: disable=import-error
@ -42,10 +41,10 @@ def _dump_includes(env):
continue
toolchain_dir = glob_escape(p.get_package_dir(name))
toolchain_incglobs = [
join(toolchain_dir, "*", "include*"),
join(toolchain_dir, "*", "include", "c++", "*"),
join(toolchain_dir, "*", "include", "c++", "*", "*-*-*"),
join(toolchain_dir, "lib", "gcc", "*", "*", "include*"),
os.path.join(toolchain_dir, "*", "include*"),
os.path.join(toolchain_dir, "*", "include", "c++", "*"),
os.path.join(toolchain_dir, "*", "include", "c++", "*", "*-*-*"),
os.path.join(toolchain_dir, "lib", "gcc", "*", "*", "include*"),
]
for g in toolchain_incglobs:
includes.extend(glob(g))
@ -59,8 +58,9 @@ def _dump_includes(env):
# remove duplicates
result = []
for item in includes:
item = os.path.realpath(item)
if item not in result:
result.append(abspath(item))
result.append(item)
return result
@ -68,7 +68,7 @@ def _dump_includes(env):
def _get_gcc_defines(env):
items = []
try:
sysenv = environ.copy()
sysenv = os.environ.copy()
sysenv["PATH"] = str(env["ENV"]["PATH"])
result = exec_command(
"echo | %s -dM -E -" % env.subst("$CC"), env=sysenv, shell=True
@ -119,7 +119,7 @@ def _dump_defines(env):
def _get_svd_path(env):
svd_path = env.GetProjectOption("debug_svd_path")
if svd_path:
return abspath(svd_path)
return os.path.realpath(svd_path)
if "BOARD" not in env:
return None
@ -129,12 +129,12 @@ def _get_svd_path(env):
except (AssertionError, KeyError):
return None
# custom path to SVD file
if isfile(svd_path):
if os.path.isfile(svd_path):
return svd_path
# default file from ./platform/misc/svd folder
p = env.PioPlatform()
if isfile(join(p.get_dir(), "misc", "svd", svd_path)):
return abspath(join(p.get_dir(), "misc", "svd", svd_path))
if os.path.isfile(os.path.join(p.get_dir(), "misc", "svd", svd_path)):
return os.path.realpath(os.path.join(p.get_dir(), "misc", "svd", svd_path))
return None

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from os.path import abspath, relpath
import os
import click
@ -52,7 +52,7 @@ class DefectItem(object):
self.id = id
self.file = file
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):
defect_color = None
@ -86,7 +86,7 @@ class DefectItem(object):
"severity": self.SEVERITY_LABELS[self.severity],
"category": self.category,
"message": self.message,
"file": abspath(self.file),
"file": os.path.realpath(self.file),
"line": self.line,
"column": self.column,
"callstack": self.callstack,

View File

@ -132,7 +132,7 @@ class CheckToolBase(object): # pylint: disable=too-many-instance-attributes
def _add_file(path):
if not path.endswith(allowed_extensions):
return
result.append(os.path.abspath(path))
result.append(os.path.realpath(path))
for pattern in self.options["patterns"]:
for item in glob.glob(pattern):

View File

@ -14,7 +14,7 @@
from glob import glob
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 tempfile import mkdtemp
@ -35,7 +35,7 @@ def validate_path(ctx, param, value): # pylint: disable=unused-argument
for i, p in enumerate(value):
if p.startswith("~"):
value[i] = fs.expanduser(p)
value[i] = abspath(value[i])
value[i] = realpath(value[i])
if not glob(value[i]):
invalid_path = p
break
@ -158,7 +158,7 @@ def _exclude_contents(dst_dir, patterns):
for p in patterns:
contents += glob(join(glob_escape(dst_dir), p))
for path in contents:
path = abspath(path)
path = realpath(path)
if isdir(path):
fs.rmtree(path)
elif isfile(path):

View File

@ -18,7 +18,7 @@ import re
import signal
import time
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 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):
if "msp430" in gdb_path:
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
def generate_pioinit(self, dst_dir, patterns):

View File

@ -40,7 +40,7 @@ class cd(object):
def get_source_dir():
curpath = os.path.abspath(__file__)
curpath = os.path.realpath(__file__)
if not os.path.isfile(curpath):
for p in sys.path:
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):
raise exception.MissedUdevRules
origin_path = os.path.abspath(
origin_path = os.path.realpath(
os.path.join(get_source_dir(), "..", "scripts", "99-platformio-udev.rules")
)
if not os.path.isfile(origin_path):

View File

@ -15,7 +15,7 @@
import io
import os
import sys
from os.path import abspath, basename, isdir, isfile, join, relpath
from os.path import basename, isdir, isfile, join, realpath, relpath
import bottle
@ -64,7 +64,7 @@ class ProjectGenerator(object):
"project_name": basename(self.project_dir),
"project_dir": self.project_dir,
"env_name": self.env_name,
"user_home_dir": abspath(fs.expanduser("~")),
"user_home_dir": realpath(fs.expanduser("~")),
"platformio_path": sys.argv[0]
if isfile(sys.argv[0])
else where_is_program("platformio"),

View File

@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from os import remove
from os.path import abspath, exists, getmtime
import os
from time import sleep, time
from platformio import exception
@ -45,15 +44,15 @@ class LockFile(object):
def __init__(self, path, timeout=LOCKFILE_TIMEOUT, delay=LOCKFILE_DELAY):
self.timeout = timeout
self.delay = delay
self._lock_path = abspath(path) + ".lock"
self._lock_path = os.path.realpath(path) + ".lock"
self._fp = None
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
if time() - getmtime(self._lock_path) > 10:
if time() - os.path.getmtime(self._lock_path) > 10:
try:
remove(self._lock_path)
os.remove(self._lock_path)
except: # pylint: disable=bare-except
pass
else:
@ -93,9 +92,9 @@ class LockFile(object):
def release(self):
self._unlock()
if exists(self._lock_path):
if os.path.exists(self._lock_path):
try:
remove(self._lock_path)
os.remove(self._lock_path)
except: # pylint: disable=bare-except
pass

View File

@ -17,7 +17,7 @@ import json
import os
import re
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
import click
@ -423,7 +423,7 @@ class PkgInstallerMixin(object):
def get_package_by_dir(self, pkg_dir):
for manifest in self.get_installed():
if manifest["__pkg_dir"] == abspath(pkg_dir):
if manifest["__pkg_dir"] == realpath(pkg_dir):
return manifest
return None