[master 3/4] Make distutils.filelist.findall() do the right thing with symlinks maybe.

vathpela installerbot-noreply at redhat.com
Tue Oct 13 20:01:43 UTC 2015


From: Peter Jones <pjones at redhat.com>

I'm not sure this would be right if we actually wanted to /include/ the
symlink itself, but since so far they're all in directories we don't
include in the tarball, this will at least make the traversal of them
not fail.

This fixes "make local" with the EDD test case data.

Signed-off-by: Peter Jones <pjones at redhat.com>
---
 setup.py | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/setup.py b/setup.py
index 35a300d..45246cd 100644
--- a/setup.py
+++ b/setup.py
@@ -2,12 +2,45 @@
 # pylint: disable=interruptible-system-call
 
 from distutils.core import setup
+from distutils import filelist
 import subprocess
 import sys
 import glob
 import os
 import re
 
+# this is copied straight from distutils.filelist.findall , but with os.stat()
+# replaced with os.lstat(), so S_ISLNK() can actually tell us something.
+def findall(dirname = os.curdir):
+    from stat import ST_MODE, S_ISREG, S_ISDIR, S_ISLNK
+
+    file_list = []
+    stack = [dirname]
+    pop = stack.pop
+    push = stack.append
+
+    while stack:
+        dirname = pop()
+        names = os.listdir(dirname)
+
+        for name in names:
+            if dirname != os.curdir:        # avoid the dreaded "./" syndrome
+                fullname = os.path.join(dirname, name)
+            else:
+                fullname = name
+
+            # Avoid excess stat calls -- just one will do, thank you!
+            stat = os.lstat(fullname)
+            mode = stat[ST_MODE]
+            if S_ISREG(mode):
+                file_list.append(fullname)
+            elif S_ISDIR(mode) and not S_ISLNK(mode):
+                push(fullname)
+
+    return file_list
+
+filelist.findall = findall
+
 AM_RE = r'(^.. automodule::.+?(?P<mo>^\s+?:member-order:.+?\n)?.+?:\n)\n(?(mo)NEVER)'
 
 def generate_api_docs():


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/901cac95faa7235105e331d668e34144bdea7be0


More information about the anaconda-patches mailing list