source: TI05-delivery/trunk/test/runclient.py @ 1265

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/test/runclient.py@1265
Revision 1265, 1.7 KB checked in by spascoe, 15 years ago (diff)

Messages from the client that were previously printed to stdout/stderr are now returned
in a list from python functions bbftpc.connect() and bbftpc.docommand().

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2"""
3This script runs the bbftp client using the python-bbftp client wrapper.  We need this
4to test client-server interactions without importing both delivery.bbftpd and delivery.bbftpc
5into the interpreter.
6"""
7
8import os, sys, time
9from glob import glob
10
11HOME = os.path.abspath(os.getenv('NDG_DELIVERY_HOME', os.curdir))
12BUILDDIR = glob('%s/build/lib.*' % HOME)[0]
13VERSION = open('%s/VERSION' % HOME).read()
14NDG_MESSAGE_LEN = 256
15
16NDG_HANDSHAKE = "NDG-Delivery-client %s" % VERSION
17
18
19sys.path.append(BUILDDIR)
20
21import delivery.bbftpc as BC
22
23
24class AuthClientHandler(object):
25    def __init__(self, privatestr="none"):
26        self.privatestr = privatestr
27
28    def authenticate(self):
29        #print >>sys.stderr, "Waiting 20s for gdb connect: pid=%d" % os.getpid(),
30        #time.sleep(20)
31        #print >>sys.stderr, "continueing"
32
33        BC.send(NDG_HANDSHAKE)
34        resp = BC.recv()
35
36        print "Received Auth handshake: %s" % resp
37
38        BC.send(self.privatestr)
39
40        return True
41
42
43# Extract the command (-e) since bbftpc doesn't use it any more
44# Allow multiple commands
45args = sys.argv[1:]
46cmds = []
47
48while True:
49    try:
50        ei = args.index('-e')
51    except ValueError:
52        break
53    cmds.append(args[ei+1])
54    args = args[:ei] + args[ei+2:]
55
56try:
57    i = args.index('-P')
58except ValueError:
59    privatestr = "none"
60    pass
61else:
62    privatestr = args[i+1]
63    args = args[:i] + args[i+2:]
64
65ach = AuthClientHandler(privatestr)
66
67print "** runclient.py: connecting"
68msgs = BC.connect(ach, args)
69for msg in msgs:
70    print msg.rstrip()
71   
72for cmd in cmds:
73    print "** runclient.py: doing %s" % cmd
74    msgs = BC.docommand(cmd)
75    for msg in msgs:
76        print msg.rstrip()
77BC.close()
Note: See TracBrowser for help on using the repository browser.