Skip to content
Snippets Groups Projects
Commit 1756a48d authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

Don't print a traceback if we pass a single, missing argument to diffoscope...

Don't print a traceback if we pass a single, missing argument to diffoscope (eg. a JSON diff to re-load).
parent 591ea6e1
No related branches found
No related tags found
No related merge requests found
Pipeline #136157 passed
......@@ -19,7 +19,6 @@
import io
import os
import sys
import shlex
import logging
import binascii
......@@ -27,6 +26,7 @@ import subprocess
from diffoscope.tools import tool_required
from diffoscope.exc import RequiredToolNotFound
from diffoscope.utils import bail_if_non_existing
from diffoscope.config import Config
from diffoscope.excludes import any_excluded
from diffoscope.profiling import profile
......@@ -147,16 +147,6 @@ def call_difftool(file1, file2):
subprocess.call(cmd, shell=True)
def bail_if_non_existing(*paths):
if not all(map(os.path.lexists, paths)):
for path in paths:
if not os.path.lexists(path):
sys.stderr.write(
'%s: %s: No such file or directory\n' % (sys.argv[0], path)
)
sys.exit(2)
def compare_binary_files(file1, file2, source=None):
try:
if source is None:
......
......@@ -3,7 +3,7 @@
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2017 Ximin Luo <infinity0@debian.org>
# Copyright © 2017 Chris Lamb <lamby@debian.org>
# Copyright © 2017, 2020 Chris Lamb <lamby@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
......@@ -20,10 +20,13 @@
import codecs
from diffoscope.utils import bail_if_non_existing
from .json import JSONReaderV1
def load_diff_from_path(path):
bail_if_non_existing(path)
with open(path, 'rb') as fp:
return load_diff(codecs.getreader('utf-8')(fp), path)
......
......@@ -17,6 +17,9 @@
# 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 sys
def format_cmdline(cmd, replace=(), truncate=None):
def fn(x):
......@@ -44,3 +47,13 @@ def format_bytes(size, decimal_places=2):
size /= 1024.0
return f"{size:.{decimal_places}f} {unit}"
def bail_if_non_existing(*paths):
if not all(map(os.path.lexists, paths)):
for path in paths:
if not os.path.lexists(path):
sys.stderr.write(
'%s: %s: No such file or directory\n' % (sys.argv[0], path)
)
sys.exit(2)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment