Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
979 B

4 years ago
  1. import os
  2. import tarfile
  3. from gnupg import GPG
  4. from ranger.api.commands import Command
  5. class decrypt(Command):
  6. """:decrypts
  7. Decrypts a file with gpg or a directory by extracting a tar file and decrypting it
  8. passing true as the false flag will not delete the origin gpg file
  9. """
  10. def execute(self):
  11. gpg = GPG(gnupghome=os.path.join(os.path.expanduser('~'), '.gnupg'))
  12. paths = [os.path.basename(f.path) for f in self.fm.thistab.get_selection()]
  13. for p in [p for p in paths if p.endswith('gpg')]:
  14. with open(p, 'rb') as enc:
  15. dec_b = gpg.decrypt_file(enc)
  16. out_fname = os.path.splitext(p)[0]
  17. with open(out_fname, 'wb+') as dec_f:
  18. dec_f.write(dec_b.data)
  19. if self.arg(1) != 'true':
  20. os.remove(p)
  21. if tarfile.is_tarfile(out_fname):
  22. tarfile.open(out_fname).extractall(path='.')
  23. os.remove(out_fname)