[diffoscope] 01/01: comparators.debian: Tidy formatting, etc to make it more VCS-friendly.

Chris Lamb chris at chris-lamb.co.uk
Tue Feb 7 04:54:17 CET 2017


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

lamby pushed a commit to branch master
in repository diffoscope.

commit 26bae910c07c718e768404445b65a81bcaf0925b
Author: Chris Lamb <lamby at debian.org>
Date:   Tue Feb 7 16:53:53 2017 +1300

    comparators.debian: Tidy formatting, etc to make it more VCS-friendly.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/comparators/debian.py | 74 +++++++++++++++++++++++++++++++---------
 1 file changed, 58 insertions(+), 16 deletions(-)

diff --git a/diffoscope/comparators/debian.py b/diffoscope/comparators/debian.py
index c3a1ea4..d3e47b1 100644
--- a/diffoscope/comparators/debian.py
+++ b/diffoscope/comparators/debian.py
@@ -114,24 +114,41 @@ class DebControlFile(File):
         for field in sorted(set(self.deb822.keys()).union(set(other.deb822.keys()))):
             if field.startswith('Checksums-') or field == 'Files':
                 continue
-            my_value = ''
+
+            my_value = ""
             if field in self.deb822:
                 my_value = self.deb822.get_as_string(field).lstrip()
-            other_value = ''
+
+            other_value = ""
             if field in other.deb822:
                 other_value = other.deb822.get_as_string(field).lstrip()
+
             differences.append(Difference.from_text(
-                                   my_value, other_value,
-                                   self.path, other.path, source=field))
-        # compare Files as string
+                my_value,
+                other_value,
+                self.path,
+                other.path,
+                source=field,
+            ))
+
+        # Compare Files as string
         if self.deb822.get('Files'):
-            differences.append(Difference.from_text(self.deb822.get_as_string('Files'),
-                                                    other.deb822.get_as_string('Files'),
-                                                    self.path, other.path, source='Files'))
+            differences.append(Difference.from_text(
+                self.deb822.get_as_string('Files'),
+                other.deb822.get_as_string('Files'),
+                self.path,
+                other.path,
+                source='Files',
+            ))
         else:
-            differences.append(Difference.from_text(self.deb822.get_as_string('Checksums-Sha256'),
-                                                    other.deb822.get_as_string('Checksums-Sha256'),
-                                                    self.path, other.path, source='Checksums-Sha256'))
+            differences.append(Difference.from_text(
+                self.deb822.get_as_string('Checksums-Sha256'),
+                other.deb822.get_as_string('Checksums-Sha256'),
+                self.path,
+                other.path,
+                source='Checksums-Sha256',
+            ))
+
         return differences
 
 class DotChangesFile(DebControlFile):
@@ -141,24 +158,36 @@ class DotChangesFile(DebControlFile):
     def recognizes(file):
         if not DotChangesFile.RE_FILE_EXTENSION.search(file.name):
             return False
+
         changes = Changes(filename=file.path)
         try:
             changes.validate(check_signature=False)
         except FileNotFoundError:
             return False
+
         file._deb822 = changes
+
         return True
 
     def compare(self, other, source=None):
         differences = super().compare(other, source)
+
         if differences is None:
             return None
-        files_identical = all([x == y for x, y in zip(self.deb822.get('Files'), other.deb822.get('Files')) if not x['name'].endswith('.buildinfo')])
-        if files_identical and len(differences.details) == 1 and differences.details[0].source1 == 'Files':
-            logger.warning('Ignoring buildinfo file differences')
+
+        files_identical = all(
+            x == y
+            for x, y in zip(self.deb822.get('Files'), other.deb822.get('Files'))
+            if not x['name'].endswith('.buildinfo')
+        )
+
+        if files_identical and \
+                len(differences.details) == 1 and \
+                differences.details[0].source1 == 'Files':
+            logger.warning("Ignoring buildinfo file differences")
             return None
-        else:
-            return differences
+
+        return differences
 
 
 class DotDscFile(DebControlFile):
@@ -168,20 +197,26 @@ class DotDscFile(DebControlFile):
     def recognizes(file):
         if not DotDscFile.RE_FILE_EXTENSION.search(file.name):
             return False
+
         with open(file.path, 'rb') as f:
             dsc = Dsc(f)
+
             for d in dsc.get('Files'):
                 md5 = hashlib.md5()
+
                 # XXX: this will not work for containers
                 in_dsc_path = os.path.join(os.path.dirname(file.path), d['Name'])
                 if not os.path.exists(in_dsc_path):
                     return False
+
                 with open(in_dsc_path, 'rb') as f:
                     for buf in iter(functools.partial(f.read, 32768), b''):
                         md5.update(buf)
                 if md5.hexdigest() != d['md5sum']:
                     return False
+
             file._deb822 = dsc
+
         return True
 
 class DotBuildinfoContainer(DebControlContainer):
@@ -210,21 +245,28 @@ class DotBuildinfoFile(DebControlFile):
     def recognizes(file):
         if not DotBuildinfoFile.RE_FILE_EXTENSION.search(file.name):
             return False
+
         with open(file.path, 'rb') as f:
             # We can parse .buildinfo just like .dsc
             buildinfo = Dsc(f)
+
         if not 'Checksums-Sha256' in buildinfo:
             return False
+
         for d in buildinfo.get('Checksums-Sha256'):
             sha256 = hashlib.sha256()
+
             # XXX: this will not work for containers
             in_buildinfo_path = os.path.join(os.path.dirname(file.path), d['Name'])
             if not os.path.exists(in_buildinfo_path):
                 return False
+
             with open(in_buildinfo_path, 'rb') as f:
                 for buf in iter(functools.partial(f.read, 32768), b''):
                     sha256.update(buf)
             if sha256.hexdigest() != d['sha256']:
                 return False
+
         file._deb822 = buildinfo
+
         return True

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


More information about the diffoscope mailing list