p≡p engine FORK
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.

46 lines
1.3 KiB

  1. #!/usr/bin/env python3
  2. # This file is under GNU General Public License 3.0
  3. # see LICENSE.txt
  4. from sqlite3 import connect
  5. from os import environ
  6. from argparse import ArgumentParser
  7. from re import sub
  8. try:
  9. environ["ALLUSERSPROFILE"]
  10. except KeyError:
  11. db_file = "/usr/local/share/pEp/system.db"
  12. else:
  13. db_file = environ["ALLUSERSPROFILE"] + r"\pEp\system.db"
  14. p = ArgumentParser(description="show trustwords instead of hex fingerprint")
  15. p.add_argument('--db-path', '-d', type=str, default=db_file,
  16. help='path to pEp system db (default: ' + db_file + ')')
  17. p.add_argument('--lang', '-l', type=str, default="en",
  18. help='use dictionary for language LANG (default: en)')
  19. p.add_argument('--short', '-s', action='store_true',
  20. help='display the first 5 of the trustwords')
  21. p.add_argument('hex', metavar="hex", type=str, nargs='+',
  22. help='hex values of fingerprint')
  23. args = p.parse_args()
  24. c = connect(args.db_path).cursor()
  25. hex_string = sub(r"\W", "", "".join(args.hex))
  26. def hex_word(s):
  27. n = min(20, len(s)) if args.short else len(s)
  28. for i in range(0, n, 4):
  29. yield s[i:i+4]
  30. r = []
  31. for arg in hex_word(hex_string):
  32. c.execute("select word from wordlist where id = {} and lang = lower('{}')".format(
  33. str(int(arg, 16)), args.lang))
  34. r.append(c.fetchall()[0][0])
  35. print(" ".join(r))