1
/* -*- mode: C; c-basic-offset: 4 -*- */
3
#include "pygnomevfs-private.h"
4
#include <libgnomevfs/gnome-vfs-utils.h>
5
#include <libgnomevfs/gnome-vfs-find-directory.h>
6
#include <libgnomevfs/gnome-vfs-address.h>
7
#include <libgnomevfs/gnome-vfs-resolve.h>
8
#include <libgnomevfs/gnome-vfs-dns-sd.h>
11
static GHashTable *monitor_hash;
12
static gint monitor_id_counter = 0;
14
static PyObject *pygnomevfs_exc;
15
static PyObject *pygnomevfs_not_found_exc;
16
static PyObject *pygnomevfs_generic_exc;
17
static PyObject *pygnomevfs_internal_exc;
18
static PyObject *pygnomevfs_bad_parameters_exc;
19
static PyObject *pygnomevfs_not_supported_exc;
20
static PyObject *pygnomevfs_io_exc;
21
static PyObject *pygnomevfs_corrupted_data_exc;
22
static PyObject *pygnomevfs_wrong_format_exc;
23
static PyObject *pygnomevfs_bad_file_exc;
24
static PyObject *pygnomevfs_too_big_exc;
25
static PyObject *pygnomevfs_no_space_exc;
26
static PyObject *pygnomevfs_read_only_exc;
27
static PyObject *pygnomevfs_invalid_uri_exc;
28
static PyObject *pygnomevfs_not_open_exc;
29
static PyObject *pygnomevfs_invalid_open_mode_exc;
30
static PyObject *pygnomevfs_access_denied_exc;
31
static PyObject *pygnomevfs_too_many_open_files_exc;
32
static PyObject *pygnomevfs_eof_exc;
33
static PyObject *pygnomevfs_not_a_directory_exc;
34
static PyObject *pygnomevfs_in_progress_exc;
35
static PyObject *pygnomevfs_interrupted_exc;
36
static PyObject *pygnomevfs_file_exists_exc;
37
static PyObject *pygnomevfs_loop_exc;
38
static PyObject *pygnomevfs_not_permitted_exc;
39
static PyObject *pygnomevfs_is_directory_exc;
40
static PyObject *pygnomevfs_no_memory_exc;
41
static PyObject *pygnomevfs_host_not_found_exc;
42
static PyObject *pygnomevfs_invalid_host_name_exc;
43
static PyObject *pygnomevfs_host_has_no_address_exc;
44
static PyObject *pygnomevfs_login_failed_exc;
45
static PyObject *pygnomevfs_cancelled_exc;
46
static PyObject *pygnomevfs_directory_busy_exc;
47
static PyObject *pygnomevfs_directory_not_empty_exc;
48
static PyObject *pygnomevfs_too_many_links_exc;
49
static PyObject *pygnomevfs_read_only_file_system_exc;
50
static PyObject *pygnomevfs_not_same_file_system_exc;
51
static PyObject *pygnomevfs_name_too_long_exc;
52
static PyObject *pygnomevfs_service_not_available_exc;
53
static PyObject *pygnomevfs_service_obsolete_exc;
54
static PyObject *pygnomevfs_protocol_error_exc;
55
static PyObject *pygnomevfs_no_master_browser_exc;
57
static PyObject *pygnomevfs_no_default_exc;
58
static PyObject *pygnomevfs_no_handler_exc;
59
static PyObject *pygnomevfs_parse_exc;
60
static PyObject *pygnomevfs_launch_exc;
63
static PyTypeObject *_PyGObject_Type;
64
#define PyGObject_Type (*_PyGObject_Type)
67
extern void pygvvolume_add_constants(PyObject *m);
71
pygnome_vfs_result_check(GnomeVFSResult result)
76
if(result == GNOME_VFS_OK)
81
case GNOME_VFS_ERROR_NOT_FOUND:
82
exc = pygnomevfs_not_found_exc;
84
case GNOME_VFS_ERROR_GENERIC:
85
exc = pygnomevfs_generic_exc;
87
case GNOME_VFS_ERROR_INTERNAL:
88
exc = pygnomevfs_internal_exc;
90
case GNOME_VFS_ERROR_BAD_PARAMETERS:
91
exc = pygnomevfs_bad_parameters_exc;
93
case GNOME_VFS_ERROR_NOT_SUPPORTED:
94
exc = pygnomevfs_not_supported_exc;
96
case GNOME_VFS_ERROR_IO:
97
exc = pygnomevfs_io_exc;
99
case GNOME_VFS_ERROR_CORRUPTED_DATA:
100
exc = pygnomevfs_corrupted_data_exc;
102
case GNOME_VFS_ERROR_WRONG_FORMAT:
103
exc = pygnomevfs_wrong_format_exc;
105
case GNOME_VFS_ERROR_BAD_FILE:
106
exc = pygnomevfs_bad_file_exc;
108
case GNOME_VFS_ERROR_TOO_BIG:
109
exc = pygnomevfs_too_big_exc;
111
case GNOME_VFS_ERROR_NO_SPACE:
112
exc = pygnomevfs_no_space_exc;
114
case GNOME_VFS_ERROR_READ_ONLY:
115
exc = pygnomevfs_read_only_exc;
117
case GNOME_VFS_ERROR_INVALID_URI:
118
exc = pygnomevfs_invalid_uri_exc;
120
case GNOME_VFS_ERROR_NOT_OPEN:
121
exc = pygnomevfs_not_open_exc;
123
case GNOME_VFS_ERROR_INVALID_OPEN_MODE:
124
exc = pygnomevfs_invalid_open_mode_exc;
126
case GNOME_VFS_ERROR_ACCESS_DENIED:
127
exc = pygnomevfs_access_denied_exc;
129
case GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES:
130
exc = pygnomevfs_too_many_open_files_exc;
132
case GNOME_VFS_ERROR_EOF:
133
exc = pygnomevfs_eof_exc;
135
case GNOME_VFS_ERROR_NOT_A_DIRECTORY:
136
exc = pygnomevfs_not_a_directory_exc;
138
case GNOME_VFS_ERROR_IN_PROGRESS:
139
exc = pygnomevfs_in_progress_exc;
141
case GNOME_VFS_ERROR_INTERRUPTED:
142
exc = pygnomevfs_interrupted_exc;
144
case GNOME_VFS_ERROR_FILE_EXISTS:
145
exc = pygnomevfs_file_exists_exc;
147
case GNOME_VFS_ERROR_LOOP:
148
exc = pygnomevfs_loop_exc;
150
case GNOME_VFS_ERROR_NOT_PERMITTED:
151
exc = pygnomevfs_not_permitted_exc;
153
case GNOME_VFS_ERROR_IS_DIRECTORY:
154
exc = pygnomevfs_is_directory_exc;
156
case GNOME_VFS_ERROR_NO_MEMORY:
157
exc = pygnomevfs_no_memory_exc;
159
case GNOME_VFS_ERROR_HOST_NOT_FOUND:
160
exc = pygnomevfs_host_not_found_exc;
162
case GNOME_VFS_ERROR_INVALID_HOST_NAME:
163
exc = pygnomevfs_invalid_host_name_exc;
165
case GNOME_VFS_ERROR_HOST_HAS_NO_ADDRESS:
166
exc = pygnomevfs_host_has_no_address_exc;
168
case GNOME_VFS_ERROR_LOGIN_FAILED:
169
exc = pygnomevfs_login_failed_exc;
171
case GNOME_VFS_ERROR_CANCELLED:
172
exc = pygnomevfs_cancelled_exc;
174
case GNOME_VFS_ERROR_DIRECTORY_BUSY:
175
exc = pygnomevfs_directory_busy_exc;
177
case GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY:
178
exc = pygnomevfs_directory_not_empty_exc;
180
case GNOME_VFS_ERROR_TOO_MANY_LINKS:
181
exc = pygnomevfs_too_many_links_exc;
183
case GNOME_VFS_ERROR_READ_ONLY_FILE_SYSTEM:
184
exc = pygnomevfs_read_only_file_system_exc;
186
case GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM:
187
exc = pygnomevfs_not_same_file_system_exc;
189
case GNOME_VFS_ERROR_NAME_TOO_LONG:
190
exc = pygnomevfs_name_too_long_exc;
192
case GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE:
193
exc = pygnomevfs_service_not_available_exc;
195
case GNOME_VFS_ERROR_SERVICE_OBSOLETE:
196
exc = pygnomevfs_service_obsolete_exc;
198
case GNOME_VFS_ERROR_PROTOCOL_ERROR:
199
exc = pygnomevfs_protocol_error_exc;
201
case GNOME_VFS_ERROR_NO_MASTER_BROWSER:
202
exc = pygnomevfs_no_master_browser_exc;
205
case GNOME_VFS_ERROR_NO_DEFAULT:
206
exc = pygnomevfs_no_default_exc;
208
case GNOME_VFS_ERROR_NO_HANDLER:
209
exc = pygnomevfs_no_handler_exc;
211
case GNOME_VFS_ERROR_PARSE:
212
exc = pygnomevfs_parse_exc;
214
case GNOME_VFS_ERROR_LAUNCH:
215
exc = pygnomevfs_launch_exc;
227
msg = gnome_vfs_result_to_string(result);
228
PyErr_SetString(exc, (char*)msg);
236
GnomeVFSResult pygnome_vfs_exception_check(void)
238
if (!PyErr_Occurred()) {
242
if (PyErr_ExceptionMatches(pygnomevfs_not_found_exc)) {
243
return GNOME_VFS_ERROR_NOT_FOUND;
244
} else if (PyErr_ExceptionMatches(pygnomevfs_generic_exc)) {
245
return GNOME_VFS_ERROR_GENERIC;
246
} else if (PyErr_ExceptionMatches(pygnomevfs_internal_exc)) {
247
return GNOME_VFS_ERROR_INTERNAL;
248
} else if (PyErr_ExceptionMatches(pygnomevfs_bad_parameters_exc)) {
249
return GNOME_VFS_ERROR_BAD_FILE;
250
} else if (PyErr_ExceptionMatches(pygnomevfs_not_supported_exc)) {
251
return GNOME_VFS_ERROR_NOT_SUPPORTED;
252
} else if (PyErr_ExceptionMatches(pygnomevfs_io_exc)) {
253
return GNOME_VFS_ERROR_IO;
254
} else if (PyErr_ExceptionMatches(pygnomevfs_corrupted_data_exc)) {
255
return GNOME_VFS_ERROR_CORRUPTED_DATA;
256
} else if (PyErr_ExceptionMatches(pygnomevfs_wrong_format_exc)) {
257
return GNOME_VFS_ERROR_WRONG_FORMAT;
258
} else if (PyErr_ExceptionMatches(pygnomevfs_bad_file_exc)) {
259
return GNOME_VFS_ERROR_BAD_FILE;
260
} else if (PyErr_ExceptionMatches(pygnomevfs_too_big_exc)) {
261
return GNOME_VFS_ERROR_TOO_BIG;
262
} else if (PyErr_ExceptionMatches(pygnomevfs_no_space_exc)) {
263
return GNOME_VFS_ERROR_NO_SPACE;
264
} else if (PyErr_ExceptionMatches(pygnomevfs_read_only_exc)) {
265
return GNOME_VFS_ERROR_READ_ONLY;
266
} else if (PyErr_ExceptionMatches(pygnomevfs_invalid_uri_exc)) {
267
return GNOME_VFS_ERROR_INVALID_URI;
268
} else if (PyErr_ExceptionMatches(pygnomevfs_not_open_exc)) {
269
return GNOME_VFS_ERROR_NOT_OPEN;
270
} else if (PyErr_ExceptionMatches(pygnomevfs_invalid_open_mode_exc)) {
271
return GNOME_VFS_ERROR_INVALID_OPEN_MODE;
272
} else if (PyErr_ExceptionMatches(pygnomevfs_access_denied_exc)) {
273
return GNOME_VFS_ERROR_ACCESS_DENIED;
274
} else if (PyErr_ExceptionMatches(pygnomevfs_too_many_open_files_exc)) {
275
return GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES;
276
} else if (PyErr_ExceptionMatches(pygnomevfs_eof_exc)) {
277
return GNOME_VFS_ERROR_EOF;
278
} else if (PyErr_ExceptionMatches(pygnomevfs_not_a_directory_exc)) {
279
return GNOME_VFS_ERROR_NOT_A_DIRECTORY;
280
} else if (PyErr_ExceptionMatches(pygnomevfs_in_progress_exc)) {
281
return GNOME_VFS_ERROR_IN_PROGRESS;
282
} else if (PyErr_ExceptionMatches(pygnomevfs_interrupted_exc)) {
283
return GNOME_VFS_ERROR_INTERRUPTED;
284
} else if (PyErr_ExceptionMatches(pygnomevfs_file_exists_exc)) {
285
return GNOME_VFS_ERROR_FILE_EXISTS;
286
} else if (PyErr_ExceptionMatches(pygnomevfs_loop_exc)) {
287
return GNOME_VFS_ERROR_LOOP;
288
} else if (PyErr_ExceptionMatches(pygnomevfs_not_permitted_exc)) {
289
return GNOME_VFS_ERROR_NOT_PERMITTED;
290
} else if (PyErr_ExceptionMatches(pygnomevfs_is_directory_exc)) {
291
return GNOME_VFS_ERROR_IS_DIRECTORY;
292
} else if (PyErr_ExceptionMatches(pygnomevfs_no_memory_exc)) {
293
return GNOME_VFS_ERROR_NO_MEMORY;
294
} else if (PyErr_ExceptionMatches(pygnomevfs_host_not_found_exc)) {
295
return GNOME_VFS_ERROR_HOST_NOT_FOUND;
296
} else if (PyErr_ExceptionMatches(pygnomevfs_invalid_host_name_exc)) {
297
return GNOME_VFS_ERROR_INVALID_HOST_NAME;
298
} else if (PyErr_ExceptionMatches(pygnomevfs_host_has_no_address_exc)) {
299
return GNOME_VFS_ERROR_HOST_HAS_NO_ADDRESS;
300
} else if (PyErr_ExceptionMatches(pygnomevfs_login_failed_exc)) {
301
return GNOME_VFS_ERROR_LOGIN_FAILED;
302
} else if (PyErr_ExceptionMatches(pygnomevfs_cancelled_exc)) {
303
return GNOME_VFS_ERROR_CANCELLED;
304
} else if (PyErr_ExceptionMatches(pygnomevfs_directory_busy_exc)) {
305
return GNOME_VFS_ERROR_DIRECTORY_BUSY;
306
} else if (PyErr_ExceptionMatches(pygnomevfs_directory_not_empty_exc)) {
307
return GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY;
308
} else if (PyErr_ExceptionMatches(pygnomevfs_too_many_links_exc)) {
309
return GNOME_VFS_ERROR_TOO_MANY_LINKS;
310
} else if (PyErr_ExceptionMatches(pygnomevfs_read_only_file_system_exc)) {
311
return GNOME_VFS_ERROR_READ_ONLY_FILE_SYSTEM;
312
} else if (PyErr_ExceptionMatches(pygnomevfs_not_same_file_system_exc)) {
313
return GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM;
314
} else if (PyErr_ExceptionMatches(pygnomevfs_name_too_long_exc)) {
315
return GNOME_VFS_ERROR_NAME_TOO_LONG;
316
} else if (PyErr_ExceptionMatches(pygnomevfs_service_not_available_exc)) {
317
return GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE;
318
} else if (PyErr_ExceptionMatches(pygnomevfs_service_obsolete_exc)) {
319
return GNOME_VFS_ERROR_SERVICE_OBSOLETE;
320
} else if (PyErr_ExceptionMatches(pygnomevfs_protocol_error_exc)) {
321
return GNOME_VFS_ERROR_PROTOCOL_ERROR;
322
} else if (PyErr_ExceptionMatches(pygnomevfs_no_master_browser_exc)) {
323
return GNOME_VFS_ERROR_NO_MASTER_BROWSER;
330
pygvfs_create(PyObject *self, PyObject *args, PyObject *kwargs)
332
static char *kwlist[] = { "uri", "open_mode", "exclusive", "perm", NULL };
334
GnomeVFSOpenMode open_mode = GNOME_VFS_OPEN_NONE;
335
gboolean exclusive = FALSE;
337
GnomeVFSHandle *handle;
338
GnomeVFSResult result;
340
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iii:gnomevfs.create",
341
kwlist, &uri, &open_mode, &exclusive,
345
if (PyObject_TypeCheck(uri, &PyGnomeVFSURI_Type)) {
346
pyg_begin_allow_threads;
347
result = gnome_vfs_create_uri(&handle, pygnome_vfs_uri_get(uri),
348
open_mode, exclusive, perm);
349
pyg_end_allow_threads;
350
} else if (PyString_Check(uri)) {
351
pyg_begin_allow_threads;
352
result = gnome_vfs_create(&handle, PyString_AsString(uri),
353
open_mode, exclusive, perm);
354
pyg_end_allow_threads;
356
PyErr_SetString(PyExc_TypeError,
357
"uri must be a gnomevfs.URI or a string");
361
if (pygnome_vfs_result_check(result))
364
return pygnome_vfs_handle_new(handle);
368
pygvfs_get_file_info(PyObject *self, PyObject *args, PyObject *kwargs)
370
static char *kwlist[] = { "uri", "options", NULL };
372
GnomeVFSFileInfo *finfo;
373
GnomeVFSFileInfoOptions options = GNOME_VFS_FILE_INFO_DEFAULT;
374
GnomeVFSResult result;
376
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
377
"O|i:gnomevfs.get_file_info",
378
kwlist, &uri, &options))
381
finfo = gnome_vfs_file_info_new();
382
if (PyObject_TypeCheck(uri, &PyGnomeVFSURI_Type)) {
383
pyg_begin_allow_threads;
384
result = gnome_vfs_get_file_info_uri(pygnome_vfs_uri_get(uri), finfo,
386
pyg_end_allow_threads;
387
} else if (PyString_Check(uri)) {
388
pyg_begin_allow_threads;
389
result = gnome_vfs_get_file_info(PyString_AsString(uri), finfo,
391
pyg_end_allow_threads;
393
PyErr_SetString(PyExc_TypeError,
394
"uri must be a gnomevfs.URI or a string");
395
gnome_vfs_file_info_unref(finfo);
399
if (pygnome_vfs_result_check(result)) {
400
gnome_vfs_file_info_unref(finfo);
403
return pygnome_vfs_file_info_new(finfo);
407
pygvfs_set_file_info(PyObject *self, PyObject *args, PyObject *kwargs)
409
static char *kwlist[] = { "uri", "info", "mask", NULL };
411
PyGnomeVFSFileInfo *finfo;
412
GnomeVFSSetFileInfoMask mask = GNOME_VFS_SET_FILE_INFO_NONE;
413
GnomeVFSResult result;
415
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
416
"OO!i:gnomevfs.set_file_info",
418
&PyGnomeVFSFileInfo_Type, &finfo,
422
if (PyObject_TypeCheck(uri, &PyGnomeVFSURI_Type)) {
423
pyg_begin_allow_threads;
424
result = gnome_vfs_set_file_info_uri(pygnome_vfs_uri_get(uri),
426
pyg_end_allow_threads;
427
} else if (PyString_Check(uri)) {
428
pyg_begin_allow_threads;
429
result = gnome_vfs_set_file_info(PyString_AsString(uri),
431
pyg_end_allow_threads;
433
PyErr_SetString(PyExc_TypeError,
434
"uri must be a gnomevfs.URI or a string");
437
if (pygnome_vfs_result_check(result))
445
pygvfs_truncate(PyObject *self, PyObject *args, PyObject *kwargs)
447
static char *kwlist[] = { "uri", "length", NULL };
448
PyObject *uri, *py_length;
449
GnomeVFSFileSize length;
450
GnomeVFSResult result;
452
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO:gnomevfs.truncate",
453
kwlist, &uri, &py_length))
456
length = PyLong_Check(py_length) ? PyLong_AsUnsignedLongLong(py_length)
457
: PyInt_AsLong(py_length);
458
if (PyErr_Occurred()) return NULL;
460
if (PyObject_TypeCheck(uri, &PyGnomeVFSURI_Type))
461
result = gnome_vfs_truncate_uri(pygnome_vfs_uri_get(uri), length);
462
else if (PyString_Check(uri))
463
result = gnome_vfs_truncate(PyString_AsString(uri), length);
465
PyErr_SetString(PyExc_TypeError,
466
"uri must be a gnomevfs.URI or a string");
470
if (pygnome_vfs_result_check(result))
478
pygvfs_make_directory(PyObject *self, PyObject *args, PyObject *kwargs)
480
static char *kwlist[] = { "uri", "perm", NULL };
483
GnomeVFSResult result;
485
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
486
"Oi:gnomevfs.make_directory", kwlist,
490
if (PyObject_TypeCheck(uri, &PyGnomeVFSURI_Type)) {
491
pyg_begin_allow_threads;
492
result = gnome_vfs_make_directory_for_uri(pygnome_vfs_uri_get(uri),
494
pyg_end_allow_threads;
495
} else if (PyString_Check(uri)) {
496
pyg_begin_allow_threads;
497
result = gnome_vfs_make_directory(PyString_AsString(uri), perm);
498
pyg_end_allow_threads;
500
PyErr_SetString(PyExc_TypeError,
501
"uri must be a gnomevfs.URI or a string");
505
if (pygnome_vfs_result_check(result))
513
pygvfs_remove_directory(PyObject *self, PyObject *args, PyObject *kwargs)
515
static char *kwlist[] = { "uri", NULL };
517
GnomeVFSResult result;
519
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
520
"O:gnomevfs.remove_directory", kwlist,
524
if (PyObject_TypeCheck(uri, &PyGnomeVFSURI_Type)) {
525
pyg_begin_allow_threads;
526
result = gnome_vfs_remove_directory_from_uri(pygnome_vfs_uri_get(uri));
527
pyg_end_allow_threads;
528
} else if (PyString_Check(uri)) {
529
pyg_begin_allow_threads;
530
result = gnome_vfs_remove_directory(PyString_AsString(uri));
531
pyg_end_allow_threads;
533
PyErr_SetString(PyExc_TypeError,
534
"uri must be a gnomevfs.URI or a string");
538
if (pygnome_vfs_result_check(result))
546
pygvfs_unlink(PyObject *self, PyObject *args, PyObject *kwargs)
548
static char *kwlist[] = { "uri", NULL };
550
GnomeVFSResult result;
552
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
553
"O:gnomevfs.unlink", kwlist, &uri))
556
if (PyObject_TypeCheck(uri, &PyGnomeVFSURI_Type)) {
557
pyg_begin_allow_threads;
558
result = gnome_vfs_unlink_from_uri(pygnome_vfs_uri_get(uri));
559
pyg_end_allow_threads;
560
} else if (PyString_Check(uri)) {
561
pyg_begin_allow_threads;
562
result = gnome_vfs_unlink(PyString_AsString(uri));
563
pyg_end_allow_threads;
565
PyErr_SetString(PyExc_TypeError,
566
"uri must be a gnomevfs.URI or a string");
570
if (pygnome_vfs_result_check(result))
578
pygvfs_exists(PyObject *self, PyObject *args, PyObject *kwargs)
580
static char *kwlist[] = { "uri", NULL };
582
GnomeVFSURI *uri = NULL;
585
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:gnomevfs.exists",
589
if (PyObject_TypeCheck(py_uri, &PyGnomeVFSURI_Type)) {
590
pyg_begin_allow_threads;
591
uri = gnome_vfs_uri_ref(pygnome_vfs_uri_get(py_uri));
592
pyg_end_allow_threads;
593
} else if (PyString_Check(py_uri)) {
594
pyg_begin_allow_threads;
595
uri = gnome_vfs_uri_new(PyString_AsString(py_uri));
596
pyg_end_allow_threads;
599
PyErr_SetString(PyExc_TypeError,
600
"uri must be a gnomevfs.URI or a string");
603
exists = gnome_vfs_uri_exists(uri);
604
gnome_vfs_uri_unref(uri);
606
return PyInt_FromLong(exists);
610
pygvfs_get_mime_type(PyObject *self, PyObject *args)
612
char *text_uri, *mime;
614
if(!PyArg_ParseTuple(args, "s:gnomevfs.get_mime_type",
618
pyg_begin_allow_threads;
619
mime = gnome_vfs_get_mime_type(text_uri);
620
pyg_end_allow_threads;
622
return PyString_FromString(mime);
624
PyErr_SetString(PyExc_RuntimeError,
625
"there was an error reading the file");
631
pygvfs_get_mime_type_for_data(PyObject *self, PyObject *args)
635
int data_size, data_size1 = -G_MAXINT;
637
if(!PyArg_ParseTuple(args, "s#|i:gnomevfs.get_mime_type_for_data",
638
&data, &data_size, &data_size1))
640
if (data_size1 != -G_MAXINT)
641
PyErr_Warn(PyExc_DeprecationWarning, "ignoring deprecated argument data_size");
642
pyg_begin_allow_threads;
643
mime = gnome_vfs_get_mime_type_for_data(data, data_size);
644
pyg_end_allow_threads;
646
return PyString_FromString(mime);
648
PyErr_SetString(PyExc_RuntimeError,
649
"there was an error reading the file");
655
pygvfs_mime_get_icon(PyObject *self, PyObject *args)
660
if(!PyArg_ParseTuple(args, "s:gnomevfs.mime_get_icon",
664
retval = gnome_vfs_mime_get_icon(mime_type);
665
if (retval == NULL) {
669
return PyString_FromString(retval);
673
pygvfs_mime_set_icon(PyObject *self, PyObject *args)
675
char *mime_type, *filename;
676
GnomeVFSResult result;
678
if(!PyArg_ParseTuple(args, "ss:gnomevfs.mime_set_icon",
679
&mime_type, &filename))
682
result = gnome_vfs_mime_set_icon(mime_type, filename);
683
if (pygnome_vfs_result_check(result)) {
692
pygvfs_mime_get_description(PyObject *self, PyObject *args)
695
const char *description;
697
if(!PyArg_ParseTuple(args, "s:gnomevfs.mime_get_description",
700
description = gnome_vfs_mime_get_description(mime_type);
702
return PyString_FromString(description);
710
pygvfs_mime_set_description(PyObject *self, PyObject *args)
712
char *mime_type, *description;
713
GnomeVFSResult result;
715
if(!PyArg_ParseTuple(args, "ss:gnomevfs.mime_set_description",
716
&mime_type, &description))
719
result = gnome_vfs_mime_set_description(mime_type, description);
720
if (pygnome_vfs_result_check(result)) {
729
pygvfs_mime_can_be_executable(PyObject *self, PyObject *args)
733
if(!PyArg_ParseTuple(args, "s:gnomevfs.mime_can_be_executable",
737
return PyInt_FromLong(gnome_vfs_mime_can_be_executable(mime_type));
741
pygvfs_mime_set_can_be_executable(PyObject *self, PyObject *args)
745
GnomeVFSResult result;
747
if(!PyArg_ParseTuple(args, "si:gnomevfs.mime_set_description",
748
&mime_type, &new_value))
751
result = gnome_vfs_mime_set_can_be_executable(mime_type, new_value);
752
if (pygnome_vfs_result_check(result)) {
761
pygvfs_monitor_marshal(GnomeVFSMonitorHandle *handle,
762
const gchar *monitor_uri,
763
const gchar *info_uri,
764
GnomeVFSMonitorEventType event_type,
765
PyGVFSCustomNotify *cunote)
768
PyGILState_STATE state;
770
state = pyg_gil_state_ensure();
773
retobj = PyEval_CallFunction(cunote->func, "(ssiO)", monitor_uri,
774
info_uri, event_type, cunote->data);
776
retobj = PyObject_CallFunction(cunote->func, "(ssi)", monitor_uri,
777
info_uri, event_type);
779
if (retobj == NULL) {
786
pyg_gil_state_release(state);
790
pygvfs_monitor_add(PyObject *self, PyObject *args)
795
PyObject *extra = NULL;
796
PyGVFSCustomNotify *cunote;
797
GnomeVFSMonitorHandle *handle;
798
GnomeVFSResult result;
801
if (!PyArg_ParseTuple(args, "siO|O:gnomevfs.monitor_add",
802
&text_uri, &monitor_type,
803
&callback, &extra)) {
807
if (!PyCallable_Check(callback)) {
808
PyErr_SetString(PyExc_TypeError, "third argument not callable");
812
cunote = g_new0(PyGVFSCustomNotify, 1);
813
cunote->func = callback;
814
cunote->data = extra;
815
Py_INCREF(cunote->func);
816
Py_XINCREF(cunote->data);
817
pyg_begin_allow_threads;
818
result = gnome_vfs_monitor_add(&handle, text_uri, monitor_type,
819
(GnomeVFSMonitorCallback)pygvfs_monitor_marshal,
821
pyg_end_allow_threads;
823
if (pygnome_vfs_result_check(result)) {
828
monitor_id = ++monitor_id_counter;
829
while (g_hash_table_lookup(monitor_hash, GINT_TO_POINTER(monitor_id)));
831
g_hash_table_insert(monitor_hash,
832
GINT_TO_POINTER(monitor_id),
835
return PyInt_FromLong(monitor_id);
839
pygvfs_monitor_cancel(PyObject *self, PyObject *args)
842
GnomeVFSMonitorHandle *handle;
844
if (!PyArg_ParseTuple(args, "i:gnomevfs.monitor_cancel",
849
handle = g_hash_table_lookup(monitor_hash, GINT_TO_POINTER(monitor_id));
850
if (handle == NULL) {
851
PyErr_SetString(PyExc_ValueError, "Invalid monitor id");
855
gnome_vfs_monitor_cancel(handle);
856
g_hash_table_remove(monitor_hash, GINT_TO_POINTER(monitor_id));
863
pygvfs_read_entire_file(PyObject *self, PyObject *args)
865
GnomeVFSResult result;
871
if (!PyArg_ParseTuple(args, "s:gnomevfs.read_entire_file", &uri))
874
pyg_begin_allow_threads;
875
result = gnome_vfs_read_entire_file (uri, &file_size, &file_contents);
876
pyg_end_allow_threads;
878
if (pygnome_vfs_result_check(result))
880
rv = PyString_FromStringAndSize(file_contents, file_size);
881
g_free(file_contents);
886
pygvfs_mime_application_new(GnomeVFSMimeApplication *mimeapp)
888
PyObject *uri_schemes;
892
uri_schemes = PyList_New(g_list_length(mimeapp->supported_uri_schemes));
893
for (i = 0, l = mimeapp->supported_uri_schemes; l; ++i, l = l->next)
894
PyList_SET_ITEM(uri_schemes, i, PyString_FromString((const char *) l->data));
896
return Py_BuildValue("sssOONO", mimeapp->id, mimeapp->name,
898
mimeapp->can_open_multiple_files? Py_True : Py_False,
899
mimeapp->expects_uris? Py_True : Py_False,
901
mimeapp->requires_terminal? Py_True : Py_False);
905
pygvfs_mime_get_default_application(PyObject *self, PyObject *args)
907
const char *mime_type;
908
GnomeVFSMimeApplication *mimeapp;
911
if(!PyArg_ParseTuple(args, "s:gnomevfs.mime_get_default_application",
914
if (!(mimeapp = gnome_vfs_mime_get_default_application(mime_type))) {
918
retval = pygvfs_mime_application_new(mimeapp);
919
gnome_vfs_mime_application_free(mimeapp);
925
pygvfs_xfer_progress_callback(GnomeVFSXferProgressInfo *info, gpointer _data)
927
PyGVFSCustomNotify *data = _data;
928
PyObject *py_info, *callback_return;
930
PyGILState_STATE state;
932
state = pyg_gil_state_ensure();
933
py_info = pygnome_vfs_xfer_progress_info_new(info);
935
callback_return = PyObject_CallFunction(data->func, "OO", py_info, data->data);
937
callback_return = PyObject_CallFunction(data->func, "O", py_info);
939
/* because the programmer may keep a reference to the
940
* VFSXferProgressInfo python wrapper but we don't own the
941
* VFSXferProgressInfo itself, we remove the link from the
942
* python wrapper to the C structure */
943
pygnome_vfs_xfer_progress_info_set(py_info, NULL);
947
if (callback_return == NULL) {
949
pyg_gil_state_release(state);
950
return GNOME_VFS_XFER_ERROR_ACTION_ABORT;
952
if (!PyInt_Check(callback_return)) {
953
PyErr_SetString(PyExc_TypeError, "progress callback must return an int");
955
pyg_gil_state_release(state);
956
return GNOME_VFS_XFER_ERROR_ACTION_ABORT;
958
retval = PyInt_AsLong(callback_return);
959
Py_DECREF(callback_return);
960
pyg_gil_state_release(state);
965
pygvfs_xfer_uri(PyObject *self, PyObject *args, PyObject *kwargs)
967
static char *kwlist[] = { "source_uri", "target_uri", "xfer_options",
968
"error_mode", "overwrite_mode",
969
"progress_callback", "data", NULL };
970
PyObject *source_uri, *target_uri;
971
int xfer_options = -1, error_mode = -1, overwrite_mode = -1;
972
PyGVFSCustomNotify custom_data = {NULL, NULL};
973
GnomeVFSResult result;
975
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O!iii|OO:gnomevfs.xfer_uri",
977
&PyGnomeVFSURI_Type, &source_uri,
978
&PyGnomeVFSURI_Type, &target_uri,
979
&xfer_options, &error_mode, &overwrite_mode,
980
&custom_data.func, &custom_data.data))
983
if (custom_data.func == Py_None)
984
custom_data.func = NULL;
985
if (!custom_data.func) {
986
if (error_mode == GNOME_VFS_XFER_ERROR_MODE_QUERY) {
987
PyErr_SetString(PyExc_ValueError, "callback is required with QUERY error mode");
990
} else if (!PyCallable_Check(custom_data.func)) {
991
PyErr_SetString(PyExc_TypeError, "progress_callback must be callable");
995
pyg_begin_allow_threads;
996
result = gnome_vfs_xfer_uri(pygnome_vfs_uri_get(source_uri),
997
pygnome_vfs_uri_get(target_uri),
998
xfer_options, error_mode, overwrite_mode,
1000
pygvfs_xfer_progress_callback : NULL),
1002
pyg_end_allow_threads;
1003
if (pygnome_vfs_result_check(result))
1011
_pygvfs_uri_sequence_to_glist(PyObject *seq, GList **list)
1016
if (!PySequence_Check(seq))
1019
len = PySequence_Length(seq);
1020
for (i = 0; i < len; ++i) {
1021
item = PySequence_GetItem(seq, i);
1022
if (!PyObject_TypeCheck(item, &PyGnomeVFSURI_Type)) {
1028
*list = g_list_append(*list, pygnome_vfs_uri_get(item));
1035
pygvfs_xfer_uri_list(PyObject *self, PyObject *args, PyObject *kwargs)
1037
static char *kwlist[] = { "source_uri_list", "target_uri_list", "xfer_options",
1038
"error_mode", "overwrite_mode",
1039
"progress_callback", "data", NULL };
1040
PyObject *py_source_uri_list, *py_target_uri_list;
1041
GList *source_uri_list = NULL, *target_uri_list = NULL;
1042
int xfer_options = -1, error_mode = -1, overwrite_mode = -1;
1043
PyGVFSCustomNotify custom_data = {NULL, NULL};
1044
GnomeVFSResult result;
1046
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOiii|OO:gnomevfs.xfer_uri_list",
1048
&py_source_uri_list, &py_target_uri_list,
1049
&xfer_options, &error_mode, &overwrite_mode,
1050
&custom_data.func, &custom_data.data))
1053
if (!_pygvfs_uri_sequence_to_glist(py_source_uri_list, &source_uri_list)) {
1054
PyErr_SetString(PyExc_TypeError, "source_uri_list "
1055
" must be a sequence of gnomevfs.URI");
1058
if (!_pygvfs_uri_sequence_to_glist(py_target_uri_list, &target_uri_list)) {
1059
PyErr_SetString(PyExc_TypeError, "target_uri_list "
1060
" must be a sequence of gnomevfs.URI");
1061
g_list_free(source_uri_list);
1065
if (custom_data.func == Py_None)
1066
custom_data.func = NULL;
1067
if (!custom_data.func) {
1068
if (error_mode == GNOME_VFS_XFER_ERROR_MODE_QUERY) {
1069
PyErr_SetString(PyExc_ValueError, "callback is required with QUERY error mode");
1072
} else if (!PyCallable_Check(custom_data.func)) {
1073
PyErr_SetString(PyExc_TypeError, "progress_callback must be callable");
1074
g_list_free(source_uri_list);
1075
g_list_free(target_uri_list);
1079
pyg_begin_allow_threads;
1080
result = gnome_vfs_xfer_uri_list(source_uri_list, target_uri_list,
1081
xfer_options, error_mode, overwrite_mode,
1083
pygvfs_xfer_progress_callback : NULL),
1085
pyg_end_allow_threads;
1087
g_list_free(source_uri_list);
1088
g_list_free(target_uri_list);
1089
if (pygnome_vfs_result_check(result))
1097
pygvfs_xfer_delete_list(PyObject *self, PyObject *args, PyObject *kwargs)
1099
static char *kwlist[] = { "delete_uri_list",
1100
"xfer_options", "error_mode",
1101
"progress_callback", "data", NULL };
1102
PyObject *py_delete_uri_list;
1103
GList *delete_uri_list = NULL;
1104
int xfer_options = -1, error_mode = -1;
1105
PyGVFSCustomNotify custom_data = {NULL, NULL};
1106
GnomeVFSResult result;
1108
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oii|OO:gnomevfs.xfer_delete_list",
1110
&py_delete_uri_list,
1111
&error_mode, &xfer_options,
1112
&custom_data.func, &custom_data.data))
1115
if (!_pygvfs_uri_sequence_to_glist(py_delete_uri_list, &delete_uri_list)) {
1116
PyErr_SetString(PyExc_TypeError, "delete_uri_list "
1117
" must be a sequence of gnomevfs.URI");
1121
if (custom_data.func == Py_None)
1122
custom_data.func = NULL;
1123
if (!custom_data.func) {
1124
if (error_mode == GNOME_VFS_XFER_ERROR_MODE_QUERY) {
1125
PyErr_SetString(PyExc_ValueError, "callback is required with QUERY error mode");
1128
} else if (!PyCallable_Check(custom_data.func)) {
1129
PyErr_SetString(PyExc_TypeError, "progress_callback must be callable");
1130
g_list_free(delete_uri_list);
1134
pyg_begin_allow_threads;
1135
result = gnome_vfs_xfer_delete_list(delete_uri_list,
1136
error_mode, xfer_options,
1138
pygvfs_xfer_progress_callback : NULL),
1140
pyg_end_allow_threads;
1142
g_list_free(delete_uri_list);
1143
if (pygnome_vfs_result_check(result))
1151
pygvfs_mime_get_default_action_type(PyObject *self, PyObject *args, PyObject *kwargs)
1153
static char *kwlist[] = { "mime_type", NULL };
1156
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:gnomevfs.mime_get_default_action_type",
1157
kwlist, &mime_type))
1159
return PyInt_FromLong(gnome_vfs_mime_get_default_action_type(mime_type));
1163
pygvfs_mime_action_new(GnomeVFSMimeAction *action)
1165
switch (action->action_type)
1167
case GNOME_VFS_MIME_ACTION_TYPE_NONE:
1168
return Py_BuildValue("(iO)", action->action_type, Py_None);
1170
case GNOME_VFS_MIME_ACTION_TYPE_APPLICATION:
1171
return Py_BuildValue("(iN)", action->action_type,
1172
pygvfs_mime_application_new(action->action.application));
1174
case GNOME_VFS_MIME_ACTION_TYPE_COMPONENT: {
1176
PyObject *component;
1177
any._type = TC_Bonobo_ServerInfo;
1178
any._value = action->action.application;
1179
component = pyorbit_demarshal_any(&any);
1181
PyErr_SetString(PyExc_TypeError, "unable to convert Bonobo_ServerInfo of component");
1184
return Py_BuildValue("(iN)", action->action_type, component);
1187
PyErr_SetString(PyExc_ValueError, "unknown action type returned");
1193
pygvfs_mime_get_default_action(PyObject *self, PyObject *args, PyObject *kwargs)
1195
static char *kwlist[] = { "mime_type", NULL };
1197
GnomeVFSMimeAction *action;
1200
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:gnomevfs.mime_get_default_action",
1201
kwlist, &mime_type))
1203
if (!(action = gnome_vfs_mime_get_default_action(mime_type))) {
1207
retval = pygvfs_mime_action_new(action);
1208
gnome_vfs_mime_action_free(action);
1213
pygvfs_mime_get_default_component(PyObject *self, PyObject *args, PyObject *kwargs)
1215
static char *kwlist[] = { "mime_type", NULL };
1217
Bonobo_ServerInfo *component;
1218
PyObject *py_component;
1221
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:gnomevfs.mime_get_default_component",
1222
kwlist, &mime_type))
1224
if (!(component = gnome_vfs_mime_get_default_component(mime_type))) {
1228
any._type = TC_Bonobo_ServerInfo;
1229
any._value = component;
1230
py_component = pyorbit_demarshal_any(&any);
1232
PyErr_SetString(PyExc_TypeError, "unable to convert Bonobo_ServerInfo of component");
1235
CORBA_free(component);
1236
return py_component;
1240
pygvfs_mime_components_list_new(GList *list)
1243
Bonobo_ServerInfo *component;
1244
PyObject *py_component;
1246
guint i, len = g_list_length(list);
1248
retval = PyList_New(len);
1249
for (i = 0; list; ++i, list = list->next) {
1251
component = (Bonobo_ServerInfo *) list->data;
1252
any._value = component;
1253
py_component = pyorbit_demarshal_any(&any);
1255
PyErr_SetString(PyExc_TypeError, "unable to convert Bonobo_ServerInfo of component");
1259
PyList_SET_ITEM(retval, i, py_component);
1265
pygvfs_mime_get_short_list_components(PyObject *self, PyObject *args, PyObject *kwargs)
1267
static char *kwlist[] = { "mime_type", NULL };
1272
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:gnomevfs.mime_get_short_list_components",
1273
kwlist, &mime_type))
1275
list = gnome_vfs_mime_get_short_list_components(mime_type);
1276
py_list = pygvfs_mime_components_list_new(list);
1277
gnome_vfs_mime_component_list_free(list);
1282
pygvfs_mime_get_all_components(PyObject *self, PyObject *args, PyObject *kwargs)
1284
static char *kwlist[] = { "mime_type", NULL };
1289
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:gnomevfs.mime_get_all_components",
1290
kwlist, &mime_type))
1292
list = gnome_vfs_mime_get_all_components(mime_type);
1293
py_list = pygvfs_mime_components_list_new(list);
1294
gnome_vfs_mime_component_list_free(list);
1299
pygvfs_mime_applications_list_new(GList *list)
1303
guint i, len = g_list_length(list);
1305
retval = PyList_New(len);
1306
for (i = 0; list; ++i, list = list->next) {
1308
py_app = pygvfs_mime_application_new((GnomeVFSMimeApplication *) list->data);
1309
PyList_SET_ITEM(retval, i, py_app);
1315
pygvfs_mime_get_short_list_applications(PyObject *self, PyObject *args, PyObject *kwargs)
1317
static char *kwlist[] = { "mime_type", NULL };
1322
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1323
"s:gnomevfs.mime_get_short_list_applications",
1324
kwlist, &mime_type))
1326
list = gnome_vfs_mime_get_short_list_applications(mime_type);
1327
py_list = pygvfs_mime_applications_list_new(list);
1328
gnome_vfs_mime_application_list_free(list);
1333
pygvfs_mime_get_all_applications(PyObject *self, PyObject *args, PyObject *kwargs)
1335
static char *kwlist[] = { "mime_type", NULL };
1340
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1341
"s:gnomevfs.mime_get_all_applications",
1342
kwlist, &mime_type))
1344
list = gnome_vfs_mime_get_all_applications(mime_type);
1345
py_list = pygvfs_mime_applications_list_new(list);
1346
gnome_vfs_mime_application_list_free(list);
1351
pygvfs_mime_set_default_action_type(PyObject *self, PyObject *args, PyObject *kwargs)
1353
static char *kwlist[] = { "mime_type", "action_type", NULL };
1355
GnomeVFSMimeActionType action_type;
1356
GnomeVFSResult result;
1358
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1359
"si:gnomevfs.mime_set_default_action_type",
1360
kwlist, &mime_type, &action_type))
1362
result = gnome_vfs_mime_set_default_action_type(mime_type, action_type);
1363
if (pygnome_vfs_result_check(result))
1370
pygvfs_mime_set_default_application(PyObject *self, PyObject *args, PyObject *kwargs)
1372
static char *kwlist[] = { "mime_type", "application_id", NULL };
1373
char *mime_type, *application_id;
1374
GnomeVFSResult result;
1376
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1377
"ss:gnomevfs.mime_set_default_application",
1378
kwlist, &mime_type, &application_id))
1380
result = gnome_vfs_mime_set_default_application(mime_type, application_id);
1381
if (pygnome_vfs_result_check(result))
1388
pygvfs_mime_set_default_component(PyObject *self, PyObject *args, PyObject *kwargs)
1390
static char *kwlist[] = { "mime_type", "component_iid", NULL };
1391
char *mime_type, *component_iid;
1392
GnomeVFSResult result;
1394
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1395
"ss:gnomevfs.mime_set_default_component",
1396
kwlist, &mime_type, &component_iid))
1398
result = gnome_vfs_mime_set_default_component(mime_type, component_iid);
1399
if (pygnome_vfs_result_check(result))
1406
string_list_converter(PyObject *in, void *out)
1412
if (!PySequence_Check(in)) {
1413
PyErr_SetString(PyExc_TypeError, "argument must be a sequence");
1416
len = PySequence_Length(in);
1417
for (i = 0; i < len; ++i) {
1418
item = PySequence_GetItem(in, i);
1419
if (!PyString_Check(item)) {
1424
list = g_list_append(list, PyString_AsString(item));
1427
*((GList **) out) = list;
1432
pygvfs_mime_set_short_list_applications(PyObject *self, PyObject *args, PyObject *kwargs)
1434
static char *kwlist[] = { "mime_type", "application_ids", NULL };
1436
GList *application_ids;
1437
GnomeVFSResult result;
1439
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1440
"sO&:gnomevfs.mime_set_short_list_applications",
1442
string_list_converter, &application_ids))
1444
result = gnome_vfs_mime_set_short_list_applications(mime_type, application_ids);
1445
g_list_free(application_ids);
1446
if (pygnome_vfs_result_check(result))
1453
pygvfs_mime_set_short_list_components(PyObject *self, PyObject *args, PyObject *kwargs)
1455
static char *kwlist[] = { "mime_type", "component_iids", NULL };
1457
GList *component_iids;
1458
GnomeVFSResult result;
1460
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1461
"sO&:gnomevfs.mime_set_short_list_components",
1463
string_list_converter, &component_iids))
1465
result = gnome_vfs_mime_set_short_list_components(mime_type, component_iids);
1466
g_list_free(component_iids);
1467
if (pygnome_vfs_result_check(result))
1475
pygvfs_mime_add_application_to_short_list(PyObject *self, PyObject *args, PyObject *kwargs)
1477
static char *kwlist[] = { "mime_type", "application_id", NULL };
1478
char *mime_type, *application_id;
1479
GnomeVFSResult result;
1481
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1482
"ss:gnomevfs.mime_add_application_to_short_list",
1483
kwlist, &mime_type, &application_id))
1485
result = gnome_vfs_mime_add_application_to_short_list(mime_type, application_id);
1486
if (pygnome_vfs_result_check(result))
1493
pygvfs_mime_remove_application_from_short_list(PyObject *self, PyObject *args, PyObject *kwargs)
1495
static char *kwlist[] = { "mime_type", "application_id", NULL };
1496
char *mime_type, *application_id;
1497
GnomeVFSResult result;
1499
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1500
"ss:gnomevfs.mime_remove_application_from_short_list",
1501
kwlist, &mime_type, &application_id))
1503
result = gnome_vfs_mime_remove_application_from_short_list(mime_type, application_id);
1504
if (pygnome_vfs_result_check(result))
1511
pygvfs_mime_add_component_to_short_list(PyObject *self, PyObject *args, PyObject *kwargs)
1513
static char *kwlist[] = { "mime_type", "component_iid", NULL };
1514
char *mime_type, *component_iid;
1515
GnomeVFSResult result;
1517
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1518
"ss:gnomevfs.mime_add_component_to_short_list",
1519
kwlist, &mime_type, &component_iid))
1521
result = gnome_vfs_mime_add_component_to_short_list(mime_type, component_iid);
1522
if (pygnome_vfs_result_check(result))
1529
pygvfs_mime_remove_component_from_short_list(PyObject *self, PyObject *args, PyObject *kwargs)
1531
static char *kwlist[] = { "mime_type", "component_iid", NULL };
1532
char *mime_type, *component_iid;
1533
GnomeVFSResult result;
1535
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1536
"ss:gnomevfs.mime_remove_component_from_short_list",
1537
kwlist, &mime_type, &component_iid))
1539
result = gnome_vfs_mime_remove_component_from_short_list(mime_type, component_iid);
1540
if (pygnome_vfs_result_check(result))
1547
pygvfs_mime_add_extension(PyObject *self, PyObject *args, PyObject *kwargs)
1549
static char *kwlist[] = { "mime_type", "extension", NULL };
1550
char *mime_type, *extension;
1551
GnomeVFSResult result;
1553
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1554
"ss:gnomevfs.mime_add_extension",
1555
kwlist, &mime_type, &extension))
1557
result = gnome_vfs_mime_add_extension(mime_type, extension);
1558
if (pygnome_vfs_result_check(result))
1565
pygvfs_mime_remove_extension(PyObject *self, PyObject *args, PyObject *kwargs)
1567
static char *kwlist[] = { "mime_type", "extension", NULL };
1568
char *mime_type, *extension;
1569
GnomeVFSResult result;
1571
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1572
"ss:gnomevfs.mime_remove_extension",
1573
kwlist, &mime_type, &extension))
1575
result = gnome_vfs_mime_remove_extension(mime_type, extension);
1576
if (pygnome_vfs_result_check(result))
1583
pygvfs_mime_extend_all_applications(PyObject *self, PyObject *args, PyObject *kwargs)
1585
static char *kwlist[] = { "mime_type", "application_ids", NULL };
1587
GList *application_ids;
1588
GnomeVFSResult result;
1590
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1591
"sO&:gnomevfs.mime_extend_all_applications",
1593
string_list_converter, &application_ids))
1595
result = gnome_vfs_mime_extend_all_applications(mime_type, application_ids);
1596
g_list_free(application_ids);
1597
if (pygnome_vfs_result_check(result))
1604
pygvfs_mime_remove_from_all_applications(PyObject *self, PyObject *args, PyObject *kwargs)
1606
static char *kwlist[] = { "mime_type", "application_ids", NULL };
1608
GList *application_ids;
1609
GnomeVFSResult result;
1611
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1612
"sO&:gnomevfs.mime_remove_from_all_applications",
1614
string_list_converter, &application_ids))
1616
result = gnome_vfs_mime_remove_from_all_applications(mime_type, application_ids);
1617
g_list_free(application_ids);
1618
if (pygnome_vfs_result_check(result))
1625
pygvfs_mime_application_new_from_id(PyObject *self, PyObject *args, PyObject *kwargs)
1627
static char *kwlist[] = { "id", NULL };
1629
GnomeVFSMimeApplication *app;
1631
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1632
"s:gnomevfs.mime_application_new_from_id",
1635
app = gnome_vfs_mime_application_new_from_id(id);
1638
/* not sure if NULL is a valid return value, but we handle
1639
* it just in case... */
1640
PyErr_SetString(PyExc_ValueError, "unknown application id");
1643
return pygvfs_mime_application_new(app);
1647
pyvfs_format_file_size_for_display(PyObject *self, PyObject *args)
1653
if(!PyArg_ParseTuple(args, "K", &size))
1656
cstring = gnome_vfs_format_file_size_for_display(size);
1657
string = PyString_FromString(cstring);
1666
pygvfs_resolve(PyObject *self, PyObject *args)
1672
GnomeVFSResolveHandle *handle;
1673
GnomeVFSAddress *address;
1675
if (!PyArg_ParseTuple(args, "s", &hostname))
1678
pyg_begin_allow_threads;
1680
res = gnome_vfs_resolve(hostname, &handle);
1682
if (pygnome_vfs_result_check(res)) {
1687
list = PyList_New(0);
1689
while (gnome_vfs_resolve_next_address(handle, &address))
1695
type = gnome_vfs_address_get_family_type(address);
1696
str = gnome_vfs_address_to_string(address);
1698
pair = Py_BuildValue("(is)", type, str);
1701
PyList_Append(list, pair);
1705
gnome_vfs_resolve_free(handle);
1710
pyg_end_allow_threads;
1716
pygvfs_connect_to_server(PyObject *self, PyObject *args, PyObject *kwargs)
1718
static char *kwlist[] = { "uri", "display_name", "icon", NULL };
1719
char *uri, *display_name, *icon;
1721
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1722
"s:gnomevfs.connect_to_server",
1723
kwlist, &uri, &display_name, &icon))
1725
gnome_vfs_connect_to_server(uri, display_name, icon);
1730
#define pygvfs_generic_str_map_func(name, argname) \
1732
pygvfs_##name(PyObject *self, PyObject *args, PyObject *kwargs) \
1734
static char *kwlist[] = { #argname, NULL }; \
1738
if (!PyArg_ParseTupleAndKeywords(args, kwargs, \
1739
"s:gnomevfs."#name, \
1742
str = gnome_vfs_##name(str); \
1744
PyErr_SetString(PyExc_RuntimeError, "unknown error"); \
1747
retval = PyString_FromString(str); \
1752
pygvfs_generic_str_map_func(escape_string, string);
1753
pygvfs_generic_str_map_func(escape_path_string, path);
1754
pygvfs_generic_str_map_func(escape_host_and_path_string, string);
1755
pygvfs_generic_str_map_func(escape_slashes, string);
1758
pygvfs_escape_set(PyObject *self, PyObject *args, PyObject *kwargs)
1760
static char *kwlist[] = { "string", "match_set", NULL };
1764
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1765
"ss:gnomevfs.escape_set",
1766
kwlist, &str, &str1))
1768
str = gnome_vfs_escape_set(str, str1);
1770
PyErr_SetString(PyExc_RuntimeError, "unknown error");
1773
retval = PyString_FromString(str);
1779
pygvfs_unescape_string(PyObject *self, PyObject *args, PyObject *kwargs)
1781
static char *kwlist[] = { "escaped_string", "illegal_characters", NULL };
1785
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1786
"ss:gnomevfs.unescape_string",
1787
kwlist, &str, &str1))
1789
str = gnome_vfs_escape_set(str, str1);
1791
PyErr_SetString(PyExc_RuntimeError, "unknown error");
1794
retval = PyString_FromString(str);
1799
pygvfs_generic_str_map_func(make_uri_canonical, uri);
1800
pygvfs_generic_str_map_func(make_path_name_canonical, path);
1801
pygvfs_generic_str_map_func(unescape_string_for_display, escaped);
1802
pygvfs_generic_str_map_func(get_local_path_from_uri, uri);
1803
pygvfs_generic_str_map_func(get_uri_from_local_path, local_full_path);
1806
pygvfs_is_executable_command_string(PyObject *self, PyObject *args, PyObject *kwargs)
1808
static char *kwlist[] = { "command_string", NULL };
1811
PyObject *py_retval;
1813
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1814
"s:gnomevfs.is_executable_command_string",
1817
retval = gnome_vfs_is_executable_command_string(str);
1818
py_retval = retval? Py_True : Py_False;
1819
Py_INCREF(py_retval);
1824
pygvfs_get_volume_free_space(PyObject *self, PyObject *args, PyObject *kwargs)
1826
static char *kwlist[] = { "vfs_uri", NULL };
1828
GnomeVFSFileSize size = 0;
1829
GnomeVFSResult result;
1830
PyObject *py_retval;
1832
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1833
"O!:gnomevfs.get_volume_free_space",
1835
&PyGnomeVFSURI_Type, &py_uri))
1837
result = gnome_vfs_get_volume_free_space(pygnome_vfs_uri_get(py_uri), &size);
1838
if (pygnome_vfs_result_check(result))
1840
py_retval = PyLong_FromUnsignedLongLong(size);
1844
pygvfs_generic_str_map_func(icon_path_from_filename, filename);
1847
pygvfs_open_fd(PyObject *self, PyObject *args, PyObject *kwargs)
1849
static char *kwlist[] = { "filedes", NULL };
1851
GnomeVFSResult result;
1852
PyObject *py_retval;
1853
GnomeVFSHandle *handle = NULL;
1855
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1856
"i:gnomevfs.open_fd",
1859
result = gnome_vfs_open_fd(&handle, filedes);
1860
if (pygnome_vfs_result_check(result))
1862
py_retval = pygnome_vfs_handle_new(handle);
1867
pygvfs_is_primary_thread(void)
1870
PyObject *py_retval;
1872
retval = gnome_vfs_is_primary_thread();
1873
py_retval = retval? Py_True : Py_False;
1874
Py_INCREF(py_retval);
1878
pygvfs_generic_str_map_func(format_uri_for_display, uri);
1879
pygvfs_generic_str_map_func(make_uri_from_input, uri);
1882
pygvfs_make_uri_from_input_with_dirs(PyObject *self, PyObject *args, PyObject *kwargs)
1884
static char *kwlist[] = { "escaped_string", "illegal_characters", NULL };
1889
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1890
"si:gnomevfs.make_uri_from_input_with_dirs",
1891
kwlist, &str, &dirs))
1893
str = gnome_vfs_make_uri_from_input_with_dirs(str, dirs);
1895
PyErr_SetString(PyExc_RuntimeError, "unknown error");
1898
retval = PyString_FromString(str);
1903
pygvfs_generic_str_map_func(make_uri_canonical_strip_fragment, uri);
1906
pygvfs_uris_match(PyObject *self, PyObject *args, PyObject *kwargs)
1908
static char *kwlist[] = { "uri_1", "uri_2", NULL };
1911
PyObject *py_retval;
1913
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1914
"ss:gnomevfs.uris_match",
1915
kwlist, &uri1, &uri2))
1917
retval = gnome_vfs_uris_match(uri1, uri2);
1918
py_retval = retval? Py_True : Py_False;
1919
Py_INCREF(py_retval);
1923
pygvfs_generic_str_map_func(get_uri_scheme, uri);
1924
pygvfs_generic_str_map_func(make_uri_from_shell_arg, uri);
1927
pygvfs_url_show(PyObject *self, PyObject *args, PyObject *kwargs)
1929
static char *kwlist[] = { "url", "env", NULL };
1931
GnomeVFSResult result;
1932
PyObject *py_env = NULL;
1934
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1935
"s|O!:gnomevfs.url_show",
1936
kwlist, &url, &PyList_Type, &py_env))
1942
int len = PyList_Size(py_env);
1944
env = g_new(char *, len + 1);
1945
for (i = 0; i < len; ++i) {
1946
PyObject *item = PyList_GET_ITEM(py_env, i);
1947
if (!PyString_Check(item)) {
1948
PyErr_SetString(PyExc_TypeError, "second argument (env) "
1949
"must be a list of strings");
1953
env[i] = PyString_AsString(item);
1958
result = gnome_vfs_url_show_with_env(url, env);
1959
if (env) g_free(env);
1960
if (pygnome_vfs_result_check(result))
1967
static inline PyObject *
1968
pygvfs_dns_service_new(GnomeVFSDNSSDService *service)
1970
return Py_BuildValue("sss", service->name, service->type, service->domain);
1974
_wrap_gnome_vfs_dns_sd_browse_sync(PyObject *self, PyObject *args, PyObject *kwargs)
1976
static char *kwlist[] = { "domain", "type", "timeout_msec", NULL };
1977
char *domain, *type;
1980
GnomeVFSDNSSDService *services = NULL;
1981
GnomeVFSResult result;
1982
PyObject *py_services;
1985
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1986
"ssi:gnomevfs.dns_sd_browse_sync", kwlist,
1987
&domain, &type, &timeout_msec))
1990
pyg_unblock_threads();
1991
result = gnome_vfs_dns_sd_browse_sync(domain, type, timeout_msec,
1992
&n_services, &services);
1993
pyg_block_threads();
1994
if (pygnome_vfs_result_check(result))
1996
py_services = PyList_New(n_services);
1997
for (i = 0; i < n_services; ++i)
1998
PyList_SET_ITEM(py_services, i, pygvfs_dns_service_new(services + i));
1999
gnome_vfs_dns_sd_service_list_free(services, n_services);
2004
__text_hash_to_dict(char *key, char *value, PyObject *dict)
2006
PyObject *pyval = PyString_FromString(value);
2007
PyDict_SetItemString(dict, key, pyval);
2012
_wrap_gnome_vfs_dns_sd_resolve_sync(PyObject *self, PyObject *args, PyObject *kwargs)
2014
static char *kwlist[] = { "name", "type", "domain", "timeout_msec", NULL };
2015
char *name, *domain, *type;
2017
GnomeVFSResult result;
2018
char *host, *text_raw;
2019
int port, text_raw_len;
2024
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
2025
"sssi:gnomevfs.dns_sd_resolve_sync", kwlist,
2026
&name, &type, &domain, &timeout_msec))
2029
pyg_unblock_threads();
2030
result = gnome_vfs_dns_sd_resolve_sync(name, type, domain, timeout_msec,
2031
&host, &port, &hash,
2032
&text_raw_len, &text_raw);
2033
pyg_block_threads();
2035
if (pygnome_vfs_result_check(result))
2038
py_hash = PyDict_New();
2039
g_hash_table_foreach(hash, (GHFunc) __text_hash_to_dict, py_hash);
2040
g_hash_table_destroy(hash);
2041
retval = Py_BuildValue("Ns#", py_hash, text_raw, text_raw_len);
2047
_wrap_gnome_vfs_dns_sd_list_browse_domains_sync(PyObject *self, PyObject *args, PyObject *kwargs)
2049
static char *kwlist[] = { "domain", "timeout_msec", NULL };
2052
GnomeVFSResult result;
2056
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
2057
"si:gnomevfs.dns_sd_list_browse_domains_sync", kwlist,
2058
&domain, &timeout_msec))
2061
pyg_unblock_threads();
2062
result = gnome_vfs_dns_sd_list_browse_domains_sync(domain,
2065
pyg_block_threads();
2066
if (pygnome_vfs_result_check(result))
2068
retval = PyList_New(0);
2069
for (l = domains; l; l = l->next) {
2070
PyObject *item = PyString_FromString((char *) l->data);
2071
PyList_Append(retval, item);
2075
g_list_free(domains);
2080
_wrap_gnome_vfs_get_default_browse_domains(PyObject *self, PyObject *args, PyObject *kwargs)
2085
pyg_unblock_threads();
2086
domains = gnome_vfs_get_default_browse_domains();
2087
pyg_block_threads();
2089
retval = PyList_New(0);
2090
for (l = domains; l; l = l->next) {
2091
PyObject *item = PyString_FromString((char *) l->data);
2092
PyList_Append(retval, item);
2096
g_list_free(domains);
2100
static PyMethodDef pygnomevfs_functions[] = {
2101
{ "create", (PyCFunction)pygvfs_create, METH_VARARGS|METH_KEYWORDS },
2102
{ "get_file_info", (PyCFunction)pygvfs_get_file_info,
2103
METH_VARARGS|METH_KEYWORDS },
2104
{ "set_file_info", (PyCFunction)pygvfs_set_file_info,
2105
METH_VARARGS|METH_KEYWORDS },
2106
{ "truncate", (PyCFunction)pygvfs_truncate, METH_VARARGS|METH_KEYWORDS },
2107
{ "make_directory", (PyCFunction)pygvfs_make_directory,
2108
METH_VARARGS|METH_KEYWORDS },
2109
{ "remove_directory", (PyCFunction)pygvfs_remove_directory,
2110
METH_VARARGS|METH_KEYWORDS },
2111
{ "unlink", (PyCFunction)pygvfs_unlink, METH_VARARGS|METH_KEYWORDS },
2112
{ "exists", (PyCFunction)pygvfs_exists, METH_VARARGS|METH_KEYWORDS },
2113
{ "format_file_size_for_display", pyvfs_format_file_size_for_display, METH_VARARGS},
2114
{ "get_mime_type", (PyCFunction)pygvfs_get_mime_type, METH_VARARGS },
2115
{ "get_mime_type_for_data", (PyCFunction)pygvfs_get_mime_type_for_data,
2117
{ "mime_get_icon", (PyCFunction)pygvfs_mime_get_icon, METH_VARARGS },
2118
{ "mime_set_icon", (PyCFunction)pygvfs_mime_set_icon, METH_VARARGS },
2119
{ "mime_get_description", (PyCFunction)pygvfs_mime_get_description,
2121
{ "mime_set_description", (PyCFunction)pygvfs_mime_set_description,
2123
{ "mime_can_be_executable", (PyCFunction)pygvfs_mime_can_be_executable,
2125
{ "mime_set_can_be_executable", (PyCFunction)pygvfs_mime_set_can_be_executable,
2127
{ "monitor_add", pygvfs_monitor_add, METH_VARARGS},
2128
{ "monitor_cancel", pygvfs_monitor_cancel, METH_VARARGS},
2129
{ "read_entire_file", pygvfs_read_entire_file, METH_VARARGS},
2130
{ "mime_get_default_application", (PyCFunction)pygvfs_mime_get_default_application,
2132
{ "xfer_uri", (PyCFunction)pygvfs_xfer_uri, METH_VARARGS|METH_KEYWORDS },
2133
{ "xfer_uri_list", (PyCFunction)pygvfs_xfer_uri_list, METH_VARARGS|METH_KEYWORDS },
2134
{ "xfer_delete_list", (PyCFunction)pygvfs_xfer_delete_list, METH_VARARGS|METH_KEYWORDS },
2135
{ "mime_get_default_action_type", (PyCFunction)pygvfs_mime_get_default_action_type,
2136
METH_VARARGS|METH_KEYWORDS },
2137
{ "mime_get_default_action", (PyCFunction)pygvfs_mime_get_default_action,
2138
METH_VARARGS|METH_KEYWORDS },
2139
{ "mime_get_default_component", (PyCFunction)pygvfs_mime_get_default_component,
2140
METH_VARARGS|METH_KEYWORDS },
2141
{ "mime_get_short_list_components", (PyCFunction)pygvfs_mime_get_short_list_components,
2142
METH_VARARGS|METH_KEYWORDS },
2143
{ "mime_get_short_list_applications", (PyCFunction)pygvfs_mime_get_short_list_applications,
2144
METH_VARARGS|METH_KEYWORDS },
2145
{ "mime_get_all_applications", (PyCFunction)pygvfs_mime_get_all_applications,
2146
METH_VARARGS|METH_KEYWORDS },
2147
{ "mime_get_all_components", (PyCFunction)pygvfs_mime_get_all_components,
2148
METH_VARARGS|METH_KEYWORDS },
2149
{ "mime_set_default_action_type", (PyCFunction)pygvfs_mime_set_default_action_type,
2150
METH_VARARGS|METH_KEYWORDS },
2151
{ "mime_set_default_application", (PyCFunction)pygvfs_mime_set_default_application,
2152
METH_VARARGS|METH_KEYWORDS },
2153
{ "mime_set_default_component", (PyCFunction)pygvfs_mime_set_default_component,
2154
METH_VARARGS|METH_KEYWORDS },
2155
{ "mime_set_short_list_applications", (PyCFunction)pygvfs_mime_set_short_list_applications,
2156
METH_VARARGS|METH_KEYWORDS },
2157
{ "mime_set_short_list_components", (PyCFunction)pygvfs_mime_set_short_list_components,
2158
METH_VARARGS|METH_KEYWORDS },
2159
{ "mime_add_application_to_short_list", (PyCFunction)pygvfs_mime_add_application_to_short_list,
2160
METH_VARARGS|METH_KEYWORDS },
2161
{ "mime_remove_application_from_short_list",
2162
(PyCFunction)pygvfs_mime_remove_application_from_short_list, METH_VARARGS|METH_KEYWORDS },
2163
{ "mime_add_component_to_short_list", (PyCFunction)pygvfs_mime_add_component_to_short_list,
2164
METH_VARARGS|METH_KEYWORDS },
2165
{ "mime_remove_component_from_short_list", (PyCFunction)pygvfs_mime_remove_component_from_short_list,
2166
METH_VARARGS|METH_KEYWORDS },
2167
{ "mime_add_extension", (PyCFunction)pygvfs_mime_add_extension,
2168
METH_VARARGS|METH_KEYWORDS },
2169
{ "mime_remove_extension", (PyCFunction)pygvfs_mime_remove_extension,
2170
METH_VARARGS|METH_KEYWORDS },
2171
{ "mime_extend_all_applications", (PyCFunction)pygvfs_mime_extend_all_applications,
2172
METH_VARARGS|METH_KEYWORDS },
2173
{ "mime_remove_from_all_applications", (PyCFunction)pygvfs_mime_remove_from_all_applications,
2174
METH_VARARGS|METH_KEYWORDS },
2175
{ "mime_application_new_from_id", (PyCFunction)pygvfs_mime_application_new_from_id,
2176
METH_VARARGS|METH_KEYWORDS },
2177
{ "connect_to_server", (PyCFunction)pygvfs_connect_to_server,
2178
METH_VARARGS|METH_KEYWORDS },
2179
{ "escape_string", (PyCFunction)pygvfs_escape_string,
2180
METH_VARARGS|METH_KEYWORDS },
2181
{ "escape_path_string", (PyCFunction)pygvfs_escape_path_string,
2182
METH_VARARGS|METH_KEYWORDS },
2183
{ "escape_host_and_path_string", (PyCFunction)pygvfs_escape_host_and_path_string,
2184
METH_VARARGS|METH_KEYWORDS },
2185
{ "escape_slashes", (PyCFunction)pygvfs_escape_slashes,
2186
METH_VARARGS|METH_KEYWORDS },
2187
{ "escape_set", (PyCFunction)pygvfs_escape_set,
2188
METH_VARARGS|METH_KEYWORDS },
2189
{ "unescape_string", (PyCFunction)pygvfs_unescape_string,
2190
METH_VARARGS|METH_KEYWORDS },
2191
{ "make_uri_canonical", (PyCFunction)pygvfs_make_uri_canonical,
2192
METH_VARARGS|METH_KEYWORDS },
2193
{ "make_path_name_canonical", (PyCFunction)pygvfs_make_path_name_canonical,
2194
METH_VARARGS|METH_KEYWORDS },
2195
{ "unescape_string_for_display", (PyCFunction)pygvfs_unescape_string_for_display,
2196
METH_VARARGS|METH_KEYWORDS },
2197
{ "get_local_path_from_uri", (PyCFunction)pygvfs_get_local_path_from_uri,
2198
METH_VARARGS|METH_KEYWORDS },
2199
{ "get_uri_from_local_path", (PyCFunction)pygvfs_get_uri_from_local_path,
2200
METH_VARARGS|METH_KEYWORDS },
2201
{ "is_executable_command_string", (PyCFunction)pygvfs_is_executable_command_string,
2202
METH_VARARGS|METH_KEYWORDS },
2203
{ "get_volume_free_space", (PyCFunction)pygvfs_get_volume_free_space,
2204
METH_VARARGS|METH_KEYWORDS },
2205
{ "icon_path_from_filename", (PyCFunction)pygvfs_icon_path_from_filename,
2206
METH_VARARGS|METH_KEYWORDS },
2207
{ "open_fd", (PyCFunction)pygvfs_open_fd,
2208
METH_VARARGS|METH_KEYWORDS },
2209
{ "is_primary_thread", (PyCFunction)pygvfs_is_primary_thread,
2211
{ "format_uri_for_display", (PyCFunction)pygvfs_format_uri_for_display,
2212
METH_VARARGS|METH_KEYWORDS },
2213
{ "make_uri_from_input", (PyCFunction)pygvfs_make_uri_from_input,
2214
METH_VARARGS|METH_KEYWORDS },
2215
{ "make_uri_from_input_with_dirs", (PyCFunction)pygvfs_make_uri_from_input_with_dirs,
2216
METH_VARARGS|METH_KEYWORDS },
2217
{ "make_uri_canonical_strip_fragment", (PyCFunction)pygvfs_make_uri_canonical_strip_fragment,
2218
METH_VARARGS|METH_KEYWORDS },
2219
{ "uris_match", (PyCFunction)pygvfs_uris_match,
2220
METH_VARARGS|METH_KEYWORDS },
2221
{ "get_uri_scheme", (PyCFunction)pygvfs_get_uri_scheme,
2222
METH_VARARGS|METH_KEYWORDS },
2223
{ "make_uri_from_shell_arg", (PyCFunction)pygvfs_make_uri_from_shell_arg,
2224
METH_VARARGS|METH_KEYWORDS },
2225
{ "url_show", (PyCFunction)pygvfs_url_show,
2226
METH_VARARGS|METH_KEYWORDS },
2227
{ "resolve", pygvfs_resolve, METH_VARARGS},
2228
{ "dns_sd_browse_sync", (PyCFunction)_wrap_gnome_vfs_dns_sd_browse_sync,
2229
METH_VARARGS|METH_KEYWORDS},
2230
{ "dns_sd_resolve_sync", (PyCFunction)_wrap_gnome_vfs_dns_sd_resolve_sync,
2231
METH_VARARGS|METH_KEYWORDS},
2232
{ "dns_sd_list_browse_domains_sync",
2233
(PyCFunction)_wrap_gnome_vfs_dns_sd_list_browse_domains_sync,
2234
METH_VARARGS|METH_KEYWORDS},
2235
{ "get_default_browse_domains",
2236
(PyCFunction)_wrap_gnome_vfs_get_default_browse_domains, METH_NOARGS},
2243
register_constants(PyObject *module)
2245
#define regconst(x) PyModule_AddIntConstant(module, #x, GNOME_VFS_ ## x)
2246
regconst(FILE_FLAGS_NONE);
2247
regconst(FILE_FLAGS_SYMLINK);
2248
regconst(FILE_FLAGS_LOCAL);
2249
regconst(FILE_TYPE_UNKNOWN);
2250
regconst(FILE_TYPE_REGULAR);
2251
regconst(FILE_TYPE_DIRECTORY);
2252
regconst(FILE_TYPE_FIFO);
2253
regconst(FILE_TYPE_SOCKET);
2254
regconst(FILE_TYPE_CHARACTER_DEVICE);
2255
regconst(FILE_TYPE_BLOCK_DEVICE);
2256
regconst(FILE_TYPE_SYMBOLIC_LINK);
2257
regconst(FILE_INFO_FIELDS_NONE);
2258
regconst(FILE_INFO_FIELDS_TYPE);
2259
regconst(FILE_INFO_FIELDS_PERMISSIONS);
2260
regconst(FILE_INFO_FIELDS_FLAGS);
2261
regconst(FILE_INFO_FIELDS_DEVICE);
2262
regconst(FILE_INFO_FIELDS_INODE);
2263
regconst(FILE_INFO_FIELDS_LINK_COUNT);
2264
regconst(FILE_INFO_FIELDS_SIZE);
2265
regconst(FILE_INFO_FIELDS_BLOCK_COUNT);
2266
regconst(FILE_INFO_FIELDS_IO_BLOCK_SIZE);
2267
regconst(FILE_INFO_FIELDS_ATIME);
2268
regconst(FILE_INFO_FIELDS_MTIME);
2269
regconst(FILE_INFO_FIELDS_CTIME);
2270
regconst(FILE_INFO_FIELDS_SYMLINK_NAME);
2271
regconst(FILE_INFO_FIELDS_MIME_TYPE);
2272
regconst(PERM_SUID);
2273
regconst(PERM_SGID);
2274
regconst(PERM_STICKY);
2275
regconst(PERM_USER_READ);
2276
regconst(PERM_USER_WRITE);
2277
regconst(PERM_USER_EXEC);
2278
regconst(PERM_USER_ALL);
2279
regconst(PERM_GROUP_READ);
2280
regconst(PERM_GROUP_WRITE);
2281
regconst(PERM_GROUP_EXEC);
2282
regconst(PERM_GROUP_ALL);
2283
regconst(PERM_OTHER_READ);
2284
regconst(PERM_OTHER_WRITE);
2285
regconst(PERM_OTHER_EXEC);
2286
regconst(PERM_OTHER_ALL);
2287
regconst(FILE_INFO_DEFAULT);
2288
regconst(FILE_INFO_GET_MIME_TYPE);
2289
regconst(FILE_INFO_FORCE_FAST_MIME_TYPE);
2290
regconst(FILE_INFO_FORCE_SLOW_MIME_TYPE);
2291
regconst(FILE_INFO_FOLLOW_LINKS);
2292
regconst(SET_FILE_INFO_NONE);
2293
regconst(SET_FILE_INFO_NAME);
2294
regconst(SET_FILE_INFO_PERMISSIONS);
2295
regconst(SET_FILE_INFO_OWNER);
2296
regconst(SET_FILE_INFO_TIME);
2297
regconst(DIRECTORY_VISIT_DEFAULT);
2298
regconst(DIRECTORY_VISIT_SAMEFS);
2299
regconst(DIRECTORY_VISIT_LOOPCHECK);
2300
regconst(OPEN_NONE);
2301
regconst(OPEN_READ);
2302
regconst(OPEN_WRITE);
2303
regconst(OPEN_RANDOM);
2304
regconst(OPEN_TRUNCATE);
2305
regconst(SEEK_START);
2306
regconst(SEEK_CURRENT);
2308
regconst(MONITOR_FILE);
2309
regconst(MONITOR_DIRECTORY);
2310
regconst(MONITOR_EVENT_CHANGED);
2311
regconst(MONITOR_EVENT_DELETED);
2312
regconst(MONITOR_EVENT_STARTEXECUTING);
2313
regconst(MONITOR_EVENT_STOPEXECUTING);
2314
regconst(MONITOR_EVENT_CREATED);
2315
regconst(MONITOR_EVENT_METADATA_CHANGED);
2316
regconst(MIME_APPLICATION_ARGUMENT_TYPE_URIS);
2317
regconst(MIME_APPLICATION_ARGUMENT_TYPE_PATHS);
2318
regconst(MIME_APPLICATION_ARGUMENT_TYPE_URIS_FOR_NON_FILES);
2319
regconst(XFER_DEFAULT);
2320
regconst(XFER_FOLLOW_LINKS);
2321
regconst(XFER_RECURSIVE);
2322
regconst(XFER_SAMEFS);
2323
regconst(XFER_DELETE_ITEMS);
2324
regconst(XFER_EMPTY_DIRECTORIES);
2325
regconst(XFER_NEW_UNIQUE_DIRECTORY);
2326
regconst(XFER_REMOVESOURCE);
2327
regconst(XFER_USE_UNIQUE_NAMES);
2328
regconst(XFER_LINK_ITEMS);
2329
regconst(XFER_FOLLOW_LINKS_RECURSIVE);
2330
regconst(XFER_PROGRESS_STATUS_OK);
2331
regconst(XFER_PROGRESS_STATUS_VFSERROR);
2332
regconst(XFER_PROGRESS_STATUS_OVERWRITE);
2333
regconst(XFER_PROGRESS_STATUS_DUPLICATE);
2334
regconst(XFER_OVERWRITE_MODE_ABORT);
2335
regconst(XFER_OVERWRITE_MODE_QUERY);
2336
regconst(XFER_OVERWRITE_MODE_REPLACE);
2337
regconst(XFER_OVERWRITE_MODE_SKIP);
2338
regconst(XFER_OVERWRITE_ACTION_ABORT);
2339
regconst(XFER_OVERWRITE_ACTION_REPLACE);
2340
regconst(XFER_OVERWRITE_ACTION_REPLACE_ALL);
2341
regconst(XFER_OVERWRITE_ACTION_SKIP);
2342
regconst(XFER_OVERWRITE_ACTION_SKIP_ALL);
2343
regconst(XFER_ERROR_MODE_ABORT);
2344
regconst(XFER_ERROR_MODE_QUERY);
2345
regconst(XFER_ERROR_ACTION_ABORT);
2346
regconst(XFER_ERROR_ACTION_RETRY);
2347
regconst(XFER_ERROR_ACTION_SKIP);
2348
regconst(XFER_PHASE_INITIAL);
2349
regconst(XFER_CHECKING_DESTINATION);
2350
regconst(XFER_PHASE_COLLECTING);
2351
regconst(XFER_PHASE_READYTOGO);
2352
regconst(XFER_PHASE_OPENSOURCE);
2353
regconst(XFER_PHASE_OPENTARGET);
2354
regconst(XFER_PHASE_COPYING);
2355
regconst(XFER_PHASE_MOVING);
2356
regconst(XFER_PHASE_READSOURCE);
2357
regconst(XFER_PHASE_WRITETARGET);
2358
regconst(XFER_PHASE_CLOSESOURCE);
2359
regconst(XFER_PHASE_CLOSETARGET);
2360
regconst(XFER_PHASE_DELETESOURCE);
2361
regconst(XFER_PHASE_SETATTRIBUTES);
2362
regconst(XFER_PHASE_FILECOMPLETED);
2363
regconst(XFER_PHASE_CLEANUP);
2364
regconst(XFER_PHASE_COMPLETED);
2365
regconst(DIRECTORY_KIND_DESKTOP);
2366
regconst(DIRECTORY_KIND_TRASH);
2370
static void initialize_exceptions (PyObject *d)
2372
pygnomevfs_exc = PyErr_NewException ("gnomevfs.Error",
2373
PyExc_RuntimeError, NULL);
2374
PyDict_SetItemString(d, "Error", pygnomevfs_exc);
2376
#define register_exception(c_name, py_name) \
2377
pygnomevfs_##c_name##_exc = \
2378
PyErr_NewException ("gnomevfs." py_name "Error", \
2379
pygnomevfs_exc, NULL); \
2380
PyDict_SetItemString(d, py_name "Error", pygnomevfs_##c_name##_exc);
2382
register_exception(not_found, "NotFound");
2383
register_exception(generic, "Generic");
2384
register_exception(internal, "Internal");
2385
register_exception(bad_parameters, "BadParameters");
2386
register_exception(not_supported, "NotSupported");
2387
register_exception(io, "IO");
2388
register_exception(corrupted_data, "CorruptedData");
2389
register_exception(wrong_format, "WrongFormat");
2390
register_exception(bad_file, "BadFile");
2391
register_exception(too_big, "TooBig");
2392
register_exception(no_space, "NoSpace");
2393
register_exception(read_only, "ReadOnly");
2394
register_exception(invalid_uri, "InvalidURI");
2395
register_exception(not_open, "NotOpen");
2396
register_exception(invalid_open_mode, "InvalidOpenMode");
2397
register_exception(access_denied, "AccessDenied");
2398
register_exception(too_many_open_files, "TooManyOpenFiles");
2399
register_exception(eof, "EOF");
2400
register_exception(not_a_directory, "NotADirectory");
2401
register_exception(in_progress, "InProgress");
2402
register_exception(interrupted, "Interrupted");
2403
register_exception(file_exists, "FileExists");
2404
register_exception(loop, "Loop");
2405
register_exception(not_permitted, "NotPermitted");
2406
register_exception(is_directory, "IsDirectory");
2407
register_exception(no_memory, "NoMemory");
2408
register_exception(host_not_found, "HostNotFound");
2409
register_exception(invalid_host_name, "InvalidHostName");
2410
register_exception(host_has_no_address, "HostHasNoAddress");
2411
register_exception(login_failed, "LoginFailed");
2412
register_exception(cancelled, "Cancelled");
2413
register_exception(directory_busy, "DirectoryBusy");
2414
register_exception(directory_not_empty, "DirectoryNotEmpty");
2415
register_exception(too_many_links, "TooManyLinks");
2416
register_exception(read_only_file_system, "ReadOnlyFileSystem");
2417
register_exception(not_same_file_system, "NotSameFileSystem");
2418
register_exception(name_too_long, "NameTooLong");
2419
register_exception(service_not_available, "ServiceNotAvailable");
2420
register_exception(service_obsolete, "ServiceObsolete");
2421
register_exception(protocol_error, "ProtocolError");
2422
register_exception(no_master_browser, "NoMasterBrowser");
2424
register_exception(no_default, "NoDefault");
2425
register_exception(no_handler, "NoHandler");
2426
register_exception(parse, "Parse");
2427
register_exception(launch, "Launch");
2429
#undef register_exception
2432
struct _PyGnomeVFS_Functions pygnomevfs_api_functions = {
2433
pygnome_vfs_exception_check,
2434
pygnome_vfs_uri_new,
2435
&PyGnomeVFSURI_Type,
2436
pygnome_vfs_file_info_new,
2437
&PyGnomeVFSFileInfo_Type,
2438
pygnome_vfs_context_new,
2439
&PyGnomeVFSContext_Type,
2443
/* initialise stuff extension classes */
2445
pygnomefs_register_gobject_based_classes(PyObject *d)
2449
if ((module = PyImport_ImportModule("gobject")) != NULL) {
2450
PyObject *moddict = PyModule_GetDict(module);
2452
_PyGObject_Type = (PyTypeObject *)PyDict_GetItemString(moddict, "GObject");
2453
if (_PyGObject_Type == NULL) {
2454
PyErr_SetString(PyExc_ImportError,
2455
"cannot import name GObject from gobject");
2459
PyErr_SetString(PyExc_ImportError,
2460
"could not import gobject");
2464
pygobject_register_class(d, "Volume", GNOME_VFS_TYPE_VOLUME, &PyGnomeVFSVolume_Type,
2465
Py_BuildValue("(O)", &PyGObject_Type));
2466
pygobject_register_class(d, "Drive", GNOME_VFS_TYPE_DRIVE, &PyGnomeVFSDrive_Type,
2467
Py_BuildValue("(O)", &PyGObject_Type));
2468
pygobject_register_class(d, "VolumeMonitor", GNOME_VFS_TYPE_VOLUME_MONITOR,
2469
&PyGnomeVFSVolumeMonitor_Type,
2470
Py_BuildValue("(O)", &PyGObject_Type));
2476
PyObject *m, *d, *o;
2478
PyGnomeVFSURI_Type.ob_type = &PyType_Type;
2479
PyGnomeVFSContext_Type.ob_type = &PyType_Type;
2480
PyGnomeVFSFileInfo_Type.ob_type = &PyType_Type;
2481
PyGnomeVFSDirectoryHandle_Type.ob_type = &PyType_Type;
2482
PyGnomeVFSHandle_Type.ob_type = &PyType_Type;
2486
if (!gnome_vfs_init()) {
2487
PyErr_SetString(PyExc_RuntimeError, "could not initialise gnomevfs");
2491
if (PyType_Ready(&PyGnomeVFSURI_Type) < 0)
2493
if (PyType_Ready(&PyGnomeVFSContext_Type) < 0)
2495
if (PyType_Ready(&PyGnomeVFSFileInfo_Type) < 0)
2497
if (PyType_Ready(&PyGnomeVFSDirectoryHandle_Type) < 0)
2499
if (PyType_Ready(&PyGnomeVFSHandle_Type) < 0)
2501
if (PyType_Ready(&PyGnomeVFSXferProgressInfo_Type) < 0)
2504
m = Py_InitModule("gnomevfs", pygnomevfs_functions);
2505
d = PyModule_GetDict(m);
2507
register_constants(m);
2508
initialize_exceptions(d);
2509
PyDict_SetItemString(d, "Error", pygnomevfs_exc);
2511
PyDict_SetItemString(d, "URI", (PyObject *)&PyGnomeVFSURI_Type);
2512
PyDict_SetItemString(d, "Context", (PyObject *)&PyGnomeVFSContext_Type);
2513
PyDict_SetItemString(d, "FileInfo", (PyObject *)&PyGnomeVFSFileInfo_Type);
2514
PyDict_SetItemString(d, "DirectoryHandle",
2515
(PyObject *)&PyGnomeVFSDirectoryHandle_Type);
2516
PyDict_SetItemString(d, "Handle", (PyObject *)&PyGnomeVFSHandle_Type);
2519
pygnomefs_register_gobject_based_classes(d);
2520
pygvvolume_add_constants(m);
2522
PyDict_SetItemString(d, "async", pygvfs_async_module_init ());
2524
PyDict_SetItemString(d, "open_directory",
2525
(PyObject *)&PyGnomeVFSDirectoryHandle_Type);
2526
PyDict_SetItemString(d, "open", (PyObject *)&PyGnomeVFSHandle_Type);
2528
PyDict_SetItemString(d, "_PyGnomeVFS_API",
2529
o=PyCObject_FromVoidPtr(&pygnomevfs_api_functions,NULL));
2532
monitor_hash = g_hash_table_new(g_direct_hash, g_direct_equal);