|
Packit |
d7e8d0 |
#!/usr/bin/env python
|
|
Packit |
d7e8d0 |
#
|
|
Packit |
d7e8d0 |
# Copyright (C) 2016 g10 Code GmbH
|
|
Packit |
d7e8d0 |
# Copyright (C) 2005 Igor Belyi <belyi@users.sourceforge.net>
|
|
Packit |
d7e8d0 |
#
|
|
Packit |
d7e8d0 |
# This program is free software; you can redistribute it and/or modify
|
|
Packit |
d7e8d0 |
# it under the terms of the GNU General Public License as published by
|
|
Packit |
d7e8d0 |
# the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
d7e8d0 |
# (at your option) any later version.
|
|
Packit |
d7e8d0 |
#
|
|
Packit |
d7e8d0 |
# This program is distributed in the hope that it will be useful, but
|
|
Packit |
d7e8d0 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
d7e8d0 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
d7e8d0 |
# General Public License for more details.
|
|
Packit |
d7e8d0 |
#
|
|
Packit |
d7e8d0 |
# You should have received a copy of the GNU General Public License
|
|
Packit Service |
30b792 |
# along with this program; if not, see <https://www.gnu.org/licenses/>.
|
|
Packit |
d7e8d0 |
"""Simple interactive editor to test editor scripts"""
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
from __future__ import absolute_import, print_function, unicode_literals
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
import sys
|
|
Packit |
d7e8d0 |
import gpg
|
|
Packit |
d7e8d0 |
|
|
Packit Service |
30b792 |
del absolute_import, print_function, unicode_literals
|
|
Packit Service |
30b792 |
|
|
Packit |
d7e8d0 |
if len(sys.argv) != 2:
|
|
Packit |
d7e8d0 |
sys.exit("Usage: %s <Gpg key pattern>\n" % sys.argv[0])
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
name = sys.argv[1]
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
with gpg.Context() as c:
|
|
Packit |
d7e8d0 |
keys = list(c.keylist(name))
|
|
Packit |
d7e8d0 |
if len(keys) == 0:
|
|
Packit |
d7e8d0 |
sys.exit("No key matching {}.".format(name))
|
|
Packit |
d7e8d0 |
if len(keys) > 1:
|
|
Packit |
d7e8d0 |
sys.exit("More than one key matching {}.".format(name))
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
key = keys[0]
|
|
Packit |
d7e8d0 |
print("Editing key {} ({}):".format(key.uids[0].uid, key.subkeys[0].fpr))
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
def edit_fnc(keyword, args):
|
|
Packit Service |
30b792 |
print("Status: {}, args: {} > ".format(keyword, args), end="")
|
|
Packit |
d7e8d0 |
|
|
Packit Service |
30b792 |
if 'GET' not in keyword:
|
|
Packit |
d7e8d0 |
# no prompt
|
|
Packit |
d7e8d0 |
print()
|
|
Packit |
d7e8d0 |
return None
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
try:
|
|
Packit |
d7e8d0 |
return input()
|
|
Packit |
d7e8d0 |
except EOFError:
|
|
Packit |
d7e8d0 |
return "quit"
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
c.interact(key, edit_fnc, sink=sys.stdout)
|