Commit ea660044 authored by Chris Lamb's avatar Chris Lamb 💬

Provide a cleaner and more explicit solution to modifying the path to include /usr/sbin etc.

Signed-off-by: Chris Lamb's avatarChris Lamb <lamby@debian.org>
parent 2213dd78
......@@ -5,6 +5,7 @@
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2014-2015 Jérémy Bobbio <lunar@debian.org>
# Copyright © 2017 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
......@@ -27,6 +28,7 @@ import argparse
import traceback
from . import VERSION
from .path import set_path
from .tools import tool_required, OS_NAMES, get_current_os
from .config import Config
from .locale import set_locale
......@@ -252,6 +254,7 @@ def run_diffoscope(parsed_args):
Config().fuzzy_threshold = parsed_args.fuzzy_threshold
Config().new_file = parsed_args.new_file
Config().excludes = parsed_args.excludes
set_path()
set_locale()
logger.debug('Starting comparison')
ProgressManager().setup(parsed_args)
......
# -*- coding: utf-8 -*-
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2017 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
# 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 set_path():
pathlist = os.environ['PATH'].split(os.pathsep)
for x in ('/sbin', '/usr/sbin', '/usr/local/sbin'):
if x not in pathlist:
pathlist.append(x)
os.environ['PATH'] = os.pathsep.join(pathlist)
......@@ -2,7 +2,7 @@
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2016 Chris Lamb <lamby@debian.org>
# Copyright © 2016, 2017 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
......@@ -38,15 +38,6 @@ OS_NAMES = collections.OrderedDict([
('FreeBSD', 'FreeBSD'),
])
# Ensure tests and the runtime environment can locate binaries in /usr/sbin
# (eg. tcpdump). We must modify the path before the @tool_required decorator is
# applied.
pathlist = os.environ['PATH'].split(os.pathsep)
for x in ('/sbin', '/usr/sbin', '/usr/local/sbin'):
if x not in pathlist:
pathlist.append(x)
os.environ['PATH'] = os.pathsep.join(pathlist)
def tool_required(command):
"""
......
......@@ -3,6 +3,7 @@
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2016 Brett Smith <debbug@brettcsmith.org>
# Copyright © 2017 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
......@@ -19,10 +20,13 @@
import pytest
from diffoscope.path import set_path
from diffoscope.locale import set_locale
from diffoscope.progress import ProgressManager
from diffoscope.comparators import ComparatorManager
# Ensure set_path fixture runs before all tests.
set_path()
# Ensure set_locale fixture runs before each test.
set_locale = pytest.fixture(autouse=True, scope='session')(set_locale)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment