forked from IBMSpectrumComputing/lsf-python-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsf.i
More file actions
executable file
·332 lines (271 loc) · 7.99 KB
/
lsf.i
File metadata and controls
executable file
·332 lines (271 loc) · 7.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/*
* (C) Copyright IBM Corporation 2013
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Eclipse Public License.
*
*/
/* File: lsf.i */
%module lsf
%include "cpointer.i"
%include "carrays.i"
FILE *fopen(char *filename, char *mode);
int fclose(FILE *f);
%{
#define SWIG_FILE_WITH_INIT
#include "lsf.h"
#include "lsbatch.h"
%}
%pointer_functions(int, intp)
%pointer_functions(float, floatp)
%pointer_functions(long, longp)
%pointer_functions(LS_LONG_INT, LS_LONG_INT_POINTER)
%array_functions(int, intArray)
%array_functions(float, floatArray)
%array_functions(char *, stringArray)
%array_functions(struct dependJobs, dependJobsArray)
%array_functions(long, longArray)
//helper function for transforming char** to python list
%inline %{
PyObject * char_p_p_to_pylist(PyObject* ptrobj, int size){
void* cptr = 0;
int res = 0;
PyObject * list = 0;
int i = 0;
res = SWIG_ConvertPtr(ptrobj, &cptr,SWIGTYPE_p_p_char, 0);
if (!SWIG_IsOK(res)) {
PyErr_SetString(PyExc_TypeError,"not a SWIGTYPE_p_p_char");
return NULL;
}
list = PyList_New(size);
for (i = 0; i < size; i++) {
PyList_SetItem(list,i,PyString_FromString(((char**)cptr)[i]));
}
return list;
}
PyObject * string_array_to_pylist(PyObject* ptrobj, int size){
return char_p_p_to_pylist(ptrobj,size);
}
%}
%array_class(struct queueInfoEnt, queueInfoEntArray);
%array_class(struct hostInfoEnt, hostInfoEntArray);
%array_class(struct hostLoad, hostLoadArray);
// handle int arrays
%typemap(in) int [ANY] (int temp[$1_dim0]) {
int i;
for (i = 0; i < $1_dim0; i++) {
PyObject *o = PySequence_GetItem($input,i);
temp[i] = (int) PyInt_AsLong(o);
}
$1 = temp;
}
// See github issue 1
//%typemap(freearg) int [ANY] {
// free((int *) $1);
//}
%typemap(out) int [ANY] {
int i;
$result = PyList_New($1_dim0);
for (i = 0; i < $1_dim0; i++) {
PyObject *o = PyLong_FromDouble((int) $1[i]);
PyList_SetItem($result,i,o);
}
}
// typemap for time_t
%typemap(in) time_t {
$1 = (time_t) PyLong_AsLong($input);
}
%typemap(freearg) time_t {
if ($1) free((time_t *) $1);
}
%typemap(out) time_t {
$result = PyLong_FromLong((long)$1);
}
%typemap(arginit) time_t {
$1 = 0;
}
/*
The following routines are not wrapped because SWIG has issues generating
proper code for them
*/
// Following are ignored from lsf.h
%ignore getBEtime;
%ignore ls_gethostrespriority;
%ignore ls_loadoftype;
%ignore ls_lostconnection;
%ignore ls_nioclose;
%ignore ls_nioctl;
%ignore ls_niodump;
%ignore ls_nioinit;
%ignore ls_niokill;
%ignore ls_nionewtask;
%ignore ls_nioread;
%ignore ls_nioremovetask;
%ignore ls_nioselect;
%ignore ls_niosetdebug;
%ignore ls_niostatus;
%ignore ls_niotasks;
%ignore ls_niowrite;
%ignore ls_placeoftype;
%ignore ls_readrexlog;
%ignore ls_verrlog;
%ignore lsb_globalpolicy;
%ignore lsb_jobidindex2str;
%ignore LOG_VERSION;
%ignore ls_errmsg;
// Following are ignored from lsbatch.h
%ignore lsb_readstatusline;
// Now include the rest...
%include "lsf.h"
%include "lsbatch.h"
%inline %{
PyObject * get_host_names() {
struct hostInfo *hostinfo;
char *resreq;
int numhosts = 0;
int options = 0;
resreq="";
hostinfo = ls_gethostinfo(resreq, &numhosts, NULL, 0, options);
PyObject *result = PyList_New(numhosts);
int i;
for (i = 0; i < numhosts; i++) {
PyObject *o = PyString_FromString(hostinfo[i].hostName);
PyList_SetItem(result,i,o);
}
return result;
}
PyObject * get_host_info() {
struct hostInfo *hostinfo;
char *resreq;
int numhosts = 0;
int options = 0;
resreq = "";
hostinfo = ls_gethostinfo(resreq, &numhosts, NULL, 0, options);
PyObject *result = PyList_New(numhosts);
int i;
for (i = 0; i < numhosts; i++) {
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(&hostinfo[i]),
SWIGTYPE_p_hostInfo, 0 | 0 );
PyList_SetItem(result,i,o);
}
return result;
}
/* taken form stdio.h */
#define SEEK_SET 0 /* Seek from beginning of file. */
#define SEEK_CUR 1 /* Seek from current position. */
#define SEEK_END 2 /* Seek from end of file. */
PyObject * lsb_fseek(PyObject *obj0, PyObject *obj1, PyObject *obj2){
FILE *arg1 = (FILE *) 0 ;
void *argp1 = 0 ;
long val2 = 0 ;
int val3 = 0 ;
int res1 = 0 ;
int res2 = 0 ;
int res3 = 0 ;
PyObject *resultobj = 0;
int result;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_FILE, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "fseek" "', argument " "1"" of type '" "FILE *""'");
}
arg1 = (FILE *)(argp1);
res2 = SWIG_AsVal_long(obj1, &val2 );
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "fseek" "', argument " "2"" of type '" "long *""'");
}
res3 = SWIG_AsVal_int(obj2, &val3 );
if (!SWIG_IsOK(res3)) {
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "fseek" "', argument " "3"" of type '" "int *""'");
}
result = (int)fseek(arg1,val2,val3);
resultobj = SWIG_From_int((int)(result));
return resultobj;
fail:
return NULL;
}
PyObject * lsb_ftell(PyObject *obj0){
FILE *arg1 = (FILE *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *resultobj = 0;
long result;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_FILE, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "fseek" "', argument " "1"" of type '" "FILE *""'");
}
arg1 = (FILE *)(argp1);
result = (long)ftell(arg1);
resultobj = SWIG_From_long((long)(result));
return resultobj;
fail:
return NULL;
}
PyObject * get_load_of_hosts() {
struct hostLoad *hostload;
char *resreq;
int numhosts = 0;
resreq = "";
hostload = ls_loadofhosts(resreq, &numhosts, 0, NULL, NULL, 0);
PyObject *result = PyList_New(numhosts);
int i;
for (i = 0; i < numhosts; i++) {
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(&hostload[i]),
SWIGTYPE_p_hostLoad, 0 | 0 );
PyList_SetItem(result,i,o);
}
return result;
}
PyObject * get_host_load(char *resreq, int index) {
struct hostLoad *hosts;
int numhosts = 0;
int options = 0;
char *fromhost = NULL;
hosts = ls_load(resreq, &numhosts, options, fromhost);
if (hosts == NULL || numhosts > 1) {
ls_perror("ls_load");
exit(-1);
}
PyObject *result = PyFloat_FromDouble(hosts[0].li[index]);
return result;
}
PyObject * get_queue_info_by_name(char** name, int num) {
struct queueInfoEnt* queueinfo;
int numqueues = num;
int options = 0;
queueinfo = lsb_queueinfo(name, &numqueues, NULL, 0, options);
PyObject *result = PyList_New(numqueues);
int i;
for (i = 0; i < numqueues; i++) {
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(&queueinfo[i]),
SWIGTYPE_p_queueInfoEnt, 0 | 0 );
PyList_SetItem(result,i,o);
}
return result;
}
PyObject * get_hostgroup_info_by_name(char** name, int num) {
struct groupInfoEnt* hostgroupinfo;
int numgroups = num;
int options = 0;
hostgroupinfo = lsb_hostgrpinfo(name, &numgroups, options);
PyObject *result = PyList_New(numgroups);
int i;
for (i = 0; i < numgroups; i++) {
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(&hostgroupinfo[i]),
SWIGTYPE_p_groupInfoEnt, 0 | 0 );
PyList_SetItem(result,i,o);
}
return result;
}
PyObject * get_conf_value(char *name, char *path) {
struct config_param param[2];
param[0].paramName = name;
param[0].paramValue = NULL;
param[1].paramName = NULL;
param[1].paramValue = NULL;
if (ls_readconfenv(¶m[0],path) == 0) {
return Py_BuildValue("s", param[0].paramValue);
} else {
Py_RETURN_NONE;
}
}
%}