Return-Path: X-Original-To: apmail-corinthia-commits-archive@minotaur.apache.org Delivered-To: apmail-corinthia-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 55E0D176C8 for ; Wed, 1 Apr 2015 16:26:16 +0000 (UTC) Received: (qmail 87679 invoked by uid 500); 1 Apr 2015 16:26:13 -0000 Delivered-To: apmail-corinthia-commits-archive@corinthia.apache.org Received: (qmail 87659 invoked by uid 500); 1 Apr 2015 16:26:13 -0000 Mailing-List: contact commits-help@corinthia.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@corinthia.incubator.apache.org Delivered-To: mailing list commits@corinthia.incubator.apache.org Received: (qmail 87650 invoked by uid 99); 1 Apr 2015 16:26:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Apr 2015 16:26:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 01 Apr 2015 16:26:09 +0000 Received: (qmail 82700 invoked by uid 99); 1 Apr 2015 16:24:34 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Apr 2015 16:24:34 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3D1FDE10A2; Wed, 1 Apr 2015 16:24:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pmkelly@apache.org To: commits@corinthia.incubator.apache.org Message-Id: <12a572bac7ce44858c6fdd55d57573a5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-corinthia git commit: dbwebserver: Python updates & Node version Date: Wed, 1 Apr 2015 16:24:34 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Repository: incubator-corinthia Updated Branches: refs/heads/master 1b12e2e5e -> ee6e8174c dbwebserver: Python updates & Node version Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/ee6e8174 Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/ee6e8174 Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/ee6e8174 Branch: refs/heads/master Commit: ee6e8174cec4bb0de8ed2171434319f97672079e Parents: 1b12e2e Author: Franz de Copenhague Authored: Wed Apr 1 21:11:26 2015 +0700 Committer: Peter Kelly Committed: Wed Apr 1 23:19:12 2015 +0700 ---------------------------------------------------------------------- consumers/dfwebserver/.gitignore | 2 + consumers/dfwebserver/assets/input.docx | Bin 0 -> 12833 bytes .../dfwebserver/examples/node/server/.gitignore | 1 + .../examples/node/server/package.json | 17 +++ .../dfwebserver/examples/node/server/server.js | 105 ++++++++++++++++++ consumers/dfwebserver/examples/node/simple.js | 10 ++ consumers/dfwebserver/input.docx | Bin 12833 -> 0 bytes consumers/dfwebserver/makefile | 35 ------ consumers/dfwebserver/node/.gitignore | 3 + consumers/dfwebserver/node/.npmignore | 0 consumers/dfwebserver/node/LICENSE | 16 +++ consumers/dfwebserver/node/package.json | 16 +++ consumers/dfwebserver/node/src/docformats.js | 27 +++++ consumers/dfwebserver/other.html | 1 - consumers/dfwebserver/python/input.docx | Bin 0 -> 12833 bytes consumers/dfwebserver/python/makefile | 48 +++++++++ consumers/dfwebserver/python/other.html | 1 + consumers/dfwebserver/python/setup.py | 64 +++++++++++ consumers/dfwebserver/python/src/dfconvert.c | 108 +++++++++++++++++++ consumers/dfwebserver/python/src/dfutil.c | 64 +++++++++++ consumers/dfwebserver/python/test.py | 42 ++++++++ consumers/dfwebserver/python/testSubprocess.py | 52 +++++++++ consumers/dfwebserver/setup.py | 51 --------- consumers/dfwebserver/test.py | 29 ----- consumers/dfwebserver/testSubprocess.py | 39 ------- consumers/dfwebserver/web/client/index.html | 10 +- 26 files changed, 585 insertions(+), 156 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/.gitignore ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/.gitignore b/consumers/dfwebserver/.gitignore new file mode 100644 index 0000000..3cd6f04 --- /dev/null +++ b/consumers/dfwebserver/.gitignore @@ -0,0 +1,2 @@ +pool +uploads \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/assets/input.docx ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/assets/input.docx b/consumers/dfwebserver/assets/input.docx new file mode 100644 index 0000000..9de8bc3 Binary files /dev/null and b/consumers/dfwebserver/assets/input.docx differ http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/examples/node/server/.gitignore ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/examples/node/server/.gitignore b/consumers/dfwebserver/examples/node/server/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/consumers/dfwebserver/examples/node/server/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/examples/node/server/package.json ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/examples/node/server/package.json b/consumers/dfwebserver/examples/node/server/package.json new file mode 100644 index 0000000..215730a --- /dev/null +++ b/consumers/dfwebserver/examples/node/server/package.json @@ -0,0 +1,17 @@ +{ + "name": "server_example", + "version": "1.0.0", + "description": "", + "main": "server.js", + "dependencies": { + "express": "^4.12.3", + "multer": "^0.1.8" + }, + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node server.js" + }, + "author": "", + "license": "apache2" +} http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/examples/node/server/server.js ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/examples/node/server/server.js b/consumers/dfwebserver/examples/node/server/server.js new file mode 100644 index 0000000..ec79dfc --- /dev/null +++ b/consumers/dfwebserver/examples/node/server/server.js @@ -0,0 +1,105 @@ +var express = require('express'), + multer = require('multer') + +var path = require('path'); +var fs = require('fs'); + +var docformats = require('../../../node/src/docformats'); +docformats.options.binaryPath = path.resolve('../../../../../build/bin'); + + +var app = express(); + +var dfwebserver = path.resolve(__dirname, '../../..'); +var web = path.resolve(__dirname, '../../../../web'); + +app.get('/upload', function(req, res){ + res.send('\ +
\ +
\ + \ +
\ + '); +}); + +var multerOptions = { + dest: path.resolve(dfwebserver, 'uploads/'), + rename: function (fieldname, filename) { + return filename; + } +}; + +app.post('/upload',[ multer(multerOptions), function(req, res){ + console.log(req.body) // form fields + console.log(req.files) // form files + //res.json(req.files).status(204).end() + + res.send('\ + Navigate to this link to run dfconvert GET in the server\ + \ + '); +}]); + + +function getInput(id) { + return path.resolve(dfwebserver, 'uploads', id); +} + +function getOutput(id) { + var folder = path.resolve(dfwebserver, 'pool', id) + var parsed = path.parse(folder); + + return path.resolve(folder, parsed.name + '.html'); +} + +function getDynamicResource(id, resource) { + var folder = path.resolve(dfwebserver, 'pool', id) + + return path.resolve(folder, resource); +} + +function getStaticResource(resource) { + return path.resolve(web, 'client', resource); +} + +function sendFile(res, filename) { + if (fs.existsSync(filename)) { + res.sendFile(filename); + } else { + res.status(404).end(); // Not Found + } +} + + +app.get('/get/:id', function(req, res){ + var input = getInput(req.params.id); + var abstract = getOutput(req.params.id); + + try { + // This is required because DocFormat API throw an error + // when abstract is present in the filesystem + fs.unlinkSync(abstract); + } catch (ex) { + // do nothing + } + docformats.get(input, abstract); + sendFile(res, abstract); +}); + +app.get('/get/:id/*', function(req, res){ + var staticResource = getStaticResource(req.params[0]); + var dynamicResource = getDynamicResource(req.params.id, req.params[0]); + + if (fs.existsSync(staticResource)) { + res.sendFile(staticResource); + } else { + sendFile(res, dynamicResource); + } +}); + + + +app.listen(process.env.PORT || 8080); + + + http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/examples/node/simple.js ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/examples/node/simple.js b/consumers/dfwebserver/examples/node/simple.js new file mode 100644 index 0000000..4b2b0cf --- /dev/null +++ b/consumers/dfwebserver/examples/node/simple.js @@ -0,0 +1,10 @@ +var docformats = require('../../node/src/docformats'); +var path = require("path"); + +docformats.options.binaryPath = path.resolve('../../../../build/bin'); + +var input = path.resolve('../../assets/input.docx'); +var abstract = path.resolve('../../pool/input.docx/input.html'); + +var status = docformats.get(input, abstract); +console.log(status); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/input.docx ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/input.docx b/consumers/dfwebserver/input.docx deleted file mode 100644 index 9de8bc3..0000000 Binary files a/consumers/dfwebserver/input.docx and /dev/null differ http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/makefile ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/makefile b/consumers/dfwebserver/makefile deleted file mode 100644 index a4e3661..0000000 --- a/consumers/dfwebserver/makefile +++ /dev/null @@ -1,35 +0,0 @@ - -#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 clean 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 - - rm -f output*.docx - - rm -f dummy*.docx - - find ./ -name '*.so' -delete http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/node/.gitignore ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/node/.gitignore b/consumers/dfwebserver/node/.gitignore new file mode 100644 index 0000000..2f6141d --- /dev/null +++ b/consumers/dfwebserver/node/.gitignore @@ -0,0 +1,3 @@ +node_modules +npm-debug.log +.DS_Store \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/node/.npmignore ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/node/.npmignore b/consumers/dfwebserver/node/.npmignore new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/node/LICENSE ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/node/LICENSE b/consumers/dfwebserver/node/LICENSE new file mode 100644 index 0000000..90705e0 --- /dev/null +++ b/consumers/dfwebserver/node/LICENSE @@ -0,0 +1,16 @@ +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/node/package.json ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/node/package.json b/consumers/dfwebserver/node/package.json new file mode 100644 index 0000000..5a3746b --- /dev/null +++ b/consumers/dfwebserver/node/package.json @@ -0,0 +1,16 @@ +{ + "name": "docformats", + "version": "0.0.2", + "description": "Wrapper for DocFormats API", + "main": "src/docformats.js", + "dependencies": { + "mkdirp": "^0.5.0" + }, + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "franzdecopenhague", + "license": "apache2" +} + http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/node/src/docformats.js ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/node/src/docformats.js b/consumers/dfwebserver/node/src/docformats.js new file mode 100644 index 0000000..f94a751 --- /dev/null +++ b/consumers/dfwebserver/node/src/docformats.js @@ -0,0 +1,27 @@ +'use strict'; + +var path = require('path'); +var exec = require('child_process').execFileSync; +var mkdirp = require("mkdirp").sync; + +var df = exports; + +df.options = {binaryPath : null}; + +df.get = function (input, abstract) { + try { + var cmd = null; + if (df.options.binaryPath === undefined || df.options.binaryPath === null) { + cmd = 'dfconvert'; + } else { + cmd = path.join(df.options.binaryPath, 'dfconvert'); + } + console.log(cmd + " get " + input + " " + abstract + ""); + mkdirp(path.dirname(abstract)); + exec(cmd, ['get', input, abstract]); + } catch (ex) { + console.log(ex); + return false; + } + return true; +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/other.html ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/other.html b/consumers/dfwebserver/other.html deleted file mode 100644 index 14778ef..0000000 --- a/consumers/dfwebserver/other.html +++ /dev/null @@ -1 +0,0 @@ -text \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/python/input.docx ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/python/input.docx b/consumers/dfwebserver/python/input.docx new file mode 100644 index 0000000..9de8bc3 Binary files /dev/null and b/consumers/dfwebserver/python/input.docx differ http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/python/makefile ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/python/makefile b/consumers/dfwebserver/python/makefile new file mode 100644 index 0000000..b3546c3 --- /dev/null +++ b/consumers/dfwebserver/python/makefile @@ -0,0 +1,48 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +#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 clean 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 + - rm -f output*.docx + - rm -f dummy*.docx + - find ./ -name '*.so' -delete http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/python/other.html ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/python/other.html b/consumers/dfwebserver/python/other.html new file mode 100644 index 0000000..14778ef --- /dev/null +++ b/consumers/dfwebserver/python/other.html @@ -0,0 +1 @@ +text \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/python/setup.py ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/python/setup.py b/consumers/dfwebserver/python/setup.py new file mode 100644 index 0000000..8675b22 --- /dev/null +++ b/consumers/dfwebserver/python/setup.py @@ -0,0 +1,64 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +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/ee6e8174/consumers/dfwebserver/python/src/dfconvert.c ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/python/src/dfconvert.c b/consumers/dfwebserver/python/src/dfconvert.c new file mode 100644 index 0000000..b284222 --- /dev/null +++ b/consumers/dfwebserver/python/src/dfconvert.c @@ -0,0 +1,108 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include + +typedef struct DFError DFError; +void DFErrorRelease(DFError *error); +const char *DFErrorMessage(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) +{ + 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; +} + +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} +}; + + +/* module initialization */ +PyMODINIT_FUNC + +initdfconvert(void) +{ + (void) Py_InitModule("dfconvert", dfconvertMethods); +} http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/python/src/dfutil.c ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/python/src/dfutil.c b/consumers/dfwebserver/python/src/dfutil.c new file mode 100644 index 0000000..9e7b689 --- /dev/null +++ b/consumers/dfwebserver/python/src/dfutil.c @@ -0,0 +1,64 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include + +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/ee6e8174/consumers/dfwebserver/python/test.py ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/python/test.py b/consumers/dfwebserver/python/test.py new file mode 100644 index 0000000..213ee2b --- /dev/null +++ b/consumers/dfwebserver/python/test.py @@ -0,0 +1,42 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 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() + http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/python/testSubprocess.py ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/python/testSubprocess.py b/consumers/dfwebserver/python/testSubprocess.py new file mode 100644 index 0000000..e3bcfa6 --- /dev/null +++ b/consumers/dfwebserver/python/testSubprocess.py @@ -0,0 +1,52 @@ +#!/usr/bin/python + +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +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 http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/setup.py ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/setup.py b/consumers/dfwebserver/setup.py deleted file mode 100644 index d3cdf47..0000000 --- a/consumers/dfwebserver/setup.py +++ /dev/null @@ -1,51 +0,0 @@ -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/ee6e8174/consumers/dfwebserver/test.py ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/test.py b/consumers/dfwebserver/test.py deleted file mode 100644 index 13ee982..0000000 --- a/consumers/dfwebserver/test.py +++ /dev/null @@ -1,29 +0,0 @@ -# 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() - http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/testSubprocess.py ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/testSubprocess.py b/consumers/dfwebserver/testSubprocess.py deleted file mode 100644 index 7a67b1b..0000000 --- a/consumers/dfwebserver/testSubprocess.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/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 http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ee6e8174/consumers/dfwebserver/web/client/index.html ---------------------------------------------------------------------- diff --git a/consumers/dfwebserver/web/client/index.html b/consumers/dfwebserver/web/client/index.html index 47e5220..4b983f6 100644 --- a/consumers/dfwebserver/web/client/index.html +++ b/consumers/dfwebserver/web/client/index.html @@ -18,9 +18,14 @@ iface.setup(function() { console.log("iface setup complete"); }, - "/consumers/web/client/sample.html", + "", "/Editor/src", "/consumers/web/client"); } + + function doDummyGet() { + document.getElementById("_content").src = "/consumers/dfwebserver/pool/sample.docx/sample.html"; + + }