corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fr...@apache.org
Subject [01/17] incubator-corinthia git commit: Initial commit for Python binding
Date Wed, 29 Apr 2015 12:43:42 GMT
Repository: incubator-corinthia
Updated Branches:
  refs/heads/master ccd08368b -> aa2938d31


Initial commit for Python binding


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/0cb481d9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/0cb481d9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/0cb481d9

Branch: refs/heads/master
Commit: 0cb481d9256acb0dc8111f5b70c982f25526765d
Parents: e382093
Author: franzdecopenhague <franzdecopenhague@outlook.com>
Authored: Thu Mar 12 05:21:37 2015 +0000
Committer: franzdecopenhague <franzdecopenhague@outlook.com>
Committed: Thu Mar 12 05:21:37 2015 +0000

----------------------------------------------------------------------
 CMakeLists.txt                        |   2 +-
 consumers/dfwebserver/input.docx      | Bin 0 -> 12833 bytes
 consumers/dfwebserver/makefile        |  33 +++++++++++++++++++
 consumers/dfwebserver/other.html      |   1 +
 consumers/dfwebserver/setup.py        |  51 +++++++++++++++++++++++++++++
 consumers/dfwebserver/src/dfconvert.c |  45 +++++++++++++++++++++++++
 consumers/dfwebserver/src/dfutil.c    |  47 ++++++++++++++++++++++++++
 consumers/dfwebserver/test.py         |   5 +++
 8 files changed, 183 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0cb481d9/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7eb3585..72082ac 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,7 +36,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
 endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
 
 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
-    set(CMAKE_C_FLAGS "-std=c99 -D_GNU_SOURCE -g")
+    set(CMAKE_C_FLAGS "-std=c99 -D_GNU_SOURCE -g -fPIC")
     set(LIBS ${LIBS} m pthread xml2 z SDL2 SDL2_image)
 endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0cb481d9/consumers/dfwebserver/input.docx
----------------------------------------------------------------------
diff --git a/consumers/dfwebserver/input.docx b/consumers/dfwebserver/input.docx
new file mode 100644
index 0000000..9de8bc3
Binary files /dev/null and b/consumers/dfwebserver/input.docx differ

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0cb481d9/consumers/dfwebserver/makefile
----------------------------------------------------------------------
diff --git a/consumers/dfwebserver/makefile b/consumers/dfwebserver/makefile
new file mode 100644
index 0000000..46cb1f2
--- /dev/null
+++ b/consumers/dfwebserver/makefile
@@ -0,0 +1,33 @@
+
+#build
+#  make
+
+#install
+#  sudo python setup.py install
+
+#unistall 
+#  sudo python setup.py install --record files.txt
+#  cat files.txt | sudo xargs rm -rf      
+
+#develoment build
+#  make dev
+#  python test.py
+
+LDFLAGS ?= ""
+CFLAGS ?= ""
+
+.PHONY: default build_ext clean
+
+default: build_ext
+
+dev:
+	CFLAGS=$(CFLAGS) LDFLAGS=$(LDFLAGS) python setup.py build_ext --inplace --debug
+
+build_ext:
+	CFLAGS=$(CFLAGS) LDFLAGS=$(LDFLAGS) python setup.py build_ext --debug
+
+clean:
+	- rm -rf build
+	- rm -rf consumers
+	- rm -f output.html
+	- find ./ -name '*.so' -delete

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0cb481d9/consumers/dfwebserver/other.html
----------------------------------------------------------------------
diff --git a/consumers/dfwebserver/other.html b/consumers/dfwebserver/other.html
new file mode 100644
index 0000000..14778ef
--- /dev/null
+++ b/consumers/dfwebserver/other.html
@@ -0,0 +1 @@
+<begin>text</begin>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0cb481d9/consumers/dfwebserver/setup.py
----------------------------------------------------------------------
diff --git a/consumers/dfwebserver/setup.py b/consumers/dfwebserver/setup.py
new file mode 100644
index 0000000..d3cdf47
--- /dev/null
+++ b/consumers/dfwebserver/setup.py
@@ -0,0 +1,51 @@
+from distutils.core import setup, Extension
+
+# define the extension module
+dfutil_module = Extension('dfutil', 
+    sources=['src/dfutil.c', '../../consumers/dfutil/src/Commands.c'],
+    libraries = ['DocFormats', 'xml2'],
+    extra_compile_args = ['-std=c99'],
+    library_dirs = ['../../build/lib'],
+    include_dirs = [
+        '../../DocFormats/api/headers', 
+        '../../DocFormats/core/src/common',
+        '../../DocFormats/core/src/css', 
+        '../../DocFormats/core/src/html', 
+        '../../DocFormats/core/src/lib', 
+        '../../DocFormats/core/src/names', 
+        '../../DocFormats/core/src/xml', 
+        '../../DocFormats/core/tests/common', 
+        '../../DocFormats/core/tests/html',
+        '../../DocFormats/filters/latex/src',
+        '../../DocFormats/filters/ooxml/src/common', 
+        '../../DocFormats/filters/ooxml/src/word', 
+        '../../DocFormats/filters/ooxml/tests/word',
+        '../../DocFormats/headers',
+    ]
+)
+
+dfconvert_module = Extension('dfconvert', 
+    sources=['src/dfconvert.c'],
+    libraries = ['DocFormats', 'xml2', 'SDL2', 'SDL_image'],
+    extra_compile_args = ['-std=c99'],
+    library_dirs = ['../../build/lib'],
+    include_dirs = [
+        '../../DocFormats/api/headers', 
+        '../../DocFormats/core/src/common',
+        '../../DocFormats/core/src/css', 
+        '../../DocFormats/core/src/html', 
+        '../../DocFormats/core/src/lib', 
+        '../../DocFormats/core/src/names', 
+        '../../DocFormats/core/src/xml', 
+        '../../DocFormats/core/tests/common', 
+        '../../DocFormats/core/tests/html',
+        '../../DocFormats/filters/latex/src',
+        '../../DocFormats/filters/ooxml/src/common', 
+        '../../DocFormats/filters/ooxml/src/word', 
+        '../../DocFormats/filters/ooxml/tests/word',
+        '../../DocFormats/headers',
+    ]
+)
+
+# run the setup
+setup(ext_modules=[dfutil_module, dfconvert_module])  

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0cb481d9/consumers/dfwebserver/src/dfconvert.c
----------------------------------------------------------------------
diff --git a/consumers/dfwebserver/src/dfconvert.c b/consumers/dfwebserver/src/dfconvert.c
new file mode 100644
index 0000000..b4d88f2
--- /dev/null
+++ b/consumers/dfwebserver/src/dfconvert.c
@@ -0,0 +1,45 @@
+#include <Python.h>
+
+typedef struct DFError DFError;
+void DFErrorRelease(DFError *error);
+const char *DFErrorMessage(DFError **error);
+
+int DFGetFile(const char *concreteFilename,
+              const char *abstractFilename,
+              DFError **error);
+
+static PyObject* get_func(PyObject* self, PyObject* args)
+{
+    DFError *error = NULL;
+    
+    char * concrete = NULL;
+    char * abstract = NULL;
+    
+    if (!PyArg_ParseTuple(args, "ss", &concrete, &abstract)) {
+        return NULL;
+    }    
+    
+    if (DFGetFile(concrete, abstract, &error)) {
+        Py_RETURN_TRUE;
+    }
+
+    fprintf(stderr,"%s\n",DFErrorMessage(&error));
+    DFErrorRelease(error);
+    Py_RETURN_FALSE;
+}
+
+/*  define functions in module */
+static PyMethodDef dfconvertMethods[] =
+{
+     {"get", get_func, METH_VARARGS, "Create a new HTML file from input document"},
+     {NULL, NULL, 0, NULL}
+};
+
+
+/* module initialization */
+PyMODINIT_FUNC
+
+initdfconvert(void)
+{
+     (void) Py_InitModule("dfconvert", dfconvertMethods);
+}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0cb481d9/consumers/dfwebserver/src/dfutil.c
----------------------------------------------------------------------
diff --git a/consumers/dfwebserver/src/dfutil.c b/consumers/dfwebserver/src/dfutil.c
new file mode 100644
index 0000000..8c50aa9
--- /dev/null
+++ b/consumers/dfwebserver/src/dfutil.c
@@ -0,0 +1,47 @@
+#include <Python.h>
+
+typedef struct DFError DFError;
+void DFErrorRelease(DFError *error);
+const char *DFErrorMessage(DFError **error);
+
+int normalizeFile(const char *filename, DFError **error);
+
+static PyObject* normalize_func(PyObject* self, PyObject* args)
+{
+    DFError *dferr = NULL;
+    
+    char * filename = NULL;
+    
+    if (!PyArg_ParseTuple(args, "s", &filename)) {
+        return NULL;
+        /* if the above function returns -1, an appropriate Python exception will
+        * have been set, and the function simply returns NULL
+        */
+    }
+    
+    if (filename!=NULL) {
+        if (1 == normalizeFile(filename, &dferr)) {
+            Py_RETURN_TRUE;
+        }
+        fprintf(stderr,"%s\n",DFErrorMessage(&dferr));
+        DFErrorRelease(dferr);
+    }
+    
+    Py_RETURN_FALSE;
+}
+
+
+/*  define functions in module */
+static PyMethodDef dfutilMethods[] =
+{
+     {"normalize", normalize_func, METH_VARARGS, "evaluate the sine"},
+     {NULL, NULL, 0, NULL}
+};
+
+/* module initialization */
+PyMODINIT_FUNC
+
+initdfutil(void)
+{
+     (void) Py_InitModule("dfutil", dfutilMethods);
+}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0cb481d9/consumers/dfwebserver/test.py
----------------------------------------------------------------------
diff --git a/consumers/dfwebserver/test.py b/consumers/dfwebserver/test.py
new file mode 100644
index 0000000..936042b
--- /dev/null
+++ b/consumers/dfwebserver/test.py
@@ -0,0 +1,5 @@
+import dfutil
+import dfconvert
+
+print dfutil.normalize("other.html")
+print dfconvert.get("input.docx", "output.html");
\ No newline at end of file


Mime
View raw message