File: SignKey.py

package info (click to toggle)
gnome-keysign 1.3.0-5.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,460 kB
  • sloc: python: 5,143; xml: 126; makefile: 33; sh: 16
file content (62 lines) | stat: -rwxr-xr-x 2,380 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
#    Copyright 2015 Tobias Mueller <muelli@cryptobitch.de>
#
#    This file is part of GNOME Keysign.
#
#    GNOME Keysign is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    GNOME Keysign is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with GNOME Keysign.  If not, see <http://www.gnu.org/licenses/>.

import logging
import sys

from .util import sign_keydata_and_send

if sys.version_info.major < 3:
    input = raw_input


def main():
    import argparse
    parser = argparse.ArgumentParser(description=""
        "Certify UIDs of given OpenPGP certificates (aka sign OpenPGP keys) "
        " from a file.  "
        "The program will open each file, extract exactly one "
        "OpenPGP certificate, sign each UID separately, encrypt and send "
        "each signed UID using xdg-email.")
    parser.add_argument('-v', '--verbose', action='count', default=0,
        help="Increase detail of logging")
    parser.add_argument("file", nargs='+', type=argparse.FileType('rb'),
        help="File containing OpenPGP keys")
    args = parser.parse_args()

    log_levels = [logging.WARNING, logging.INFO, logging.DEBUG]
    log_level = log_levels[min(len(log_levels)-1, args.verbose)]
    logging.basicConfig(level=log_level)

    log = logging.getLogger(__name__)
    log.debug('Running main with args: %s', args)
    for fhandle in args.file:
        data = fhandle.read()
        log.info("Calling %r to sign %s", sign_keydata_and_send, fhandle.name)
        tmpfiles = list(sign_keydata_and_send(keydata=data))
    print("Finished signing. " +
             "We're only waiting for the signature " +
             "files to be picked up. " +
             "Press any key to quit the application.")
    input()


if __name__ == '__main__':
    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG,
            format='%(name)s (%(levelname)s): %(message)s')
    sys.exit(main())