Skip to content

Instantly share code, notes, and snippets.

@satyamz
Created August 24, 2016 04:51
Show Gist options
  • Save satyamz/66ccd98e94d47f7ef39bffc650f067d2 to your computer and use it in GitHub Desktop.
Save satyamz/66ccd98e94d47f7ef39bffc650f067d2 to your computer and use it in GitHub Desktop.
Add new command line option for hiding gzip metadata from diffoscope output
diff --git a/diffoscope/comparators/gzip.py b/diffoscope/comparators/gzip.py
index fff03e5..876418f 100644
--- a/diffoscope/comparators/gzip.py
+++ b/diffoscope/comparators/gzip.py
@@ -25,6 +25,7 @@ import collections
from diffoscope import logger, tool_required
from diffoscope.difference import Difference
from diffoscope.comparators.utils import Archive, get_compressed_content_name
+from diffoscope.config import Config
class GzipContainer(Archive):
@@ -61,3 +62,11 @@ class GzipFile(object):
def compare_details(self, other, source=None):
return [Difference.from_text(self.magic_file_type, other.magic_file_type, self, other, source='metadata')]
+
+ def compare(self, other, source=None):
+ differences = super().compare(other, source)
+ if differences is None:
+ return None
+ if Config.general.hide_profile == 'metadata' and len(differences.details) == 1 and differences.details[0].source1 == 'metadata':
+ return None
+ return differences
diff --git a/diffoscope/config.py b/diffoscope/config.py
index ff65558..e0387ce 100644
--- a/diffoscope/config.py
+++ b/diffoscope/config.py
@@ -33,6 +33,7 @@ class Config(object):
self._separate_file_diff_size = 200 * 2 ** 10 # 200kB
self._fuzzy_threshold = 60
self._new_file = False
+ self._hide_profile = None
@classproperty
def general(cls):
@@ -87,3 +88,11 @@ class Config(object):
@new_file.setter
def new_file(self, value):
self._new_file = value
+
+ @property
+ def hide_profile(self):
+ return self._hide_profile
+
+ @hide_profile.setter
+ def hide_profile(self, value):
+ self._hide_profile = value
diff --git a/diffoscope/main.py b/diffoscope/main.py
index 7cd234a..81140b8 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -102,6 +102,8 @@ def create_parser():
help='link to the jquery url, with --html-dir. Specify “disable” to disable JavaScript. When omitted diffoscope will try to create a symlink to a system installation. Known locations: %s' % ', '.join(JQUERY_SYSTEM_LOCATIONS))
parser.add_argument('path1', help='first file or directory to compare')
parser.add_argument('path2', help='second file or directory to compare')
+ parser.add_argument('--hide', dest='hide_profile', action='store', choices=['metadata'],
+ help='Switch to hide profiles from output')
if not tlsh:
parser.epilog = 'File renaming detection based on fuzzy-matching is currently disabled. It can be enabled by installing the “tlsh” module available at https://github.com/trendmicro/tlsh'
if argcomplete:
@@ -170,6 +172,7 @@ def run_diffoscope(parsed_args):
Config.general.separate_file_diff_size = parsed_args.separate_file_diff_size
Config.general.fuzzy_threshold = parsed_args.fuzzy_threshold
Config.general.new_file = parsed_args.new_file
+ Config.general.hide_profile = parsed_args.hide_profile
if parsed_args.debug:
logger.setLevel(logging.DEBUG)
set_locale()
satyam@satyamz:~/debian/satyamz-guest/project/reproducible-builds/59/complete/diffoscope/bin$ git diff
diff --git a/diffoscope/comparators/gzip.py b/diffoscope/comparators/gzip.py
index fff03e5..74711e4 100644
--- a/diffoscope/comparators/gzip.py
+++ b/diffoscope/comparators/gzip.py
@@ -25,6 +25,7 @@ import collections
from diffoscope import logger, tool_required
from diffoscope.difference import Difference
from diffoscope.comparators.utils import Archive, get_compressed_content_name
+from diffoscope.config import Config
class GzipContainer(Archive):
@@ -61,3 +62,11 @@ class GzipFile(object):
def compare_details(self, other, source=None):
return [Difference.from_text(self.magic_file_type, other.magic_file_type, self, other, source='metadata')]
+
+ def compare(self, other, source=None):
+ differences = super().compare(other, source)
+ if differences is None:
+ return None
+ if Config.general.hide_profile == 'gzip-metadata' and differences.details[0].source1 == 'metadata':
+ return None
+ return differences
diff --git a/diffoscope/config.py b/diffoscope/config.py
index ff65558..e0387ce 100644
--- a/diffoscope/config.py
+++ b/diffoscope/config.py
@@ -33,6 +33,7 @@ class Config(object):
self._separate_file_diff_size = 200 * 2 ** 10 # 200kB
self._fuzzy_threshold = 60
self._new_file = False
+ self._hide_profile = None
@classproperty
def general(cls):
@@ -87,3 +88,11 @@ class Config(object):
@new_file.setter
def new_file(self, value):
self._new_file = value
+
+ @property
+ def hide_profile(self):
+ return self._hide_profile
+
+ @hide_profile.setter
+ def hide_profile(self, value):
+ self._hide_profile = value
diff --git a/diffoscope/main.py b/diffoscope/main.py
index 7cd234a..35a8683 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -102,6 +102,8 @@ def create_parser():
help='link to the jquery url, with --html-dir. Specify “disable” to disable JavaScript. When omitted diffoscope will try to create a symlink to a system installation. Known locations: %s' % ', '.join(JQUERY_SYSTEM_LOCATIONS))
parser.add_argument('path1', help='first file or directory to compare')
parser.add_argument('path2', help='second file or directory to compare')
+ parser.add_argument('--hide', dest='hide_profile', action='store', choices=['gzip-metadata'],
+ help='Switch to hide profiles from output')
if not tlsh:
parser.epilog = 'File renaming detection based on fuzzy-matching is currently disabled. It can be enabled by installing the “tlsh” module available at https://github.com/trendmicro/tlsh'
if argcomplete:
@@ -170,6 +172,7 @@ def run_diffoscope(parsed_args):
Config.general.separate_file_diff_size = parsed_args.separate_file_diff_size
Config.general.fuzzy_threshold = parsed_args.fuzzy_threshold
Config.general.new_file = parsed_args.new_file
+ Config.general.hide_profile = parsed_args.hide_profile
if parsed_args.debug:
logger.setLevel(logging.DEBUG)
set_locale()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment