[diffoscope] 02/03: Move get_compressed_content_name to under Archive class.
Chris Lamb
chris at chris-lamb.co.uk
Sun Mar 19 23:57:56 CET 2017
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch experimental
in repository diffoscope.
commit 96708b82f9966de2c09372aa81dc9aa33337deb1
Author: Chris Lamb <lamby at debian.org>
Date: Sun Mar 19 22:45:00 2017 +0000
Move get_compressed_content_name to under Archive class.
Signed-off-by: Chris Lamb <lamby at debian.org>
---
diffoscope/comparators/bzip2.py | 3 +--
diffoscope/comparators/dex.py | 3 +--
diffoscope/comparators/gzip.py | 3 +--
diffoscope/comparators/rust.py | 3 +--
diffoscope/comparators/utils/archive.py | 9 +++++++++
diffoscope/comparators/utils/filenames.py | 29 -----------------------------
diffoscope/comparators/xz.py | 3 +--
7 files changed, 14 insertions(+), 39 deletions(-)
diff --git a/diffoscope/comparators/bzip2.py b/diffoscope/comparators/bzip2.py
index d76a29d..1923e0a 100644
--- a/diffoscope/comparators/bzip2.py
+++ b/diffoscope/comparators/bzip2.py
@@ -27,7 +27,6 @@ from diffoscope.tools import tool_required
from .utils.file import File
from .utils.archive import Archive
-from .utils.filenames import get_compressed_content_name
logger = logging.getLogger(__name__)
@@ -43,7 +42,7 @@ class Bzip2Container(Archive):
return collections.OrderedDict({'bzip2-content': self.get_member(self.get_member_names()[0])})
def get_member_names(self):
- return [get_compressed_content_name(self, '.bz2')]
+ return [self.get_compressed_content_name('.bz2')]
@tool_required('bzip2')
def extract(self, member_name, dest_dir):
diff --git a/diffoscope/comparators/dex.py b/diffoscope/comparators/dex.py
index 165fe98..bd393cd 100644
--- a/diffoscope/comparators/dex.py
+++ b/diffoscope/comparators/dex.py
@@ -27,7 +27,6 @@ from diffoscope.tools import tool_required
from .utils.file import File
from .utils.archive import Archive
-from .utils.filenames import get_compressed_content_name
logger = logging.getLogger(__name__)
@@ -47,7 +46,7 @@ class DexContainer(Archive):
return collections.OrderedDict({'dex-content': self.get_member(self.get_member_names()[0])})
def get_member_names(self):
- return [get_compressed_content_name(self, '.dex') + '.jar']
+ return [self.get_compressed_content_name('.dex') + '.jar']
@tool_required('enjarify')
def extract(self, member_name, dest_dir):
diff --git a/diffoscope/comparators/gzip.py b/diffoscope/comparators/gzip.py
index 1111a9c..4eda027 100644
--- a/diffoscope/comparators/gzip.py
+++ b/diffoscope/comparators/gzip.py
@@ -29,7 +29,6 @@ from diffoscope.difference import Difference
from .utils.file import File
from .utils.archive import Archive
-from .utils.filenames import get_compressed_content_name
logger = logging.getLogger(__name__)
@@ -45,7 +44,7 @@ class GzipContainer(Archive):
return collections.OrderedDict({'gzip-content': self.get_member(self.get_member_names()[0])})
def get_member_names(self):
- return [get_compressed_content_name(self, '.gz')]
+ return [self.get_compressed_content_name('.gz')]
@tool_required('gzip')
def extract(self, member_name, dest_dir):
diff --git a/diffoscope/comparators/rust.py b/diffoscope/comparators/rust.py
index 1b8ac9b..475fe1e 100644
--- a/diffoscope/comparators/rust.py
+++ b/diffoscope/comparators/rust.py
@@ -26,7 +26,6 @@ import collections
from diffoscope.difference import Difference
from .utils.archive import Archive
-from .utils.filenames import get_compressed_content_name
RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET = 15
RLIB_BYTECODE_OBJECT_V1_DATA_OFFSET = 23
@@ -46,7 +45,7 @@ class RustObjectContainer(Archive):
return collections.OrderedDict({'deflate-content': self.get_member(self.get_member_names()[0])})
def get_member_names(self):
- return [get_compressed_content_name(self, '.deflate')]
+ return [self.get_compressed_content_name('.deflate')]
def extract(self, member_name, dest_dir):
dest_path = os.path.join(dest_dir, member_name)
diff --git a/diffoscope/comparators/utils/archive.py b/diffoscope/comparators/utils/archive.py
index 33346dd..00ee6a6 100644
--- a/diffoscope/comparators/utils/archive.py
+++ b/diffoscope/comparators/utils/archive.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
+import os
import abc
import logging
@@ -70,6 +71,14 @@ class Archive(Container, metaclass=abc.ABCMeta):
def get_member(self, member_name):
return ArchiveMember(self, member_name)
+ def get_compressed_content_name(self, expected_extension):
+ basename = os.path.basename(self.source.path)
+
+ if not basename.endswith(expected_extension):
+ return "%s-content" % basename
+
+ return basename[:-len(expected_extension)]
+
class ArchiveMember(File):
def __init__(self, container, member_name):
diff --git a/diffoscope/comparators/utils/filenames.py b/diffoscope/comparators/utils/filenames.py
deleted file mode 100644
index 3f173e2..0000000
--- a/diffoscope/comparators/utils/filenames.py
+++ /dev/null
@@ -1,29 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# diffoscope: in-depth comparison of files, archives, and directories
-#
-# Copyright © 2016 Chris Lamb <lamby at debian.org>
-#
-# diffoscope is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# diffoscope is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
-
-import os
-
-
-def get_compressed_content_name(archive, expected_extension):
- basename = os.path.basename(archive.source.path)
-
- if not basename.endswith(expected_extension):
- return "%s-content" % basename
-
- return basename[:-len(expected_extension)]
diff --git a/diffoscope/comparators/xz.py b/diffoscope/comparators/xz.py
index edb496d..ab1d89c 100644
--- a/diffoscope/comparators/xz.py
+++ b/diffoscope/comparators/xz.py
@@ -27,7 +27,6 @@ from diffoscope.tools import tool_required
from .utils.file import File
from .utils.archive import Archive
-from .utils.filenames import get_compressed_content_name
logger = logging.getLogger(__name__)
@@ -43,7 +42,7 @@ class XzContainer(Archive):
return collections.OrderedDict({'xz-content': self.get_member(self.get_member_names()[0])})
def get_member_names(self):
- return [get_compressed_content_name(self, '.xz')]
+ return [self.get_compressed_content_name('.xz')]
@tool_required('xz')
def extract(self, member_name, dest_dir):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list