diff options
author | William Deegan <bill@baddogconsulting.com> | 2021-05-04 03:28:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-04 03:28:06 (GMT) |
commit | f046cf47ded412a0b96edb560ed7bb2daf72ccfb (patch) | |
tree | d629e0d57951e69c68a2c48fbe1f34bba23ea051 | |
parent | 147267b81c75e20cb780957bcf94a2416a0bade5 (diff) | |
parent | 2ea622bf4b2d5e6ffff66fabdb234720404b4d82 (diff) | |
download | SCons-f046cf47ded412a0b96edb560ed7bb2daf72ccfb.zip SCons-f046cf47ded412a0b96edb560ed7bb2daf72ccfb.tar.gz SCons-f046cf47ded412a0b96edb560ed7bb2daf72ccfb.tar.bz2 |
Merge pull request #3941 from mwichmann/scandir
Some code modernization: fs layer methods and others
-rwxr-xr-x | CHANGES.txt | 3 | ||||
-rw-r--r-- | SCons/CacheDir.py | 15 | ||||
-rw-r--r-- | SCons/Executor.py | 4 | ||||
-rw-r--r-- | SCons/Node/FS.py | 39 | ||||
-rw-r--r-- | SCons/Subst.py | 4 | ||||
-rw-r--r-- | SCons/Util.py | 6 |
6 files changed, 40 insertions, 31 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index d47cbdd..e7d555d 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -86,6 +86,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER - Simplified Mkdir(), the internal mkdir_func no longer needs to handle existing directories, it can now pass exist_ok=True to os.makedirs(). - Avoid WhereIs exception if user set a tool name to empty (from issue 1742) + - Maintenance: remove obsolete __getslice__ definitions (Py3 never calls); + add Node.fs.scandir to call new (Py3.5) os.scandir; Node.fs.makedirs + now passes the exist_ok flag; Cachedir creation now uses this flag. From Dillan Mills: - Add support for the (TARGET,SOURCE,TARGETS,SOURCES,CHANGED_TARGETS,CHANGED_SOURCES}.relpath property. diff --git a/SCons/CacheDir.py b/SCons/CacheDir.py index 90c70e5..f021751 100644 --- a/SCons/CacheDir.py +++ b/SCons/CacheDir.py @@ -106,16 +106,11 @@ def CachePushFunc(target, source, env): tempfile = "%s.tmp%s"%(cachefile,cache_tmp_uuid) errfmt = "Unable to copy %s to cache. Cache file is %s" - if not fs.isdir(cachedir): - try: - fs.makedirs(cachedir) - except EnvironmentError: - # We may have received an exception because another process - # has beaten us creating the directory. - if not fs.isdir(cachedir): - msg = errfmt % (str(target), cachefile) - raise SCons.Errors.SConsEnvironmentError(msg) - + try: + fs.makedirs(cachedir, exist_ok=True) + except OSError: + msg = errfmt % (str(target), cachefile) + raise SCons.Errors.SConsEnvironmentError(msg) try: if fs.islink(t.get_internal_path()): fs.symlink(fs.readlink(t.get_internal_path()), tempfile) diff --git a/SCons/Executor.py b/SCons/Executor.py index 005906f..ee52151 100644 --- a/SCons/Executor.py +++ b/SCons/Executor.py @@ -63,10 +63,6 @@ class TSList(collections.UserList): def __getitem__(self, i): nl = self.func() return nl[i] - def __getslice__(self, i, j): - nl = self.func() - i, j = max(i, 0), max(j, 0) - return nl[i:j] def __str__(self): nl = self.func() return str(nl) diff --git a/SCons/Node/FS.py b/SCons/Node/FS.py index fd2f719..909e5b6 100644 --- a/SCons/Node/FS.py +++ b/SCons/Node/FS.py @@ -1116,56 +1116,81 @@ class LocalFS: needs to use os.chdir() directly to avoid recursion. Will we really need this one? """ - #def chdir(self, path): - # return os.chdir(path) + def chmod(self, path, mode): return os.chmod(path, mode) + def copy(self, src, dst): return shutil.copy(src, dst) + def copy2(self, src, dst): return shutil.copy2(src, dst) + def exists(self, path): return os.path.exists(path) + def getmtime(self, path): return os.path.getmtime(path) + def getsize(self, path): return os.path.getsize(path) + def isdir(self, path): return os.path.isdir(path) + def isfile(self, path): return os.path.isfile(path) + def link(self, src, dst): return os.link(src, dst) + def lstat(self, path): return os.lstat(path) + def listdir(self, path): return os.listdir(path) - def makedirs(self, path): - return os.makedirs(path) - def mkdir(self, path): - return os.mkdir(path) + + def scandir(self, path): + return os.scandir(path) + + def makedirs(self, path, mode=0o777, exist_ok=False): + return os.makedirs(path, mode=mode, exist_ok=exist_ok) + + def mkdir(self, path, mode=0o777): + return os.mkdir(path, mode=mode) + def rename(self, old, new): return os.rename(old, new) + def stat(self, path): return os.stat(path) + def symlink(self, src, dst): return os.symlink(src, dst) + def open(self, path): return open(path) + def unlink(self, path): return os.unlink(path) if hasattr(os, 'symlink'): + def islink(self, path): return os.path.islink(path) + else: + def islink(self, path): - return 0 # no symlinks + return False # no symlinks if hasattr(os, 'readlink'): + def readlink(self, file): return os.readlink(file) + else: + def readlink(self, file): return '' diff --git a/SCons/Subst.py b/SCons/Subst.py index f23b2d0..4d732c3 100644 --- a/SCons/Subst.py +++ b/SCons/Subst.py @@ -217,10 +217,6 @@ class Targets_or_Sources(collections.UserList): def __getitem__(self, i): nl = self.nl._create_nodelist() return nl[i] - def __getslice__(self, i, j): - nl = self.nl._create_nodelist() - i = max(i, 0); j = max(j, 0) - return nl[i:j] def __str__(self): nl = self.nl._create_nodelist() return str(nl) diff --git a/SCons/Util.py b/SCons/Util.py index af43220..4e575d5 100644 --- a/SCons/Util.py +++ b/SCons/Util.py @@ -1345,12 +1345,6 @@ class UniqueList(UserList): def __setitem__(self, i, item): UserList.__setitem__(self, i, item) self.unique = False - def __getslice__(self, i, j): - self.__make_unique() - return UserList.__getslice__(self, i, j) - def __setslice__(self, i, j, other): - UserList.__setslice__(self, i, j, other) - self.unique = False def __add__(self, other): result = UserList.__add__(self, other) result.unique = False |