[diffoscope] 01/02: comparators/libarchive: Factor out isdir, etc switch statement.

Chris Lamb chris at chris-lamb.co.uk
Mon Dec 26 14:14:01 CET 2016


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit f3367326802e97f2059a1415d7a68006945653ca
Author: Chris Lamb <lamby at debian.org>
Date:   Mon Dec 26 10:51:46 2016 +0000

    comparators/libarchive: Factor out isdir, etc switch statement.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/comparators/libarchive.py | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/diffoscope/comparators/libarchive.py b/diffoscope/comparators/libarchive.py
index 2a4f007..d1755dc 100644
--- a/diffoscope/comparators/libarchive.py
+++ b/diffoscope/comparators/libarchive.py
@@ -188,25 +188,20 @@ class LibarchiveContainer(Archive):
         with libarchive.file_reader(self.source.path) as archive:
             for entry in archive:
                 if entry.pathname == member_name:
-                    if entry.isdir:
-                        return LibarchiveDirectory(self, entry)
-                    elif entry.issym:
-                        return LibarchiveSymlink(self, entry)
-                    elif entry.isblk or entry.ischr:
-                        return LibarchiveDevice(self, entry)
-                    else:
-                        return LibarchiveMember(self, entry)
+                    return self.get_subclass(entry)
         raise KeyError('%s not found in archive', member_name)
 
     def get_all_members(self):
         with libarchive.file_reader(self.source.path) as archive:
             for entry in archive:
-                p = entry.pathname
-                if entry.isdir:
-                    yield p, LibarchiveDirectory(self, entry)
-                elif entry.issym:
-                    yield p, LibarchiveSymlink(self, entry)
-                elif entry.isblk or entry.ischr:
-                    yield p, LibarchiveDevice(self, entry)
-                else:
-                    yield p, LibarchiveMember(self, entry)
+                yield entry.pathname, self.get_subclass(entry)
+
+    def get_subclass(self, entry):
+        if entry.isdir:
+            return LibarchiveDirectory(self, entry)
+        elif entry.issym:
+            return LibarchiveSymlink(self, entry)
+        elif entry.isblk or entry.ischr:
+            return LibarchiveDevice(self, entry)
+
+        return LibarchiveMember(self, entry)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list