[Reproducible-commits] [diffoscope] 09/13: Add support for .dsc files
Jérémy Bobbio
lunar at moszumanska.debian.org
Thu Oct 15 16:04:35 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository diffoscope.
commit dbb474e0e804f7c4ae68dcdf3323fd8345ba80b4
Author: Jérémy Bobbio <lunar at debian.org>
Date: Thu Oct 15 12:23:16 2015 +0000
Add support for .dsc files
Closes: #800359
---
diffoscope/comparators/__init__.py | 3 +-
diffoscope/comparators/binary.py | 4 +--
diffoscope/comparators/debian.py | 74 ++++++++++++++++++++++----------------
tests/comparators/test_debian.py | 64 +++++++++++++++++++++++++++------
4 files changed, 102 insertions(+), 43 deletions(-)
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index dcde9dc..d7d8d2e 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -34,7 +34,7 @@ from diffoscope.comparators.java import ClassFile
from diffoscope.comparators.cbfs import CbfsFile
from diffoscope.comparators.cpio import CpioFile
from diffoscope.comparators.deb import DebFile, Md5sumsFile, DebDataTarFile
-from diffoscope.comparators.debian import DotChangesFile
+from diffoscope.comparators.debian import DotChangesFile, DotDscFile
from diffoscope.comparators.device import Device
from diffoscope.comparators.directory import Directory, compare_directories
from diffoscope.comparators.elf import ElfFile, StaticLibFile
@@ -114,6 +114,7 @@ FILE_CLASSES = (
Symlink,
Device,
DotChangesFile,
+ DotDscFile,
Md5sumsFile,
DebDataTarFile,
TextFile,
diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index a4eb0ed..52defb0 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -295,9 +295,9 @@ class NonExistingFile(File):
def magic_file_type(self):
return self._other_file.magic_file_type
- # Be nice to .changes comparisons
+ # Be nice to .changes and .dsc comparisons
@property
- def changes(self):
+ def deb822(self):
class DummyChanges(dict):
get_as_string = lambda self, _: ''
return DummyChanges(Files=[], Version='')
diff --git a/diffoscope/comparators/debian.py b/diffoscope/comparators/debian.py
index e431ef2..d315560 100644
--- a/diffoscope/comparators/debian.py
+++ b/diffoscope/comparators/debian.py
@@ -20,6 +20,7 @@
from contextlib import contextmanager
import os.path
import re
+from debian.deb822 import Dsc
from diffoscope.changes import Changes
import diffoscope.comparators
from diffoscope.comparators.binary import File, NonExistingFile, needs_content
@@ -36,7 +37,7 @@ DOT_CHANGES_FIELDS = [
]
-class DotChangesMember(File):
+class DebControlMember(File):
def __init__(self, container, member_name):
self._container = container
self._name = member_name
@@ -70,10 +71,10 @@ class DotChangesMember(File):
return False
-class DotChangesContainer(Container):
+class DebControlContainer(Container):
@staticmethod
def get_version_trimming_re(dcc):
- version = dcc.source.changes.get('Version')
+ version = dcc.source.deb822.get('Version')
# remove the epoch as it's not in the filename
version = re.sub(r'^\d+:', '', version)
if '-' in version:
@@ -84,7 +85,7 @@ class DotChangesContainer(Container):
@contextmanager
def open(self):
- self._version_re = DotChangesContainer.get_version_trimming_re(self)
+ self._version_re = DebControlContainer.get_version_trimming_re(self)
yield self
del self._version_re
@@ -92,54 +93,67 @@ class DotChangesContainer(Container):
return {self._trim_version_number(name): self.get_member(name) for name in self.get_member_names()}
def get_member_names(self):
- return [d['name'] for d in self.source.changes.get('Files')]
+ return [d['name'] for d in self.source.deb822.get('Files')]
def get_member(self, member_name):
- return DotChangesMember(self, member_name)
+ return DebControlMember(self, member_name)
def _trim_version_number(self, name):
return self._version_re.sub('', name)
-class DotChangesFile(File):
- RE_FILE_EXTENSION = re.compile(r'\.changes$')
-
- @staticmethod
- def recognizes(file):
- if not DotChangesFile.RE_FILE_EXTENSION.search(file.name):
- return False
- with file.get_content():
- changes = Changes(filename=file.path)
- changes.validate(check_signature=False)
- file._changes = changes
- return True
-
+class DebControlFile(File):
@property
- def changes(self):
- return self._changes
+ def deb822(self):
+ return self._deb822
@needs_content
def compare_details(self, other, source=None):
differences = []
- for field in sorted(set(self.changes.keys()).union(set(other.changes.keys()))):
+ for field in sorted(set(self.deb822.keys()).union(set(other.deb822.keys()))):
if field.startswith('Checksums-') or field == 'Files':
continue
my_value = ''
- if field in self.changes:
- my_value = self.changes.get_as_string(field).lstrip()
+ if field in self.deb822:
+ my_value = self.deb822.get_as_string(field).lstrip()
other_value = ''
- if field in other.changes:
- other_value = other.changes.get_as_string(field).lstrip()
+ 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
- differences.append(Difference.from_text(self.changes.get_as_string('Files'),
- other.changes.get_as_string('Files'),
+ differences.append(Difference.from_text(self.deb822.get_as_string('Files'),
+ other.deb822.get_as_string('Files'),
self.path, other.path, source='Files'))
- with DotChangesContainer(self).open() as my_container, \
- DotChangesContainer(other).open() as other_container:
+ with DebControlContainer(self).open() as my_container, \
+ DebControlContainer(other).open() as other_container:
differences.extend(my_container.compare(other_container))
return differences
+
+class DotChangesFile(DebControlFile):
+ RE_FILE_EXTENSION = re.compile(r'\.changes$')
+
+ @staticmethod
+ def recognizes(file):
+ if not DotChangesFile.RE_FILE_EXTENSION.search(file.name):
+ return False
+ with file.get_content():
+ changes = Changes(filename=file.path)
+ changes.validate(check_signature=False)
+ file._deb822 = changes
+ return True
+
+class DotDscFile(DebControlFile):
+ RE_FILE_EXTENSION = re.compile(r'\.dsc$')
+
+ @staticmethod
+ def recognizes(file):
+ if not DotDscFile.RE_FILE_EXTENSION.search(file.name):
+ return False
+ with file.get_content():
+ with open(file.path, 'rb') as f:
+ file._deb822 = Dsc(f)
+ return True
diff --git a/tests/comparators/test_debian.py b/tests/comparators/test_debian.py
index 4e33e6b..f46e344 100644
--- a/tests/comparators/test_debian.py
+++ b/tests/comparators/test_debian.py
@@ -22,7 +22,7 @@ import shutil
import pytest
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from diffoscope.comparators.debian import DotChangesFile
+from diffoscope.comparators.debian import DotChangesFile, DotDscFile
from diffoscope.config import Config
from diffoscope.presenters.text import output_text
@@ -49,30 +49,74 @@ def dot_changes2(tmpdir):
shutil.copy(TEST_DEB_FILE2_PATH, str(tmpdir.join('b/test_1_all.deb')))
return specialize(FilesystemFile(dot_changes_path))
-def test_identification(dot_changes1):
+def test_dot_changes_identification(dot_changes1):
assert isinstance(dot_changes1, DotChangesFile)
-def test_no_differences(dot_changes1):
+def test_dot_changes_no_differences(dot_changes1):
difference = dot_changes1.compare(dot_changes1)
assert difference is None
@pytest.fixture
-def differences(dot_changes1, dot_changes2):
+def dot_changes_differences(dot_changes1, dot_changes2):
difference = dot_changes1.compare(dot_changes2)
output_text(difference, print_func=print)
return difference.details
-def test_description(differences):
- assert differences[0]
+def test_dot_changes_description(dot_changes_differences):
+ assert dot_changes_differences[0]
expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/dot_changes_description_expected_diff')).read()
- assert differences[0].unified_diff == expected_diff
+ assert dot_changes_differences[0].unified_diff == expected_diff
-def test_internal_diff(differences):
- assert differences[2].source1 == 'test_1_all.deb'
+def test_dot_changes_internal_diff(dot_changes_differences):
+ assert dot_changes_differences[2].source1 == 'test_1_all.deb'
-def test_compare_non_existing(monkeypatch, dot_changes1):
+def test_dot_changes_compare_non_existing(monkeypatch, dot_changes1):
monkeypatch.setattr(Config.general, 'new_file', True)
difference = dot_changes1.compare(NonExistingFile('/nonexisting', dot_changes1))
output_text(difference, print_func=print)
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
+
+TEST_DOT_DSC_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.dsc')
+TEST_DOT_DSC_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.dsc')
+TEST_DEB_SRC1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.debsrc.tar.gz')
+TEST_DEB_SRC2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.debsrc.tar.gz')
+
+ at pytest.fixture
+def dot_dsc1(tmpdir):
+ tmpdir.mkdir('a')
+ dot_dsc_path = str(tmpdir.join('a/test_1.dsc'))
+ shutil.copy(TEST_DOT_DSC_FILE1_PATH, dot_dsc_path)
+ shutil.copy(TEST_DEB_SRC1_PATH, str(tmpdir.join('a/test_1.tar.gz')))
+ return specialize(FilesystemFile(dot_dsc_path))
+
+ at pytest.fixture
+def dot_dsc2(tmpdir):
+ tmpdir.mkdir('b')
+ dot_dsc_path = str(tmpdir.join('b/test_1.dsc'))
+ shutil.copy(TEST_DOT_DSC_FILE2_PATH, dot_dsc_path)
+ shutil.copy(TEST_DEB_SRC2_PATH, str(tmpdir.join('b/test_1.tar.gz')))
+ return specialize(FilesystemFile(dot_dsc_path))
+
+def test_dot_dsc_identification(dot_dsc1):
+ assert isinstance(dot_dsc1, DotDscFile)
+
+def test_dot_dsc_no_differences(dot_dsc1):
+ difference = dot_dsc1.compare(dot_dsc1)
+ assert difference is None
+
+ at pytest.fixture
+def dot_dsc_differences(dot_dsc1, dot_dsc2):
+ difference = dot_dsc1.compare(dot_dsc2)
+ output_text(difference, print_func=print)
+ return difference.details
+
+def test_dot_dsc_internal_diff(dot_dsc_differences):
+ assert dot_dsc_differences[1].source1 == 'test_1.tar.gz'
+
+def test_dot_dsc_compare_non_existing(monkeypatch, dot_dsc1):
+ monkeypatch.setattr(Config.general, 'new_file', True)
+ difference = dot_dsc1.compare(NonExistingFile('/nonexisting', dot_dsc1))
+ output_text(difference, print_func=print)
+ assert difference.source2 == '/nonexisting'
+ assert difference.details[-1].source2 == '/dev/null'
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list