source: TI05-delivery/trunk/src/python_ext/bbftpc.c @ 1238

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/src/python_ext/bbftpc.c@1238
Revision 1238, 2.0 KB checked in by spascoe, 15 years ago (diff)

Fixed the client API testcase problem. The client and server modules
cannot be linked into the same python interpreter, presumably because of
symbol conflicts. This should only be an issue during testing so I've created
the runclient.py script to circumvent it. There are now a set of test cases that wrap both client and server in python.

bbftp.c has been ammended to ensure all global variables are reset on each
invocation of bbftpc_main().

Line 
1/**
2 * NDG python embedded bbftp daemon module.
3 *
4 * @author Stephen Pascoe
5 *
6 * Copyright (C) 2006 CCLRC & NERC
7 *
8 * This software may be distributed under the terms of the Q Public Licence, version 1.0 or later.
9 *
10 */
11
12#include <Python.h>
13#include <stdio.h>
14
15#include "util.h"
16
17extern char **environ;
18
19int bbftpc_main(int argc, char **argv, char **envp);
20
21/**
22 * Main entry point into the bbftp client from python.
23 */
24static PyObject *bbftpc_run(PyObject *self, PyObject *args) {
25  int i, argc;
26  struct ndg_argv argv_s;
27  char *arg;
28  PyObject *client_args, *item;
29
30  if (!PyArg_ParseTuple(args, "O", &client_args)) {
31    return NULL;
32  }
33  Py_INCREF(client_args);
34
35  /*
36   * Convert arguments into a standard argv sequence.
37   */
38
39  if ((argc = PySequence_Size(client_args)) == -1) {
40    return NULL;
41  }
42  if (!ndg_argv_init(&argv_s, argc + 1)) {
43    PyErr_SetString(PyExc_MemoryError, "malloc failed");
44    Py_DECREF(client_args);
45    return NULL;
46  }
47
48  ndg_argv_add(&argv_s, "bbftpc_run");
49  for (i=0; i<argc; i++) {
50    if ((item = PySequence_GetItem(client_args, i)) == NULL) {
51      ndg_argv_clear(&argv_s); ndg_argv_free(&argv_s);
52      Py_DECREF(client_args);
53      return NULL;
54    }
55    if ((arg = PyString_AsString(item)) == NULL) {
56      ndg_argv_clear(&argv_s); ndg_argv_free(&argv_s);
57      Py_DECREF(item);
58      Py_DECREF(client_args);
59      return NULL;
60    }
61
62    if (!ndg_argv_add(&argv_s, arg)) {
63      PyErr_SetString(PyExc_MemoryError, "ndg_argv_add failed");
64      ndg_argv_clear(&argv_s); ndg_argv_free(&argv_s);
65      Py_DECREF(item);
66      Py_DECREF(client_args);
67      return NULL;
68    }
69
70    Py_DECREF(item);
71
72  }
73  Py_DECREF(client_args);
74
75  bbftpc_main(argv_s.argc, argv_s.argv, environ);
76  ndg_argv_clear(&argv_s); ndg_argv_free(&argv_s);
77
78  Py_RETURN_NONE;
79}
80
81static PyMethodDef BbftpcMethods[] = {
82  {
83    "run", bbftpc_run, METH_VARARGS,
84    "Execute the bbftp client.\n"
85    "\n"
86    "@param args: command line arguments"
87  },
88  {NULL, NULL, 0, NULL}
89};
90
91PyMODINIT_FUNC initbbftpc(void) {
92  (void) Py_InitModule("bbftpc", BbftpcMethods);
93}
Note: See TracBrowser for help on using the repository browser.