From f83b3dd9374745a0e75221357c1aaf570340c949 Mon Sep 17 00:00:00 2001 From: Neal Gompa Date: Apr 23 2019 13:27:37 +0000 Subject: Allow controlling packager identity through environment variables In order to support more flexible automation mechanisms, allow injecting the packager identity through environment variables as an override from the regular detection mechanisms. Moreover, there are cases where we want to force the fallback identity, so we now have a way to force that through an environment variable. These are intended to be used with multi-user automation systems so that the correct identity is set regardless of what the host system is actually configured with. Signed-off-by: Neal Gompa --- diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py index b22de61..cbb3a22 100644 --- a/rust2rpm/__main__.py +++ b/rust2rpm/__main__.py @@ -72,10 +72,21 @@ def detect_editor(): return editor def detect_packager(): + # If we're forcing the fallback... + if os.getenv("RUST2RPM_NO_DETECT_PACKAGER") is not None: + return None + + # If we're supplying packager identity through an environment variable... + packager_identity = os.getenv("RUST2RPM_PACKAGER") + if packager_identity is not None: + return packager_identity + + # If we're detecting packager identity through rpmdev-packager... rpmdev_packager = shutil.which("rpmdev-packager") if rpmdev_packager is not None: return subprocess.check_output(rpmdev_packager, universal_newlines=True).strip() + # If we're detecting packager identity through git configuration... git = shutil.which("git") if git is not None: name = subprocess.check_output([git, "config", "user.name"], universal_newlines=True).strip()