Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
py3o.renderers.juno
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florent Aide
py3o.renderers.juno
Commits
51124079ebbd
Commit
51124079ebbd
authored
8 years ago
by
Florent Aide
Browse files
Options
Downloads
Patches
Plain Diff
dos2unix
parent
d1d529bd23aa
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
py3o/renderers/juno/__init__.py
+1
-1
1 addition, 1 deletion
py3o/renderers/juno/__init__.py
py3o/renderers/juno/main.py
+140
-145
140 additions, 145 deletions
py3o/renderers/juno/main.py
with
141 additions
and
146 deletions
py3o/renderers/juno/__init__.py
+
1
−
1
View file @
51124079
from
py3o.renderers.juno.main
import
Convertor
,
start_jvm
from
py3o.renderers.juno.main
import
Convertor
,
start_jvm
This diff is collapsed.
Click to expand it.
py3o/renderers/juno/main.py
+
140
−
145
View file @
51124079
import
jpype
from
jpype
import
startJVM
from
jpype
import
JPackage
import
os
import
platform
import
logging
import
pkg_resources
log
=
logging
.
getLogger
(
__name__
)
# define some hard coded jar resource we will try to find when starting the JVM
ureitems
=
[
"
juh.jar
"
,
"
jurt.jar
"
,
"
ridl.jar
"
,
"
unoloader.jar
"
,
"
java_uno.jar
"
]
basisitems
=
[
"
unoil.jar
"
,
]
def
get_oo_context
(
office_version
):
"""
returns a dict with the java_classpath_sep, ure_subpath
and oooclasses_subpath key pointing the (hopefully) correct sub paths
for the current running plateform. The implementer still needs
to provide the real base path for his plateform elsewhere in its
code though...
@param office_version: the version number of the desired
OpenOffice/LibreOffice
@type office_version: string
"""
context
=
dict
()
if
os
.
name
in
(
'
nt
'
,
'
os2
'
,
'
ce
'
):
# Windows
# tested to work with OpenOffice 3.2, we need to confirm
# it works with LibreOffice
context
[
'
java_classpath_sep
'
]
=
"
;
"
context
[
'
ure_subpath
'
]
=
os
.
path
.
join
(
'
URE
'
,
'
java
'
)
context
[
'
oooclasses_subpath
'
]
=
os
.
path
.
join
(
"
Basis
"
,
"
program
"
,
"
classes
"
)
else
:
context
[
'
java_classpath_sep
'
]
=
"
:
"
# TODO: do that properly
# for now, hard-code the stuff on CentOS5.5 x86_64 with OOo 3.1
# this is also working on RedHat RHEL 5 and on Ubuntu
context
[
'
oooclasses_subpath
'
]
=
os
.
path
.
join
(
"
program
"
,
"
classes
"
)
if
os
.
name
==
'
posix
'
and
platform
.
dist
()[
0
]
in
(
'
Ubuntu
'
,
'
debian
'
):
context
[
'
ure_subpath
'
]
=
'
java
'
else
:
context
[
'
ure_subpath
'
]
=
os
.
path
.
join
(
'
ure
'
,
'
share
'
,
'
java
'
)
return
context
def
start_jvm
(
jvm
,
oobase
,
urebase
,
office_version
,
max_mem
):
"""
this small function should be called only once. At the beginning
of your program.
It takes care of starting the JVM that will be used by our
convertor library with our requirements in terms of
classpath and memory usage
returns nothing
@param jvm: the jvm path to use :
ie c:/Program Files/Java/jre1.5.0_05/bin/client/jvm.dll
@type jvm: string
@param oobase: the base directory where we will
find basis3.3/program/classes where we find the unoil.jar package
@type oobase: string
@param urebase: the base directory where we will find ure/share/java inside
which we should find java_uno.jar, juh.jar, jurt.jar, unoloader.jar
@type oobase: string
@param office_version: the office version we want to use for rendering
@type office_version: string
@param max_mem: the maximum amount of mega bytes to allocate to
our JVM
@type max_mem: integer
"""
context
=
get_oo_context
(
office_version
)
java_classpath_sep
=
context
.
get
(
'
java_classpath_sep
'
)
ure_subpath
=
context
.
get
(
'
ure_subpath
'
)
oooclasses_subpath
=
context
.
get
(
'
oooclasses_subpath
'
)
# this is our internally compiled java class
jar
=
pkg_resources
.
resource_filename
(
'
py3o.renderers.juno
'
,
'
py3oconverter.jar
'
)
oojars
=
list
()
for
ureitem
in
ureitems
:
oojars
.
append
(
os
.
path
.
join
(
urebase
,
ure_subpath
,
ureitem
))
for
basisitem
in
basisitems
:
oojars
.
append
(
os
.
path
.
join
(
oobase
,
oooclasses_subpath
,
basisitem
))
convertor_lib
=
os
.
path
.
abspath
(
jar
)
java_classpath
=
'
-Djava.class.path=%s
'
%
(
convertor_lib
)
for
oojar
in
oojars
:
java_classpath
+=
"
%s%s
"
%
(
java_classpath_sep
,
oojar
)
# -Xms is initial memory for java, -Xmx is maximum memory for java
# java_initmem = "-Xms%sM" % max_mem
java_maxmem
=
"
-Xmx%sM
"
%
max_mem
jvm_abs
=
os
.
path
.
abspath
(
jvm
)
logging
.
debug
(
'
Starting JVM: %s with options: %s %s
'
%
(
jvm_abs
,
java_classpath
,
java_maxmem
))
startJVM
(
jvm_abs
,
java_classpath
,
java_maxmem
)
class
Convertor
(
object
):
def
__init__
(
self
,
host
,
port
):
"""
init our java lib with the host and port for the open office server
"""
if
not
jpype
.
isThreadAttachedToJVM
():
jpype
.
attachThreadToJVM
()
jconvertor_package
=
JPackage
(
'
py3oconverter
'
).
Convertor
self
.
jconvertor
=
jconvertor_package
(
host
,
port
)
def
convert
(
self
,
infilename
,
outfilename
,
filtername
):
"""
convert the input file using a certain filter produce a result
in outputfile.
:param infilename: a file name that must exist and be readable,
containing the input document to be converted
:type infilename: string
:param outfilename: a filename that must exit and be writeable,
inside which the convertor will save the result
:type outfilename: string
:param filtername: a LibreOffice filter name to use for conversion
:type filtername: string
:returns: nothing
:raises: jpype._jexception
"""
# use our java lib...
self
.
jconvertor
.
convert
(
infilename
,
outfilename
,
filtername
)
import
jpype
from
jpype
import
startJVM
from
jpype
import
JPackage
import
os
import
platform
import
logging
import
pkg_resources
log
=
logging
.
getLogger
(
__name__
)
# define some hard coded jar resource we will try to find when starting the JVM
ureitems
=
[
"
juh.jar
"
,
"
jurt.jar
"
,
"
ridl.jar
"
,
"
unoloader.jar
"
,
"
java_uno.jar
"
]
basisitems
=
[
"
unoil.jar
"
,
]
def
get_oo_context
():
"""
returns a dict with the java_classpath_sep, ure_subpath
and oooclasses_subpath key pointing the (hopefully) correct sub paths
for the current running plateform. The implementer still needs
to provide the real base path for his plateform elsewhere in its
code though...
@param office_version: the version number of the desired
OpenOffice/LibreOffice
@type office_version: string
"""
context
=
dict
()
if
os
.
name
in
(
'
nt
'
,
'
os2
'
,
'
ce
'
):
# Windows
# tested to work with OpenOffice 3.2, we need to confirm
# it works with LibreOffice
context
[
'
java_classpath_sep
'
]
=
"
;
"
context
[
'
ure_subpath
'
]
=
os
.
path
.
join
(
'
URE
'
,
'
java
'
)
context
[
'
oooclasses_subpath
'
]
=
os
.
path
.
join
(
"
Basis
"
,
"
program
"
,
"
classes
"
)
else
:
context
[
'
java_classpath_sep
'
]
=
"
:
"
context
[
'
oooclasses_subpath
'
]
=
os
.
path
.
join
(
"
program
"
,
"
classes
"
)
# TODO: add more platforms
if
os
.
name
==
'
posix
'
and
platform
.
dist
()[
0
]
in
(
'
Ubuntu
'
,
'
debian
'
):
context
[
'
ure_subpath
'
]
=
'
java
'
else
:
context
[
'
ure_subpath
'
]
=
os
.
path
.
join
(
'
ure
'
,
'
share
'
,
'
java
'
)
return
context
def
start_jvm
(
jvm
,
oobase
,
urebase
,
max_mem
):
"""
this small function should be called only once. At the beginning
of your program.
It takes care of starting the JVM that will be used by our
convertor library with our requirements in terms of
classpath and memory usage
returns nothing
@param jvm: the jvm path to use :
ie c:/Program Files/Java/jre1.5.0_05/bin/client/jvm.dll
@type jvm: string
@param oobase: the base directory where we will find the
program/classes/unoil.jar package
@type oobase: string
@param urebase: the base directory where we will find ure/share/java inside
which we should find java_uno.jar, juh.jar, jurt.jar, unoloader.jar
@type oobase: string
@param max_mem: the maximum amount of mega bytes to allocate to
our JVM
@type max_mem: integer
"""
context
=
get_oo_context
()
java_classpath_sep
=
context
.
get
(
'
java_classpath_sep
'
)
ure_subpath
=
context
.
get
(
'
ure_subpath
'
)
oooclasses_subpath
=
context
.
get
(
'
oooclasses_subpath
'
)
# this is our internally compiled java class
jar
=
pkg_resources
.
resource_filename
(
'
py3o.renderers.juno
'
,
'
py3oconverter.jar
'
)
oojars
=
list
()
for
ureitem
in
ureitems
:
oojars
.
append
(
os
.
path
.
join
(
urebase
,
ure_subpath
,
ureitem
))
for
basisitem
in
basisitems
:
oojars
.
append
(
os
.
path
.
join
(
oobase
,
oooclasses_subpath
,
basisitem
))
convertor_lib
=
os
.
path
.
abspath
(
jar
)
java_classpath
=
'
-Djava.class.path=%s
'
%
(
convertor_lib
)
for
oojar
in
oojars
:
java_classpath
+=
"
%s%s
"
%
(
java_classpath_sep
,
oojar
)
# -Xms is initial memory for java, -Xmx is maximum memory for java
# java_initmem = "-Xms%sM" % max_mem
java_maxmem
=
"
-Xmx%sM
"
%
max_mem
jvm_abs
=
os
.
path
.
abspath
(
jvm
)
logging
.
debug
(
'
Starting JVM: %s with options: %s %s
'
%
(
jvm_abs
,
java_classpath
,
java_maxmem
))
startJVM
(
jvm_abs
,
java_classpath
,
java_maxmem
)
class
Convertor
(
object
):
def
__init__
(
self
,
host
,
port
):
"""
init our java lib with the host and port for the open office server
"""
if
not
jpype
.
isThreadAttachedToJVM
():
jpype
.
attachThreadToJVM
()
jconvertor_package
=
JPackage
(
'
py3oconverter
'
).
Convertor
self
.
jconvertor
=
jconvertor_package
(
host
,
port
)
def
convert
(
self
,
infilename
,
outfilename
,
filtername
):
"""
convert the input file using a certain filter produce a result
in outputfile.
:param infilename: a file name that must exist and be readable,
containing the input document to be converted
:type infilename: string
:param outfilename: a filename that must exit and be writeable,
inside which the convertor will save the result
:type outfilename: string
:param filtername: a LibreOffice filter name to use for conversion
:type filtername: string
:returns: nothing
:raises: jpype._jexception
"""
# use our java lib...
self
.
jconvertor
.
convert
(
infilename
,
outfilename
,
filtername
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment