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

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

Updated python code to reflect the renaming of the delivery package to pybbftp.
Some C tidying to reduce compiler warnings.

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