Skip to content

Commit

Permalink
Ignore errors when removing GPG homedir
Browse files Browse the repository at this point in the history
  • Loading branch information
pdcribeiro committed Mar 2, 2021
1 parent bd907d0 commit 434b8ad
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions humans/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
from datetime import datetime
from functools import wraps
from shutil import rmtree
from tempfile import TemporaryDirectory
import gnupg
import tempfile


def with_gpg_obj(func):
@wraps(func)
def inner(key):
with TemporaryDirectory() as temp_dir:
gpg_obj = gnupg.GPG(homedir=temp_dir,
keyring="pub.gpg",
secring="sec.gpg")
gpg_obj.encoding = 'utf-8'
ret = func(key, gpg_obj)
# create temp gpg keyring
temp_dir = tempfile.mkdtemp()
gpg_obj = gnupg.GPG(homedir=temp_dir,
keyring="pub.gpg",
secring="sec.gpg")
gpg_obj.encoding = 'utf-8'
ret = func(key, gpg_obj)
# remove the keyring
rmtree(temp_dir, ignore_errors=True)

return ret
return inner

Expand Down

0 comments on commit 434b8ad

Please sign in to comment.