From b53c2825095f41166b338d84d38a2a17d68f7cc0 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Mon, 30 May 2022 22:49:15 +0200 Subject: [PATCH] v0.1.9 re-add setup.py; check python version before using subprocess module --- README.md | 4 ++-- setup.cfg | 6 ++---- setup.py | 4 ++++ src/de/p1st/exec_notify/lib/exec.py | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 setup.py diff --git a/README.md b/README.md index a8a6dc9..2d68eaf 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,8 @@ pip --version Then install with one of the following options: ```shell -sudo python3 -m pip install --upgrade git+https://codeberg.org/privacy1st/execNotify -sudo python3 -m pip install --upgrade . +sudo python3 -m pip install --upgrade --force-reinstall git+https://codeberg.org/privacy1st/execNotify +sudo python3 -m pip install --upgrade --force-reinstall . sudo python3 -m pip install --upgrade --index-url https://test.pypi.org/simple/ --no-deps de.p1st.exec-notify ``` diff --git a/setup.cfg b/setup.cfg index ec56bbe..7bf6d63 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ [metadata] name = de.p1st.exec_notify -version = 0.1.8 +version = 0.1.9 author = Daniel Langbein author_email = daniel@systemli.org description = mail notification if command fails @@ -24,9 +24,7 @@ classifiers = package_dir = = src packages = find: -; capture_output was added in 3.7 -; - https://docs.python.org/3/library/subprocess.html#subprocess.run -python_requires = >=3.7 +python_requires = >=3.6 [options.packages.find] where = src diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..0abbd0a --- /dev/null +++ b/setup.py @@ -0,0 +1,4 @@ +# This file is required for `pip install` on Ubuntu 18.04. +# It loads `setup.cfg`. +from setuptools import setup +setup() diff --git a/src/de/p1st/exec_notify/lib/exec.py b/src/de/p1st/exec_notify/lib/exec.py index ad3bf23..87b903d 100644 --- a/src/de/p1st/exec_notify/lib/exec.py +++ b/src/de/p1st/exec_notify/lib/exec.py @@ -1,3 +1,4 @@ +import sys from typing import List from sys import stdin import subprocess @@ -12,6 +13,19 @@ def execute(command: List[str]): :return: (exit_code, stdout, stderr) """ + if sys.version_info.major == 3 and sys.version_info.minor < 7: + # capture_output was added in 3.7 + # - https://docs.python.org/3/library/subprocess.html#subprocess.run + + completed: subprocess.CompletedProcess = subprocess.run( + command, + stdin=stdin, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + check=False, + ) + return completed.returncode, str(completed.stdout), str(completed.stderr) + completed: subprocess.CompletedProcess = subprocess.run( command, stdin=stdin,