[diffoscope] 01/02: Replace calling find by using os.walk in directory comparator
Jérémy Bobbio
lunar at moszumanska.debian.org
Fri Dec 18 11:45:27 CET 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository diffoscope.
commit 2cf25c6ea67674893dd3563b32ad8a18552dbd6d
Author: Jérémy Bobbio <lunar at debian.org>
Date: Fri Dec 18 11:36:56 2015 +0100
Replace calling find by using os.walk in directory comparator
`find $DIR -printf %P` does not work with FreeBSD find (and probably others).
Let's replace it with a small function using Python's os.walk.
---
diffoscope/comparators/directory.py | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/diffoscope/comparators/directory.py b/diffoscope/comparators/directory.py
index cfabff8..381a2ae 100644
--- a/diffoscope/comparators/directory.py
+++ b/diffoscope/comparators/directory.py
@@ -18,6 +18,7 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
from contextlib import contextmanager
+import os
import os.path
import re
import subprocess
@@ -28,10 +29,13 @@ from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.utils import Container, Command
-class FindAll(Command):
- @tool_required('find')
- def cmdline(self):
- return ['find', self.path, '-printf', '%P\n']
+def list_files(path):
+ path = os.path.realpath(path)
+ all_files = []
+ for root, dirs, names in os.walk(path):
+ all_files.extend([os.path.join(root[len(path) + 1:], dir) for dir in dirs])
+ all_files.extend([os.path.join(root[len(path) + 1:], name) for name in names])
+ return all_files
class Stat(Command):
@@ -123,9 +127,11 @@ class FilesystemDirectory(object):
def compare(self, other, source=None):
differences = []
try:
- find_diff = Difference.from_command(FindAll, self.path, other.path)
- if find_diff:
- differences.append(find_diff)
+ listing_diff = Difference.from_text('\n'.join(list_files(self.path)),
+ '\n'.join(list_files(other.path)),
+ self.path, other.path, source='file list')
+ if listing_diff:
+ differences.append(listing_diff)
except RequiredToolNotFound:
logger.info("Unable to find 'getfacl'.")
differences.extend(compare_meta(self.name, other.name))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list