source: TI05-delivery/trunk/examples/deliveryclient.py @ 1280

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/examples/deliveryclient.py@1280
Revision 1280, 1.4 KB checked in by spascoe, 13 years ago (diff)

Trivial change.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2"""
3A simple client.
4"""
5
6import os, sys
7from glob import glob
8
9HOME = os.path.abspath(os.getenv('NDG_DELIVERY_HOME', os.curdir))
10BUILDDIR = glob('%s/build/lib.*' % HOME)[0]
11VERSION = open('%s/VERSION' % HOME).read()
12NDG_MESSAGE_LEN = 256
13
14NDG_HANDSHAKE = "NDG-Delivery-client %s" % VERSION
15
16
17sys.path.append(BUILDDIR)
18
19import delivery.client as DC
20
21class AuthClientHandler(DC.AuthClientHandler):
22    def __init__(self, privatestr="none"):
23        self.privatestr = privatestr
24
25    def authenticate(self):
26        self.send(NDG_HANDSHAKE)
27        resp = self.recv()
28
29        print "Received Auth handshake: %s" % resp
30
31        self.send(self.privatestr)
32
33        return True
34
35def makeClient(username, hostname):
36    return DC.connect(AuthClientHandler(), ['-m', '-u', username, '-r', '1', hostname])
37
38def do(cmd):
39    return DC.docommand(cmd)
40
41def close():
42    return DC.close()
43
44
45if __name__ == '__main__':
46
47    try:
48        import readline
49    except ImportError:
50        pass
51
52
53    print """
54    ===================================
55    NDG Delivery Service example client
56    Type 'quit' to exit.
57    ==================================="""
58
59
60    (hostname, ) = sys.argv[1:]
61    makeClient('exampleUser', hostname)
62    cmd = ''
63    while 1:
64        print 'DS> ',
65        cmd = sys.stdin.readline()
66        if cmd.lower()[0] == 'q':
67            break
68        msgs = do(cmd.rstrip())
69        for msg in msgs:
70            print msg.rstrip()
71       
Note: See TracBrowser for help on using the repository browser.