Skip to content

Commit

Permalink
Merge b2fd175 into d746fdd
Browse files Browse the repository at this point in the history
  • Loading branch information
odelaere committed Jun 6, 2019
2 parents d746fdd + b2fd175 commit 6cd0611
Show file tree
Hide file tree
Showing 15 changed files with 345 additions and 279 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -22,6 +22,7 @@ lib
lib64
include
local
share
src/appy
src/collective.excelexport

Expand Down
35 changes: 26 additions & 9 deletions .travis.yml
@@ -1,3 +1,5 @@
dist: xenial

language: python

python:
Expand All @@ -14,33 +16,48 @@ env:
- PLONE_VERSION=5.0
- PLONE_VERSION=5.1

services:
- docker

before_install:
- pip install --upgrade pip
- docker pull xcgd/libreoffice:5.1
- docker pull xcgd/libreoffice:latest

install:
- sudo apt-get -qq install libfreetype6-dev liblcms1-dev libreoffice
- sudo apt update -qq -y
- sudo apt install -qq -y libfreetype6-dev liblcms2-dev make libreoffice libreoffice-script-provider-python
- sudo apt autoremove -qq -y
- sudo apt autoclean -qq -y
- mkdir -p buildout-cache/{eggs,downloads}
- mkdir $HOME/tmp
- chmod 777 $HOME/tmp
- export TMPDIR=$HOME/tmp
- sed -ie "s#plone-5#plone-$PLONE_VERSION#" buildout.cfg
- sed -ie "s#travis-5#travis-$PLONE_VERSION#" travis.cfg
- pip install lxml --no-binary lxml
- python --version
- python bootstrap.py --version=2.10.0
- python -V
- pip install -r requirements.txt
- python bootstrap.py --version=2.11.4
- bin/buildout -N -c travis.cfg annotate
- bin/buildout -N -c travis.cfg
- bin/translation-manage -c
- bin/buildout -Nt 5 -c travis.cfg

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- docker run -p 127.0.0.1:2002:8997 -d --rm --name="oo_server" xcgd/libreoffice:5.1
- bin/translation-manage -c

script:
- docker ps
- bin/test
- docker stop oo_server
- docker run -p 127.0.0.1:2002:8997 -d --rm --name="oo_server" xcgd/libreoffice:latest
- docker ps
- bin/test
- docker stop oo_server
- /usr/bin/soffice --invisible --headless --nologo --nofirststartwizard --accept="socket,host=localhost,port=2002;urp" & > /dev/null 2>&1
- bin/test

after_success:
- bin/createcoverage
- bin/createcoverage -d htmlcov
- pip install --upgrade pip
- pip install -q coveralls==0.5
- coveralls
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -20,6 +20,8 @@ Changelog
[gbastien]
- Moved files CHANGES.rst, README.rst and CONTRIBUTORS.rst from docs/ to root.
[gbastien]
- Added ability to use an external server process for LibreOffice.
[odelaere]

3.6 (2019-03-27)
----------------
Expand Down
15 changes: 13 additions & 2 deletions Makefile
@@ -1,8 +1,10 @@
#!/usr/bin/make
#
lo_version=latest

all: run

.PHONY: bootstrap buildout run test cleanall
.PHONY: bootstrap buildout run test cleanall startlibreoffice stoplibreoffice
bootstrap:
virtualenv-2.7 .
pip install -r requirements.txt
Expand All @@ -19,9 +21,18 @@ run:

test:
if ! test -f bin/test;then make buildout;fi
make startlibreoffice
rm -fr htmlcov
bin/translation-manage -c
bin/test
make stoplibreoffice

cleanall:
rm -fr develop-eggs htmlcov include .installed.cfg lib .mr.developer.cfg parts downloads eggs
rm -fr bin develop-eggs htmlcov include .installed.cfg lib .mr.developer.cfg parts downloads eggs

startlibreoffice:
make stoplibreoffice
docker run -p 2002:8997 -d --rm --name="oo_server" xcgd/libreoffice:$(lo_version)

stoplibreoffice:
if docker ps | grep oo_server;then docker stop oo_server;fi
76 changes: 0 additions & 76 deletions bin/soffice.sh

This file was deleted.

3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -58,7 +58,8 @@
'z3c.table',
# fix about orderedselect
'z3c.form>=3.2.4',
'imio.helpers>=0.13',
'imio.helpers>=0.18',
'imio.migrator>=1.11'
],
extras_require={
'test': [
Expand Down
17 changes: 16 additions & 1 deletion src/collective/documentgenerator/browser/controlpanel.py
Expand Up @@ -41,6 +41,13 @@ class IDocumentGeneratorControlPanelSchema(Interface):
"""
"""

oo_server = schema.TextLine(
title=_(u'oo_server'),
description=_(u'IP address or hostname of OO.'),
required=False,
default=safe_unicode(os.getenv('OO_SERVER', u'localhost')),
)

oo_port = schema.Int(
title=_(u'oo_port'),
description=_(u'Port Number of OO.'),
Expand All @@ -52,7 +59,7 @@ class IDocumentGeneratorControlPanelSchema(Interface):
title=_(u'uno path'),
description=_(u'Path of python with uno.'),
required=False,
default=safe_unicode(os.getenv('PYTHON_UNO', u'/usr/bin/python')),
default=safe_unicode(os.getenv('PYTHON_UNO', u'/usr/bin/python3')),
constraint=check_for_uno
)

Expand All @@ -75,6 +82,14 @@ class IDocumentGeneratorControlPanelSchema(Interface):
default=False
)

use_stream = schema.Bool(
title=_(u'Force communication via in/out stream with LibreOffice.'),
description=_(u'If enabled, this will force using stream to communicate witth LibreOffice server. '
u'This must be true if the LO server is not on localhost or is in a docker container.'),
required=True,
default=True
)


class DocumentGeneratorControlPanelEditForm(RegistryEditForm):
implements(IDocumentGeneratorSettings)
Expand Down
31 changes: 30 additions & 1 deletion src/collective/documentgenerator/browser/generation_view.py
Expand Up @@ -227,18 +227,47 @@ def _render_document(self, pod_template, output_format, sub_documents, raiseOnEr
if 'Manager' in api.user.get_roles() and output_format == 'odt':
raiseOnError = False

# stylesMapping.update({'para[class=None, parent != cell]': 'texte_delibe',
# 'para[class=xSmallText, parent != cell]': 'bodyXSmall',
# 'para[class=smallText, parent != cell]': 'bodySmall',
# 'para[class=largeText, parent != cell]': 'bodyLarge',
# 'para[class=xLargeText, parent != cell]': 'bodyXLarge',
# 'para[class=indentation, parent != cell]': 'bodyIndentation',
# 'para[class=None, parent = cell]': 'cell_delibe',
# 'table': TableProperties(cellContentStyle='cell_delibe'),
# 'para[class=xSmallText, parent = cell]': 'cellXSmall',
# 'para[class=smallText, parent = cell]': 'cellSmall',
# 'para[class=largeText, parent = cell]': 'cellLarge',
# 'para[class=xLargeText, parent = cell]': 'cellXLarge',
# 'para[class=indentation, parent = cell]': 'cellIndentation',
# })
# stylesMapping.update({'para[class=None,parent!=cell]': 'texte_delibe',
# 'para[class=xSmallText,parent!=cell]': 'bodyXSmall',
# 'para[class=smallText,parent!=cell]': 'bodySmall',
# 'para[class=largeText,parent!=cell]': 'bodyLarge',
# 'para[class=xLargeText,parent!=cell]': 'bodyXLarge',
# 'para[class=indentation,parent!=cell]': 'bodyIndentation',
# 'para[class=xSmallText,parent=cell]': 'cellXSmall',
# 'para[class=smallText,parent=cell]': 'cellSmall',
# 'para[class=largeText,parent=cell]': 'cellLarge',
# 'para[class=xLargeText,parent=cell]': 'cellXLarge',
# 'para[class=indentation,parent=cell]': 'cellIndentation',
# })

renderer = Renderer(
StringIO(document_template.data),
generation_context,
temp_filename,
pythonWithUnoPath=config.get_uno_path(),
ooServer=config.get_oo_server(),
ooPort=config.get_oo_port(),
raiseOnError=raiseOnError,
imageResolver=api.portal.get(),
forceOoCall=True,
optimalColumnWidths=optimalColumnWidths,
distributeColumns=distributeColumns,
stylesMapping=stylesMapping,
stream=config.get_use_stream(),
**kwargs
)

Expand Down Expand Up @@ -449,7 +478,7 @@ def _get_base_args(self, template_uid, output_format):
if (not base_hasattr(self.orig_template, 'mailing_loop_template') or
not self.orig_template.mailing_loop_template):
raise Exception("Cannot find 'mailing_loop_template' on template '{0}'".format(
self.orig_template.absolute_url()))
self.orig_template.absolute_url()))
loop_template = self.get_pod_template(self.orig_template.mailing_loop_template)

if 'output_format' not in annot:
Expand Down
30 changes: 29 additions & 1 deletion src/collective/documentgenerator/config.py
Expand Up @@ -5,7 +5,6 @@

import os


ODS_FORMATS = (('ods', 'LibreOffice Calc (.ods)'),
('xls', 'Microsoft Excel (.xls)'),)

Expand All @@ -31,6 +30,12 @@ def get_uno_path():
)


def get_oo_server():
return api.portal.get_registry_record(
'collective.documentgenerator.browser.controlpanel.IDocumentGeneratorControlPanelSchema.oo_server'
)


def get_oo_port():
return api.portal.get_registry_record(
'collective.documentgenerator.browser.controlpanel.IDocumentGeneratorControlPanelSchema.oo_port'
Expand All @@ -50,6 +55,22 @@ def get_raiseOnError_for_non_managers():
)


def get_use_stream():
use_stream = api.portal.get_registry_record(
'collective.documentgenerator.browser.controlpanel.IDocumentGeneratorControlPanelSchema.use_stream'
)
# backward compat. Default value is auto
return use_stream or 'auto'


def set_oo_server():
""" Get environment value in buildout to define port """
oo_server = os.getenv('OO_SERVER', None)
if oo_server:
api.portal.set_registry_record('collective.documentgenerator.browser.controlpanel.'
'IDocumentGeneratorControlPanelSchema.oo_server', oo_server)


def set_oo_port():
""" Get environment value in buildout to define port """
oo_port = os.getenv('OO_PORT', None)
Expand Down Expand Up @@ -78,3 +99,10 @@ def set_raiseOnError_for_non_managers(value):
'collective.documentgenerator.browser.controlpanel.'
'IDocumentGeneratorControlPanelSchema.raiseOnError_for_non_managers',
value)


def set_use_stream(value):
api.portal.set_registry_record(
'collective.documentgenerator.browser.controlpanel.IDocumentGeneratorControlPanelSchema.use_stream',
value
)

0 comments on commit 6cd0611

Please sign in to comment.