You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by fr...@apache.org on 2015/04/29 14:43:45 UTC
[04/17] incubator-corinthia git commit: Added put convert to
dfwebserver python binding
Added put convert to dfwebserver 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/748d7078
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/748d7078
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/748d7078
Branch: refs/heads/master
Commit: 748d707808170795dd82caae4d4dd5c89cf1eb1b
Parents: 2a53613
Author: franzdecopenhague <fr...@outlook.com>
Authored: Mon Mar 16 12:35:01 2015 +0000
Committer: franzdecopenhague <fr...@outlook.com>
Committed: Mon Mar 16 12:35:01 2015 +0000
----------------------------------------------------------------------
consumers/dfwebserver/makefile | 6 ++--
consumers/dfwebserver/src/dfconvert.c | 52 ++++++++++++++++++++++++++--
consumers/dfwebserver/test.py | 28 +++++++++++++--
consumers/dfwebserver/testSubprocess.py | 39 +++++++++++++++++++++
4 files changed, 118 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/748d7078/consumers/dfwebserver/makefile
----------------------------------------------------------------------
diff --git a/consumers/dfwebserver/makefile b/consumers/dfwebserver/makefile
index 46cb1f2..a4e3661 100644
--- a/consumers/dfwebserver/makefile
+++ b/consumers/dfwebserver/makefile
@@ -10,7 +10,7 @@
# cat files.txt | sudo xargs rm -rf
#develoment build
-# make dev
+# make clean dev
# python test.py
LDFLAGS ?= ""
@@ -29,5 +29,7 @@ build_ext:
clean:
- rm -rf build
- rm -rf consumers
- - rm -f output.html
+ - rm -f output*.html
+ - rm -f output*.docx
+ - rm -f dummy*.docx
- find ./ -name '*.so' -delete
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/748d7078/consumers/dfwebserver/src/dfconvert.c
----------------------------------------------------------------------
diff --git a/consumers/dfwebserver/src/dfconvert.c b/consumers/dfwebserver/src/dfconvert.c
index b4d88f2..99698fc 100644
--- a/consumers/dfwebserver/src/dfconvert.c
+++ b/consumers/dfwebserver/src/dfconvert.c
@@ -4,9 +4,12 @@ typedef struct DFError DFError;
void DFErrorRelease(DFError *error);
const char *DFErrorMessage(DFError **error);
-int DFGetFile(const char *concreteFilename,
- const char *abstractFilename,
- DFError **error);
+// Abstraction level 1
+
+int DFGetFile(const char *concrete, const char *abstract, DFError **error);
+int DFPutFile(const char *concrete, const char *abstract, DFError **error);
+int DFCreateFile(const char *concrete, const char *abstract, DFError **error);
+
static PyObject* get_func(PyObject* self, PyObject* args)
{
@@ -28,10 +31,53 @@ static PyObject* get_func(PyObject* self, PyObject* args)
Py_RETURN_FALSE;
}
+static PyObject* put_func(PyObject* self, PyObject* args)
+{
+ DFError *error = NULL;
+
+ char * concrete = NULL;
+ char * abstract = NULL;
+
+ if (!PyArg_ParseTuple(args, "ss", &concrete, &abstract)) {
+ return NULL;
+ }
+
+ if (DFPutFile(concrete, abstract, &error)) {
+ Py_RETURN_TRUE;
+ }
+
+ fprintf(stderr,"%s\n",DFErrorMessage(&error));
+ DFErrorRelease(error);
+ Py_RETURN_FALSE;
+}
+
+static PyObject* create_func(PyObject* self, PyObject* args)
+{
+ DFError *error = NULL;
+
+ char * concrete = NULL;
+ char * abstract = NULL;
+
+ if (!PyArg_ParseTuple(args, "ss", &concrete, &abstract)) {
+ return NULL;
+ }
+
+ if (DFCreateFile(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"},
+ {"put", put_func, METH_VARARGS, "Update an existing Word document based on a modified HTML file."},
+ {"create", create_func, METH_VARARGS, "Create a new Word document from a HTML file. The Word document must not already exist."},
{NULL, NULL, 0, NULL}
};
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/748d7078/consumers/dfwebserver/test.py
----------------------------------------------------------------------
diff --git a/consumers/dfwebserver/test.py b/consumers/dfwebserver/test.py
index 936042b..13ee982 100644
--- a/consumers/dfwebserver/test.py
+++ b/consumers/dfwebserver/test.py
@@ -1,5 +1,29 @@
+# To test:
+#
+# make clean dev
+# python test.py
+
+import unittest
+
import dfutil
import dfconvert
+import shutil
+
+
+class MyTest(unittest.TestCase):
+ def test(self):
+
+ self.assertTrue(dfutil.normalize("other.html"))
+
+ self.assertTrue(dfconvert.get("input.docx", "output.html"))
+
+ shutil.copyfile("input.docx", "dummy.docx");
+
+ self.assertTrue(dfconvert.put("dummy.docx", "output.html"))
+
+ self.assertTrue(dfconvert.create("output.docx", "output.html"))
+
+
+if __name__ == '__main__':
+ unittest.main()
-print dfutil.normalize("other.html")
-print dfconvert.get("input.docx", "output.html");
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/748d7078/consumers/dfwebserver/testSubprocess.py
----------------------------------------------------------------------
diff --git a/consumers/dfwebserver/testSubprocess.py b/consumers/dfwebserver/testSubprocess.py
new file mode 100644
index 0000000..7a67b1b
--- /dev/null
+++ b/consumers/dfwebserver/testSubprocess.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+
+import threading
+import time
+
+import dfconvert
+
+exitFlag = 0
+
+class dfconvertThread (threading.Thread):
+ def __init__(self, threadID, name, input, abstract):
+ threading.Thread.__init__(self)
+ self.threadID = threadID
+ self.name = name
+ self.input = input
+ self.abstract = abstract
+ def run(self):
+ print "Starting " + self.name
+ if exitFlag:
+ thread.exit()
+ status = dfconvert.get(self.input, self.abstract);
+ print "%s: %s status:%s" % (self.name, time.ctime(time.time()), status)
+ print "Exiting " + self.name
+
+# Create new threads
+thread1 = dfconvertThread(1, "Thread-1", "input.docx", "output1.html")
+thread2 = dfconvertThread(2, "Thread-2", "input.docx", "output2.html")
+thread3 = dfconvertThread(3, "Thread-3", "input.docx", "output3.html")
+thread4 = dfconvertThread(4, "Thread-4", "input.docx", "output4.html")
+thread5 = dfconvertThread(5, "Thread-5", "input.docx", "output5.html")
+
+# Start new Threads
+thread1.start()
+thread2.start()
+thread3.start()
+thread4.start()
+thread5.start()
+
+print "Exiting Main Thread"
\ No newline at end of file