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:
parent
dd7d37ca21
commit
864ef9b40f
@ -84,7 +84,13 @@ else:
|
|||||||
if os.path.exists(os.environ["GNUPGHOME"]) is True:
|
if os.path.exists(os.environ["GNUPGHOME"]) is True:
|
||||||
hd = os.environ["GNUPGHOME"]
|
hd = os.environ["GNUPGHOME"]
|
||||||
else:
|
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)
|
gpgfile = "{0}/{1}.gpg".format(hd, keyfile)
|
||||||
ascfile = "{0}/{1}.asc".format(hd, keyfile)
|
ascfile = "{0}/{1}.asc".format(hd, keyfile)
|
||||||
|
|
||||||
|
@ -37,7 +37,12 @@ if sys.platform == "win32":
|
|||||||
else:
|
else:
|
||||||
gpgconfcmd = "gpgconf --list-options gpg"
|
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)):
|
for i in range(len(lines)):
|
||||||
if lines[i].startswith("group") is True:
|
if lines[i].startswith("group") is True:
|
||||||
|
Loading…
Reference in New Issue
Block a user