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

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

Embedded test cases and examples work when executed from a
virtual-python with delivery service installed.

  • 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))
10VERSION = open('%s/VERSION' % HOME).read()
11NDG_MESSAGE_LEN = 256
12
13NDG_HANDSHAKE = "NDG-Delivery-client %s" % VERSION
14
15import ndg.delivery.client.pybbftp as DC
16
17class AuthClientHandler(DC.AuthClientHandler):
18    def __init__(self, privatestr="none"):
19        self.privatestr = privatestr
20
21    def authenticate(self):
22        self.send(NDG_HANDSHAKE)
23        resp = self.recv()
24
25        print "Received Auth handshake: %s" % resp
26
27        self.send(self.privatestr)
28
29        return True
30
31def makeClient(username, hostname):
32    return DC.connect(AuthClientHandler(), ['-m', '-u', username, '-r', '1', hostname])
33
34def do(cmd):
35    return DC.docommand(cmd)
36
37def close():
38    return DC.close()
39
40
41if __name__ == '__main__':
42
43    try:
44        import readline
45    except ImportError:
46        pass
47
48
49    print """
50    ===================================
51    NDG Delivery Service example client
52    Type 'quit' to exit.
53    ==================================="""
54
55
56    (hostname, ) = sys.argv[1:]
57    makeClient('exampleUser', hostname)
58    cmd = ''
59    while 1:
60        print 'DS> ',
61        cmd = sys.stdin.readline()
62        if cmd.lower()[0] == 'q':
63            break
64        msgs = do(cmd.rstrip())
65        for msg in msgs:
66            print msg.rstrip()
67       
Note: See TracBrowser for help on using the repository browser.