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).
This commit is contained in:
Ben McGinnes 2018-09-15 12:10:05 +10:00
parent dd7d37ca21
commit 864ef9b40f
2 changed files with 13 additions and 2 deletions

View File

@ -84,7 +84,13 @@ else:
if os.path.exists(os.environ["GNUPGHOME"]) is True:
hd = os.environ["GNUPGHOME"]
else:
hd = subprocess.getoutput(gpgconfcmd)
try:
hd = subprocess.getoutput(gpgconfcmd)
except:
process = subprocess.Popen(gpgconfcmd.split(),
stdout=subprocess.PIPE)
procom = process.communicate()
hd = procom[0].decode().strip()
gpgfile = "{0}/{1}.gpg".format(hd, keyfile)
ascfile = "{0}/{1}.asc".format(hd, keyfile)

View File

@ -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: