From 864ef9b40f5f9d0c66a458b6033277938d7d1d50 Mon Sep 17 00:00:00 2001 From: Ben McGinnes Date: Sat, 15 Sep 2018 12:10:05 +1000 Subject: Python examples: backwards compatibility * lang/python/examples/howto/groups.py: subprocess update * lang/python/examples/howto/export-secret-keys.py: subprocess update Both of these try the nice and easy method of getting the subprocess output available in Python 3, but will fall back to the older Popen method if it doesn't work. Essentially this is to be a little nicer to Python 2.7.15 (even though the examples are filled with warnings that py2 support is not guaranteed with the examples). --- lang/python/examples/howto/groups.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lang/python/examples/howto/groups.py') diff --git a/lang/python/examples/howto/groups.py b/lang/python/examples/howto/groups.py index b8317b69..154961b1 100644 --- a/lang/python/examples/howto/groups.py +++ b/lang/python/examples/howto/groups.py @@ -37,7 +37,12 @@ if sys.platform == "win32": else: gpgconfcmd = "gpgconf --list-options gpg" -lines = subprocess.getoutput(gpgconfcmd).splitlines() +try: + lines = subprocess.getoutput(gpgconfcmd).splitlines() +except: + process = subprocess.Popen(gpgconfcmd.split(), stdout=subprocess.PIPE) + procom = process.communicate() + lines = procom[0].decode().splitlines() for i in range(len(lines)): if lines[i].startswith("group") is True: -- cgit v1.2.3