safeword => trustword in scripts
authorVolker Birk <vb@pep-project.org>
Tue, 05 May 2015 17:37:49 +0200
changeset 2461546f1595882
parent 242 6736f061c8f8
child 247 12e852387299
safeword => trustword in scripts
db/safewords.py
db/trustwords.py
     1.1 --- a/db/safewords.py	Tue May 05 11:48:50 2015 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,42 +0,0 @@
     1.4 -#!/usr/bin/env python3
     1.5 -
     1.6 -from sqlite3 import connect
     1.7 -from os import environ
     1.8 -from argparse import ArgumentParser
     1.9 -from re import sub
    1.10 -
    1.11 -try:
    1.12 -    environ["ALLUSERSPROFILE"]
    1.13 -except KeyError:
    1.14 -    db_file = "/usr/local/share/pEp/system.db"
    1.15 -else:
    1.16 -    db_file = environ["ALLUSERSPROFILE"] + r"\pEp\system.db"
    1.17 -
    1.18 -p = ArgumentParser(description="show safewords instead of hex fingerprint")
    1.19 -p.add_argument('--db-path', '-d', type=str, default=db_file,
    1.20 -        help='path to pEp system db (default: ' + db_file + ')')
    1.21 -p.add_argument('--lang', '-l', type=str, default="en",
    1.22 -        help='use dictionary for language LANG (default: en)')
    1.23 -p.add_argument('--short', '-s', action='store_true',
    1.24 -        help='display the first 5 of the safewords')
    1.25 -p.add_argument('hex', metavar="hex", type=str, nargs='+',
    1.26 -        help='hex values of fingerprint')
    1.27 -
    1.28 -args = p.parse_args()
    1.29 -
    1.30 -c = connect(args.db_path).cursor()
    1.31 -hex_string = sub(r"\W", "", "".join(args.hex))
    1.32 -
    1.33 -def hex_word(s):
    1.34 -    n = min(20, len(s)) if args.short else len(s)
    1.35 -    for i in range(0, n, 4):
    1.36 -        yield s[i:i+4]
    1.37 -
    1.38 -r = []
    1.39 -
    1.40 -for arg in hex_word(hex_string):
    1.41 -    c.execute("select word from wordlist where id = {} and lang = lower('{}')".format(
    1.42 -            str(int(arg, 16)), args.lang))
    1.43 -    r.append(c.fetchall()[0][0])
    1.44 -
    1.45 -print(" ".join(r))
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/db/trustwords.py	Tue May 05 17:37:49 2015 +0200
     2.3 @@ -0,0 +1,42 @@
     2.4 +#!/usr/bin/env python3
     2.5 +
     2.6 +from sqlite3 import connect
     2.7 +from os import environ
     2.8 +from argparse import ArgumentParser
     2.9 +from re import sub
    2.10 +
    2.11 +try:
    2.12 +    environ["ALLUSERSPROFILE"]
    2.13 +except KeyError:
    2.14 +    db_file = "/usr/local/share/pEp/system.db"
    2.15 +else:
    2.16 +    db_file = environ["ALLUSERSPROFILE"] + r"\pEp\system.db"
    2.17 +
    2.18 +p = ArgumentParser(description="show trustwords instead of hex fingerprint")
    2.19 +p.add_argument('--db-path', '-d', type=str, default=db_file,
    2.20 +        help='path to pEp system db (default: ' + db_file + ')')
    2.21 +p.add_argument('--lang', '-l', type=str, default="en",
    2.22 +        help='use dictionary for language LANG (default: en)')
    2.23 +p.add_argument('--short', '-s', action='store_true',
    2.24 +        help='display the first 5 of the trustwords')
    2.25 +p.add_argument('hex', metavar="hex", type=str, nargs='+',
    2.26 +        help='hex values of fingerprint')
    2.27 +
    2.28 +args = p.parse_args()
    2.29 +
    2.30 +c = connect(args.db_path).cursor()
    2.31 +hex_string = sub(r"\W", "", "".join(args.hex))
    2.32 +
    2.33 +def hex_word(s):
    2.34 +    n = min(20, len(s)) if args.short else len(s)
    2.35 +    for i in range(0, n, 4):
    2.36 +        yield s[i:i+4]
    2.37 +
    2.38 +r = []
    2.39 +
    2.40 +for arg in hex_word(hex_string):
    2.41 +    c.execute("select word from wordlist where id = {} and lang = lower('{}')".format(
    2.42 +            str(int(arg, 16)), args.lang))
    2.43 +    r.append(c.fetchall()[0][0])
    2.44 +
    2.45 +print(" ".join(r))