Run update-copyright.py.
[pyassuan.git] / bin / get-info.py
1 #!/usr/bin/env python3
2 #
3 # Copyright (C) 2012 W. Trevor King <wking@drexel.edu>
4 #
5 # This file is part of pyassuan.
6 #
7 # pyassuan is free software: you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation, either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # pyassuan is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # pyassuan.  If not, see <http://www.gnu.org/licenses/>.
18
19 """Simple pinentry program for getting server info.
20 """
21
22 import socket as _socket
23
24 from pyassuan import __version__
25 from pyassuan import client as _client
26 from pyassuan import common as _common
27
28
29 if __name__ == '__main__':
30     import argparse
31     import logging
32
33     parser = argparse.ArgumentParser(description=__doc__, version=__version__)
34     parser.add_argument(
35         '-V', '--verbose', action='count', default=0,
36         help='increase verbosity')
37     parser.add_argument(
38         'filename',
39         help="path to server's unix socket")
40
41     args = parser.parse_args()
42
43     client = _client.AssuanClient(name='get-info', close_on_disconnect=True)
44
45     if args.verbose:
46         client.logger.setLevel(max(
47                 logging.DEBUG, client.logger.level - 10*args.verbose))
48
49     socket = _socket.socket(_socket.AF_UNIX, _socket.SOCK_STREAM)
50     socket.connect(args.filename)
51     client.input = socket.makefile('r')
52     client.output = socket.makefile('w')
53     client.connect()
54     try:
55         response = client.read_response()
56         assert response.type == 'OK', response
57         client.make_request(_common.Request('HELP'))
58         client.make_request(_common.Request('HELP GETINFO'))
59         for attribute in ['version', 'pid', 'socket_name', 'ssh_socket_name']:
60             client.make_request(_common.Request('GETINFO', attribute))
61     finally:
62         client.make_request(_common.Request('BYE'))
63         client.disconnect()
64         socket.shutdown(_socket.SHUT_RDWR)
65         socket.close()