Hook up mime.get_for_file
This commit is contained in:
parent
2145de1039
commit
27a3644dab
@ -14,7 +14,8 @@ INCLUDES = \
|
||||
$(LIB_CFLAGS) \
|
||||
$(LIB_BINDINGS_CFLAGS) \
|
||||
$(PYTHON_INCLUDES) \
|
||||
-I$(top_srcdir)/lib
|
||||
-I$(top_srcdir)/lib \
|
||||
-I$(top_srcdir)/lib/xdgmime
|
||||
|
||||
pkgpyexecdir = $(pythondir)/sugar
|
||||
|
||||
|
@ -9,11 +9,12 @@
|
||||
|
||||
#include "pygobject.h"
|
||||
#include "sugar-address-entry.h"
|
||||
#include "xdgmime.h"
|
||||
|
||||
#include <pygtk/pygtk.h>
|
||||
#include <glib.h>
|
||||
|
||||
#line 17 "_sugarext.c"
|
||||
#line 18 "_sugarext.c"
|
||||
|
||||
|
||||
/* ---------- types from other modules ---------- */
|
||||
@ -24,7 +25,7 @@ static PyTypeObject *_PyGtkEntry_Type;
|
||||
/* ---------- forward type declarations ---------- */
|
||||
PyTypeObject G_GNUC_INTERNAL PySugarAddressEntry_Type;
|
||||
|
||||
#line 28 "_sugarext.c"
|
||||
#line 29 "_sugarext.c"
|
||||
|
||||
|
||||
|
||||
@ -97,9 +98,32 @@ _wrap_sugar_mime_get_mime_type_from_file_name(PyObject *self, PyObject *args, Py
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
#line 23 "_sugarext.override"
|
||||
static PyObject *
|
||||
_wrap_sugar_mime_get_mime_type_for_file(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
static char *kwlist[] = { "filename", NULL };
|
||||
char *filename;
|
||||
const gchar *ret;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,"s:get_mime_type_for_file", kwlist, &filename))
|
||||
return NULL;
|
||||
|
||||
ret = sugar_mime_get_mime_type_for_file(filename, NULL);
|
||||
|
||||
if (ret)
|
||||
return PyString_FromString(ret);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
#line 120 "_sugarext.c"
|
||||
|
||||
|
||||
const PyMethodDef py_sugarext_functions[] = {
|
||||
{ "get_mime_type_from_file_name", (PyCFunction)_wrap_sugar_mime_get_mime_type_from_file_name, METH_VARARGS|METH_KEYWORDS,
|
||||
NULL },
|
||||
{ "get_mime_type_for_file", (PyCFunction)_wrap_sugar_mime_get_mime_type_for_file, METH_VARARGS|METH_KEYWORDS,
|
||||
NULL },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
@ -123,6 +147,6 @@ py_sugarext_register_classes(PyObject *d)
|
||||
}
|
||||
|
||||
|
||||
#line 127 "_sugarext.c"
|
||||
#line 151 "_sugarext.c"
|
||||
pygobject_register_class(d, "SugarAddressEntry", SUGAR_TYPE_ADDRESS_ENTRY, &PySugarAddressEntry_Type, Py_BuildValue("(O)", &PyGtkEntry_Type));
|
||||
}
|
||||
|
@ -17,3 +17,11 @@
|
||||
'("const-char*" "filename")
|
||||
)
|
||||
)
|
||||
|
||||
(define-function get_mime_type_for_file
|
||||
(c-name "sugar_mime_get_mime_type_for_file")
|
||||
(return-type "const-char*")
|
||||
(parameters
|
||||
'("const-char*" "filename")
|
||||
)
|
||||
)
|
||||
|
@ -5,6 +5,7 @@ headers
|
||||
|
||||
#include "pygobject.h"
|
||||
#include "sugar-address-entry.h"
|
||||
#include "xdgmime.h"
|
||||
|
||||
#include <pygtk/pygtk.h>
|
||||
#include <glib.h>
|
||||
@ -18,3 +19,22 @@ ignore-glob
|
||||
*_get_type
|
||||
_*
|
||||
%%
|
||||
override sugar_mime_get_mime_type_for_file kwargs
|
||||
static PyObject *
|
||||
_wrap_sugar_mime_get_mime_type_for_file(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
static char *kwlist[] = { "filename", NULL };
|
||||
char *filename;
|
||||
const gchar *ret;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,"s:get_mime_type_for_file", kwlist, &filename))
|
||||
return NULL;
|
||||
|
||||
ret = sugar_mime_get_mime_type_for_file(filename, NULL);
|
||||
|
||||
if (ret)
|
||||
return PyString_FromString(ret);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
%%
|
||||
|
@ -3,6 +3,9 @@ try:
|
||||
except ImportError:
|
||||
from sugar import ltihooks
|
||||
from sugar import _sugarext
|
||||
|
||||
|
||||
def get_for_file(file_name):
|
||||
return _sugarext.get_mime_type_for_file(file_name)
|
||||
|
||||
def get_from_file_name(file_name):
|
||||
return _sugarext.get_mime_type_from_file_name(file_name)
|
||||
|
@ -16,6 +16,15 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
from sugar.objects import mime
|
||||
import sys
|
||||
|
||||
print mime.get_from_file_name('test.pdf')
|
||||
from sugar import objects
|
||||
|
||||
print 'MIME type for test.pdf (from extension):'
|
||||
print objects.mime.get_from_file_name('test.pdf')
|
||||
|
||||
print ''
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
print 'MIME type for file %s:' % sys.argv[1]
|
||||
print objects.mime.get_for_file(sys.argv[1])
|
||||
|
Loading…
Reference in New Issue
Block a user