Commit 356b1886 authored by Chris Lamb's avatar Chris Lamb 💬

Use more-Python logging functions based on __name__, etc.

Signed-off-by: Chris Lamb's avatarChris Lamb <lamby@debian.org>
parent 352a6ada
......@@ -43,12 +43,14 @@ __license__ = 'MIT'
import os.path
import hashlib
import logging
import subprocess
from debian import deb822
from .tools import tool_required
from .logging import logger
logger = logging.getLogger(__name__)
class ChangesFileException(Exception):
......
......@@ -19,15 +19,18 @@
import re
import os.path
import logging
import subprocess
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.tempfiles import get_temporary_directory
from .utils.file import File
from .utils.archive import Archive
logger = logging.getLogger(__name__)
class ApkContainer(Archive):
@property
def path(self):
......
......@@ -19,15 +19,17 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import re
import logging
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.difference import Difference
from .utils.file import File
from .utils.command import Command
from .utils.libarchive import LibarchiveContainer, list_libarchive
logger = logging.getLogger(__name__)
# TODO: this would also be useful for Go archives. Currently those are handled
# by StaticLibFile, but then readelf complains with "Error: Not an ELF file".
......
......@@ -19,16 +19,18 @@
import re
import os.path
import logging
import subprocess
import collections
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from .utils.file import File
from .utils.archive import Archive
from .utils.filenames import get_compressed_content_name
logger = logging.getLogger(__name__)
class Bzip2Container(Archive):
def open_archive(self):
......
......@@ -21,16 +21,18 @@ import io
import os
import re
import struct
import logging
import subprocess
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.difference import Difference
from .utils.file import File
from .utils.archive import Archive
from .utils.command import Command
logger = logging.getLogger(__name__)
class CbfsListing(Command):
def __init__(self, *args, **kwargs):
......
......@@ -18,8 +18,8 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import re
import logging
from diffoscope.logging import logger
from diffoscope.difference import Difference
from .tar import TarContainer
......@@ -33,6 +33,8 @@ try:
except ImportError:
deb822 = None
logger = logging.getLogger(__name__)
# Return a dict with build ids as keys and file as values for all deb in the
# given container
......
......@@ -20,12 +20,12 @@
import re
import os.path
import hashlib
import logging
import functools
import collections
from debian.deb822 import Dsc
from diffoscope.logging import logger
from diffoscope.changes import Changes
from diffoscope.difference import Difference
......@@ -40,6 +40,8 @@ DOT_CHANGES_FIELDS = [
"Changes",
]
logger = logging.getLogger(__name__)
class DebControlMember(File):
def __init__(self, container, member_name):
......
......@@ -19,16 +19,18 @@
import re
import os.path
import logging
import subprocess
import collections
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from .utils.file import File
from .utils.archive import Archive
from .utils.filenames import get_compressed_content_name
logger = logging.getLogger(__name__)
class DexContainer(Archive):
@property
......
......@@ -19,11 +19,11 @@
import os
import re
import logging
import subprocess
from diffoscope.exc import RequiredToolNotFound
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.progress import Progress
from diffoscope.difference import Difference
......@@ -31,6 +31,8 @@ from .binary import FilesystemFile
from .utils.command import Command
from .utils.container import Container
logger = logging.getLogger(__name__)
def list_files(path):
path = os.path.realpath(path)
......
......@@ -19,12 +19,12 @@
import os
import re
import logging
import subprocess
import collections
from diffoscope.exc import OutputParsingError
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.tempfiles import get_named_temporary_file
from diffoscope.difference import Difference
......@@ -51,6 +51,8 @@ DEBUG_SECTION_GROUPS = (
'gdb_index',
)
logger = logging.getLogger(__name__)
class Readelf(Command):
def __init__(self, *args, **kwargs):
......
......@@ -18,10 +18,10 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import re
import logging
import os.path
import collections
from diffoscope.logging import logger
from diffoscope.difference import Difference
from .utils.file import File
......@@ -32,6 +32,8 @@ try:
except ImportError:
guestfs = None
logger = logging.getLogger(__name__)
class FsImageContainer(Archive):
def open_archive(self):
......
......@@ -19,14 +19,16 @@
import io
import re
import logging
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.difference import Difference
from .utils.file import File
from .utils.command import Command
logger = logging.getLogger(__name__)
class Msgunfmt(Command):
CHARSET_RE = re.compile(rb'^"Content-Type: [^;]+; charset=([^\\]+)\\n"$')
......
......@@ -19,16 +19,18 @@
import re
import os.path
import logging
import subprocess
import collections
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.difference import Difference
from .utils.archive import Archive
from .utils.filenames import get_compressed_content_name
logger = logging.getLogger(__name__)
class GzipContainer(Archive):
def open_archive(self):
......
......@@ -19,17 +19,19 @@
import re
import struct
import logging
import platform
import subprocess
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.profiling import profile
from diffoscope.difference import Difference
from .utils.file import File
from .utils.command import Command
logger = logging.getLogger(__name__)
class ShowIface(Command):
@tool_required('ghc')
......
......@@ -18,14 +18,16 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import os
import logging
from diffoscope.config import Config
from diffoscope.logging import logger
from diffoscope.difference import Difference
from .binary import FilesystemFile
from .utils.file import File
logger = logging.getLogger(__name__)
class MissingFile(File):
"""
......
......@@ -21,16 +21,18 @@
import os
import re
import logging
import subprocess
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.profiling import profile
from diffoscope.difference import Difference
from .utils.file import File
from .utils.command import Command
logger = logging.getLogger(__name__)
class Ppudump(Command):
@tool_required('ppudump')
......
......@@ -18,15 +18,17 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import re
import logging
from diffoscope.exc import RequiredToolNotFound
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.difference import Difference
from .text import TextFile
from .utils.command import Command
logger = logging.getLogger(__name__)
class Pstotext(Command):
@tool_required('ps2ascii')
......
......@@ -21,17 +21,19 @@
import io
import rpm
import os.path
import logging
import binascii
import subprocess
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.tempfiles import get_temporary_directory
from diffoscope.difference import Difference
from .rpm_fallback import AbstractRpmFile
from .utils.archive import Archive
logger = logging.getLogger(__name__)
def convert_header_field(io, header):
if isinstance(header, list):
......
......@@ -20,10 +20,10 @@
import zlib
import os.path
import logging
import collections
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.difference import Difference
from .utils.archive import Archive
......@@ -33,6 +33,8 @@ RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET = 15
RLIB_BYTECODE_OBJECT_V1_DATA_OFFSET = 23
ZLIB_DEFAULT_COMPRESSION = b'\x78\x9C'
logger = logging.getLogger(__name__)
class RustObjectContainer(Archive):
def open_archive(self):
......
......@@ -20,11 +20,11 @@
import re
import stat
import logging
import subprocess
import collections
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.difference import Difference
from .utils.file import File
......@@ -34,6 +34,8 @@ from .directory import Directory
from .utils.archive import Archive, ArchiveMember
from .utils.command import Command
logger = logging.getLogger(__name__)
class SquashfsSuperblock(Command):
@tool_required('unsquashfs')
......
......@@ -18,13 +18,15 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import os
import logging
from diffoscope.logging import logger
from diffoscope.tempfiles import get_named_temporary_file
from diffoscope.difference import Difference
from .utils.file import File
logger = logging.getLogger(__name__)
class Symlink(File):
@staticmethod
......
......@@ -18,8 +18,8 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import abc
import logging
from diffoscope.logging import logger
from diffoscope.profiling import profile
from diffoscope.tempfiles import get_temporary_directory
......@@ -28,6 +28,8 @@ from ..missing_file import MissingFile
from .file import File
from .container import Container
logger = logging.getLogger(__name__)
class Archive(Container, metaclass=abc.ABCMeta):
def __new__(cls, source, *args, **kwargs):
......
......@@ -19,10 +19,11 @@
import io
import abc
import logging
import subprocess
import threading
from diffoscope.logging import logger
logger = logging.getLogger(__name__)
class Command(object, metaclass=abc.ABCMeta):
......
......@@ -20,10 +20,10 @@
import io
import os
import sys
import logging
import binascii
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.exc import RequiredToolNotFound
from diffoscope.config import Config
from diffoscope.profiling import profile
......@@ -39,6 +39,8 @@ try:
except ImportError:
tlsh = None
logger = logging.getLogger(__name__)
class Xxd(Command):
@tool_required('xxd')
......
......@@ -18,11 +18,11 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import abc
import logging
import itertools
import collections
from diffoscope.config import Config
from diffoscope.logging import logger
from diffoscope.progress import Progress
from ..missing_file import MissingFile
......@@ -32,6 +32,7 @@ from .specialize import specialize
NO_COMMENT = None
logger = logging.getLogger(__name__)
class Container(object, metaclass=abc.ABCMeta):
......
......@@ -21,11 +21,11 @@ import os
import re
import abc
import magic
import logging
import subprocess
from diffoscope.exc import RequiredToolNotFound, OutputParsingError
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.profiling import profile
from diffoscope.difference import Difference
......@@ -36,6 +36,8 @@ except ImportError:
SMALL_FILE_THRESHOLD = 65536 # 64 kiB
logger = logging.getLogger(__name__)
class File(object, metaclass=abc.ABCMeta):
if hasattr(magic, 'open'): # use Magic-file-extensions from file
......
......@@ -17,16 +17,18 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import logging
import operator
from diffoscope.config import Config
from diffoscope.logging import logger
try:
import tlsh
except ImportError:
tlsh = None
logger = logging.getLogger(__name__)
def perform_fuzzy_matching(members1, members2):
if tlsh == None or Config().fuzzy_threshold == 0:
......
......@@ -21,9 +21,9 @@
import time
import os.path
import ctypes
import logging
import libarchive
from diffoscope.logging import logger
from diffoscope.tempfiles import get_temporary_directory
from ..device import Device
......@@ -32,6 +32,8 @@ from ..directory import Directory
from .archive import Archive, ArchiveMember
logger = logging.getLogger(__name__)
# Monkeypatch libarchive-c (<< 2.2)
if not hasattr(libarchive.ffi, 'entry_rdevmajor'):
......
......@@ -17,13 +17,15 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import logging
import importlib
from diffoscope.logging import logger
from diffoscope.profiling import profile
from .. import COMPARATORS
logger = logging.getLogger(__name__)
def specialize(file):
for cls in FILE_CLASSES:
......
......@@ -19,16 +19,18 @@
import re
import os.path
import logging
import subprocess
import collections
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from .utils.file import File
from .utils.archive import Archive
from .utils.filenames import get_compressed_content_name
logger = logging.getLogger(__name__)
class XzContainer(Archive):
def open_archive(self):
......
......@@ -22,6 +22,7 @@ import re
import io
import signal
import hashlib
import logging
import threading
import contextlib
import subprocess
......@@ -32,9 +33,10 @@ from multiprocessing.dummy import Queue
from .exc import RequiredToolNotFound
from .tools import tool_required
from .config import Config
from .logging import logger
from .profiling import profile
logger = logging.getLogger(__name__)
class DiffParser(object):
RANGE_RE = re.compile(r'^@@\s+-(?P<start1>\d+)(,(?P<len1>\d+))?\s+\+(?P<start2>\d+)(,(?P<len2>\d+))?\s+@@$')
......
......@@ -19,8 +19,9 @@
import os
import time
import logging
from .logging import logger
logger = logging.getLogger(__name__)
def set_locale():
......
......@@ -19,12 +19,16 @@
import logging
logger = logging.getLogger("diffoscope")
logger.setLevel(logging.WARNING)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
def setup_logging(debug):
logger = logging.getLogger()
logger.setLevel(logging.DEBUG if debug else logging.WARNING)
formatter = logging.Formatter('%(created).3f %(levelname).1s: %(message)s')
ch.setFormatter(formatter)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
formatter = logging.Formatter(
'%(asctime)s %(levelname).1s: %(name)s: %(message)s',
)
ch.setFormatter(formatter)
......@@ -31,7 +31,7 @@ from .exc import RequiredToolNotFound
from .tools import tool_required, OS_NAMES, get_current_os
from .config import Config
from .locale import set_locale
from .logging import logger
from .logging import setup_logging
from .progress import ProgressManager, Progress
from .profiling import ProfileManager, profile
from .tempfiles import clean_all_temp_files
......@@ -40,6 +40,9 @@ from .presenters.html import JQUERY_SYSTEM_LOCATIONS
from .presenters.utils import output_all
from .comparators.utils.compare import compare_root_paths
logger = logging.getLogger(__name__)
try:
import tlsh
except ImportError:
......@@ -211,6 +214,7 @@ def maybe_set_limit(config, parsed_args, key):
def run_diffoscope(parsed_args):
setup_logging(parsed_args.debug)
if not tlsh and Config().fuzzy_threshold != parsed_args.fuzzy_threshold:
logger.warning('Fuzzy-matching is currently disabled as the "tlsh" module is unavailable.')
maybe_set_limit(Config(), parsed_args, "max_report_size")
......@@ -222,8 +226,6 @@ def run_diffoscope(parsed_args):
maybe_set_limit(Config(), parsed_args, "max_diff_input_lines")
Config().fuzzy_threshold = parsed_args.fuzzy_threshold
Config().new_file = parsed_args.new_file
if parsed_args.debug:
logger.setLevel(logging.DEBUG)
set_locale()
logger.debug('Starting comparison')
ProgressManager().setup(parsed_args)
......
......@@ -38,11 +38,11 @@ import sys
import html
import codecs
import hashlib
import logging
import contextlib
from diffoscope import VERSION
from diffoscope.config import Config
from diffoscope.logging import logger
from ..icon import FAVICON_BASE64
......@@ -65,6 +65,8 @@ JQUERY_SYSTEM_LOCATIONS = (
'/usr/share/javascript/jquery/jquery.js',
)
logger = logging.getLogger(__name__)
class PrintLimitReached(Exception):
pass
......
......@@ -20,11 +20,13 @@
import subprocess
import sys
import logging
from diffoscope.tools import tool_required
from diffoscope.logging import logger
from diffoscope.difference import color_unified_diff
logger = logging.getLogger(__name__)
def print_difference(difference, print_func, color=False):
if difference.comments:
......
......@@ -19,14 +19,16 @@
import sys
import codecs
import logging
import contextlib