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

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

test client script dumps output to bbftpc.log. Some debug code removed.

  • 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 pybbftp.client as DC
22
23class AuthClientHandler(DC.AuthClientHandler):
24    def __init__(self, privatestr="none"):
25        self.privatestr = privatestr
26
27    def authenticate(self):
28        self.send(NDG_HANDSHAKE)
29        resp = self.recv()
30
31        print "Received Auth handshake: %s" % resp
32
33        self.send(self.privatestr)
34
35        return True
36
37
38# Extract the command (-e) since bbftpc doesn't use it any more
39# Allow multiple commands
40args = sys.argv[1:]
41cmds = []
42
43while True:
44    try:
45        ei = args.index('-e')
46    except ValueError:
47        break
48    cmds.append(args[ei+1])
49    args = args[:ei] + args[ei+2:]
50
51try:
52    i = args.index('-P')
53except ValueError:
54    privatestr = "none"
55    pass
56else:
57    privatestr = args[i+1]
58    args = args[:i] + args[i+2:]
59
60ach = AuthClientHandler(privatestr)
61
62print "** runclient.py: connecting"
63msgs = DC.connect(ach, args)
64for msg in msgs:
65    print msg.rstrip()
66   
67for cmd in cmds:
68    print "** runclient.py: doing %s" % cmd
69    msgs = DC.docommand(cmd)
70    for msg in msgs:
71        print msg.rstrip()
72DC.close()
Note: See TracBrowser for help on using the repository browser.