From c162d2b886c40d1065568d28286c6644cc017fe4 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Wed, 7 Jun 2017 21:32:43 +0100 Subject: [PATCH] Not depending on python-distro. - Python-distro is new and isn't packaged in many distributions. - Can just get the distribution ID directly. --- install-dependencies | 11 ++--------- install-tools | 3 +-- tools.py | 11 +++++++++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/install-dependencies b/install-dependencies index d452b1f..b44ec85 100755 --- a/install-dependencies +++ b/install-dependencies @@ -10,29 +10,22 @@ set -e DIST_ID=$(cat /etc/os-release | grep "^ID=" | cut -d "=" -f 2) if [ $DIST_ID == "fedora" ]; then INSTALL_CMD="dnf -y install" - DEPS="python3-distro python3-inotify python3-pygments python3-docopt python3-pillow" + DEPS="python3-inotify python3-pygments python3-docopt python3-pillow" elif [ $DIST_ID == "arch" ]; then INSTALL_CMD="pacman -S --noconfirm --needed" DEPS="python-pyinotify python-pygments python-docopt python-pillow" - sudo pacman -S --noconfirm python-pip - sudo pip3 install distro elif [ $DIST_ID == "opensuse" ]; then INSTALL_CMD="zypper -n install" DEPS="python3-pyinotify python3-Pygments python3-docopt python3-Pillow" - sudo pip3 install distro elif [ $DIST_ID == "debian" ]; then INSTALL_CMD="apt --yes install" DEPS="python3-pyinotify python3-pygments python3-docopt python3-pillow" - sudo apt --yes install python3-pip - sudo pip3 install distro elif [ $DIST_ID == "gentoo" ]; then INSTALL_CMD="emerge --noreplace" DEPS="pyinotify pygments docopt pillow" - emerge --noreplace dev-python/pip - sudo pip3 install --user distro else INSTALL_CMD="apt --yes install" - DEPS="python3-distro python3-pyinotify python3-pygments python3-docopt python3-pillow" + DEPS="python3-pyinotify python3-pygments python3-docopt python3-pillow" fi echo "Installing the dependencies of the vigil script..." sudo $INSTALL_CMD $DEPS util-linux diff --git a/install-tools b/install-tools index 0f96d68..faea23f 100755 --- a/install-tools +++ b/install-tools @@ -4,12 +4,11 @@ # Licensed under the Artistic License 2.0. -import distro import subprocess import tools -dist_id = distro.id() +dist_id = tools.get_distro_id() pip_deps, pip3_deps, dist_deps = set(), set(), set() for dependency in tools.dependencies(dist_id): if "/" in dependency: diff --git a/tools.py b/tools.py index a8de3a9..b3979a1 100644 --- a/tools.py +++ b/tools.py @@ -23,7 +23,6 @@ import tempfile import time import traceback -import distro import PIL.Image import pygments import pygments.lexers @@ -878,9 +877,17 @@ def is_tool_in_distribution(tool, distribution): return tool +def get_distro_id(): + with open("/etc/os-release") as os_release_file: + for line in os_release_file: + if line.startswith("ID="): + return line[len("ID="):].strip() + raise AssertionError + + @functools.lru_cache(maxsize=1) def _tools_for_extension(): - distribution = distro.id() + distribution = get_distro_id() result = {} for extensions, tools in TOOLS_FOR_EXTENSIONS: for extension in extensions: