[diffoscope] 05/10: All files can now belong to a container

Jérémy Bobbio lunar at moszumanska.debian.org
Wed Jan 20 16:11:44 CET 2016


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

lunar pushed a commit to branch master
in repository diffoscope.

commit a7c07921a644da0e16e3002d459f1336a8c71d1c
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Wed Jan 20 13:07:57 2016 +0000

    All files can now belong to a container
    
    Which container a file belongs to can be useful information in other contexts
    than just archives. We've seen it for ELF sections, and we can keep it
    for directories.
    
    This will help us implement cross-file analysis.
---
 diffoscope/comparators/binary.py    | 10 +++++++++-
 diffoscope/comparators/directory.py |  2 +-
 diffoscope/comparators/elf.py       |  4 ++--
 diffoscope/comparators/utils.py     |  6 +-----
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index 91dd671..9663214 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -87,6 +87,9 @@ class File(object, metaclass=ABCMeta):
                 self._mimedb_encoding = magic.Magic(mime_encoding=True)
             return self._mimedb_encoding.from_file(path).decode('utf-8')
 
+    def __init__(self, container=None):
+        self._container = container
+
     def __repr__(self):
         return '<%s %s>' % (self.__class__, self.name)
 
@@ -111,6 +114,10 @@ class File(object, metaclass=ABCMeta):
         return self._name
 
     @property
+    def container(self):
+        return self._container
+
+    @property
     def as_container(self):
         if not hasattr(self.__class__, 'CONTAINER_CLASS'):
             if hasattr(self, '_other_file'):
@@ -227,7 +234,8 @@ class File(object, metaclass=ABCMeta):
 
 
 class FilesystemFile(File):
-    def __init__(self, path):
+    def __init__(self, path, container=None):
+        super().__init__(container=container)
         self._name = path
 
     @property
diff --git a/diffoscope/comparators/directory.py b/diffoscope/comparators/directory.py
index 63ae4a7..71ba9ad 100644
--- a/diffoscope/comparators/directory.py
+++ b/diffoscope/comparators/directory.py
@@ -173,4 +173,4 @@ class DirectoryContainer(Container):
         return names
 
     def get_member(self, member_name):
-        return diffoscope.comparators.specialize(FilesystemFile(os.path.join(self.source.path, member_name)))
+        return diffoscope.comparators.specialize(FilesystemFile(os.path.join(self.source.path, member_name), container=self))
diff --git a/diffoscope/comparators/elf.py b/diffoscope/comparators/elf.py
index d0ac2a9..bb1a9d5 100644
--- a/diffoscope/comparators/elf.py
+++ b/diffoscope/comparators/elf.py
@@ -204,7 +204,7 @@ def _should_skip_section(name, type):
 
 class ElfSection(File):
     def __init__(self, elf_container, member_name):
-        self._elf_container = elf_container
+        super().__init__(container=elf_container)
         self._name = member_name
 
     @property
@@ -213,7 +213,7 @@ class ElfSection(File):
 
     @property
     def path(self):
-        return self._elf_container.source.path
+        return self.container.source.path
 
     def cleanup(self):
         pass
diff --git a/diffoscope/comparators/utils.py b/diffoscope/comparators/utils.py
index ea1b274..94afd23 100644
--- a/diffoscope/comparators/utils.py
+++ b/diffoscope/comparators/utils.py
@@ -236,16 +236,12 @@ class NonExistingContainer(Container):
 
 class ArchiveMember(File):
     def __init__(self, container, member_name):
-        self._container = container
+        super().__init__(container=container)
         self._name = member_name
         self._temp_dir = None
         self._path = None
 
     @property
-    def container(self):
-        return self._container
-
-    @property
     def path(self):
         if self._path is None:
             logger.debug('unpacking %s', self._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