ajout des sources originales

This commit is contained in:
Nicolas Pettiaux 2022-06-05 11:23:43 +02:00
parent 6c67cd1e8e
commit 4c7c6bd399
29 changed files with 4863 additions and 0 deletions

336
OOoPy-1.11/PKG-INFO Normal file
View File

@ -0,0 +1,336 @@
Metadata-Version: 1.1
Name: OOoPy
Version: 1.11
Summary: OOoPy: Modify OpenOffice.org documents in Python
Home-page: http://ooopy.sourceforge.net/
Author: Ralf Schlatterbeck
Author-email: rsc@runtux.com
License: GNU Library or Lesser General Public License (LGPL)
Download-URL: http://downloads.sourceforge.net/project/ooopy/ooopy/1.11/OOoPy-1.11.tar.gz
Description:
OOoPy: Modify OpenOffice.org documents in Python
================================================
:Author: Ralf Schlatterbeck <rsc@runtux.com>
OpenOffice.org (OOo) documents are ZIP archives containing several XML
files. Therefore it is easy to inspect, create, or modify OOo
documents. OOoPy is a library in Python for these tasks with OOo
documents. To not reinvent the wheel, OOoPy uses an existing XML
library, ElementTree_ by Fredrik Lundh. OOoPy is a thin wrapper around
ElementTree_ using Python's ZipFile to read and write OOo documents.
.. _ElementTree: http://effbot.org/zone/element-index.htm
In addition to being a wrapper for ElementTree_, OOoPy contains a
framework for applying XML transforms to OOo documents. Several
Transforms for OOo documents exist, e.g., for changing OOo fields (OOo
Insert-Fields menu) or using OOo fields for a mail merge application.
Some other transformations for modifying OOo settings and meta
information are also given as examples.
Applications like this come in handy in applications where calling
native OOo is not an option, e.g., in server-side Web applications.
If the mailmerge transform doesn't work for your document: The OOo
format is well documented but there are ordering constraints in the body
of an OOo document.
I've not yet figured out all the tags and their order in the
OOo body. Individual elements in an OOo document (like e.g., frames,
sections, tables) need to have their own unique names. After a mailmerge,
there are duplicate names for some items. So far I'm renumbering only
frames, sections, and tables. See the renumber objects at the end of
ooopy/Transforms.py. So if you encounter missing parts of the mailmerged
document, check if there are some renumberings missing or send me a `bug
report`_.
.. _`bug report`: http://ooopy.sourceforge.net/#reporting-bugs
There is currently not much documentation except for a python doctest in
OOoPy.py and Transformer.py and the command-line utilities_.
For running these test, after installing
ooopy (assuming here you installed using python into /usr/local)::
cd /usr/local/share/ooopy
python run_doctest.py /usr/local/lib/python2.X/site-packages/ooopy/Transformer.py
python run_doctest.py /usr/local/lib/python2.X/site-packages/ooopy/OOoPy.py
Both should report no failed tests.
For running the doctest on python2.3 with the metaclass trickery of
autosuper, see the file run_doctest.py. For later versions of python the
bug in doctest is already fixed.
Usage
-----
There were some slight changes to the API when supporting the open
document format introduced with OOo 2.0. See below if you get a traceback
when upgrading from an old version.
See the online documentation, e.g.::
% python
>>> from ooopy.OOoPy import OOoPy
>>> help (OOoPy)
>>> from ooopy.Transformer import Transformer
>>> help (Transformer)
Help, I'm getting an AssertionError traceback from Transformer, e.g.::
Traceback (most recent call last):
File "./replace.py", line 17, in ?
t = Transformer(Field_Replace(replace = replace_dictionary))
File "/usr/local/lib/python2.4/site-packages/ooopy/Transformer.py", line 1226, in __init__
assert (mimetype in mimetypes)
AssertionError
The API changed slightly when implementing handling of different
versions of OOo files. Now the first parameter you pass to the
Transformer constructor is the mimetype of the OpenOffice.org document
you intend to transform. The mimetype can be fetched from another opened
OOo document, e.g.::
ooo = OOoPy (infile = 'test.odt', outfile = 'test_out.odt')
t = Transformer(ooo.mimetype, ...
Usage of Command-Line Utilities
-------------------------------
A, well, there are command-line _`utilities` now:
- ooo_cat for concatenating several OOo files into one
- ooo_grep to do equivalent of grep -l on OOo files -- only runs on
Unix-like operating systems, probably only with the GNU version of grep
(it's a shell-script using ooo_as_text)
- ooo_fieldreplace for replacing fields in an OOo document
- ooo_mailmerge for doing a mailmerge from a template OOo document and a
CSV (comma separated values) input
- ooo_as_text for getting the text from an OOo-File (e.g., for doing a
"grep" on the output).
- ooo_prettyxml for pretty-printing the XML nodes of one of the XML
files inside an OOo document. Mainly useful for debugging.
All utilities take a ``--help`` option.
Resources
---------
Project information and download from `Sourceforge main page`_
.. _`Sourceforge main page`: http://sourceforge.net/projects/ooopy/
You need at least version 2.3 of python.
For using OOoPy with Python versions below 2.5, you need to download and
install the
`ElementTree Library`_ by Fredrik Lundh. For documentation about the OOo
XML file format, see the book by J. David Eisenberg called
`OASIS OpenDocument Essentials`_ which is under the Gnu Free
Documentation License and is also available `in print`_. For a reference
document you may want to check out the `XML File Format Specification`_
(PDF) by OpenOffice.org.
A german page for OOoPy exists at `runtux.com`_
.. _`ElementTree Library`: http://effbot.org/downloads/#elementtree
.. _`OASIS OpenDocument Essentials`: http://books.evc-cit.info/
.. _`in print`:
http://www.lulu.com/product/paperback/oasis-opendocument-essentials/392512
.. _`XML File Format Specification`:
http://xml.openoffice.org/xml_specification.pdf
.. _`runtux.com`: http://www.runtux.com/ooopy.html
Reporting Bugs
--------------
Please use the `Sourceforge Bug Tracker`_ and
- attach the OOo document that reproduces your problem
- give a short description of what you think is the correct behaviour
- give a description of the observed behaviour
- tell me exactly what you did.
.. _`Sourceforge Bug Tracker`:
http://sourceforge.net/tracker/?group_id=134329&atid=729727
Changes
-------
Version 1.11: Small Bug fix ooo_mailmerge
Now ooo_mailmerge uses the delimiter option, it was ignored before.
Thanks to Bob Danek for report and test.
- Fix setting csv delimiter in ooo_mailmerge
Version 1.10: Fix table styles when concatenating
Now ooo_cat fixes tables styles when concatenating (renaming): We
optimize style usage by re-using existing styles. But for some table
styles the original names were not renamed to the re-used ones.
Fixes SF Bug 10, thanks to Claudio Girlanda for reporting.
- Fix style renaming for table styles when concatenating documents
- Add some missing namespaces (ooo 2009)
Version 1.9: Add Picture Handling for Concatenation
Now ooo_cat supports pictures, thanks to Antonio Sánchez for reporting
that this wasn't working.
- Add a list of filenames + contents to Transformer
- Update this file-list in Concatenate
- Add Manifest_Append transform to update META-INF/manifest.xml with
added filenames
- Add hook in OOoPy for adding files
- Update tests
- Update ooo_cat to use new transform
- This is the first release after migration of the version control from
Subversion to GIT
Version 1.8: Minor bugfixes
Distribute a missing file that is used in the doctest. Fix directory
structure. Thanks to Michael Nagel for suggesting the change and
reporting the bug.
- The file ``testenum.odt`` was missing from MANIFEST.in
- All OOo files and other files needed for testing are now in the
subdirectory ``testfiles``.
- All command line utilities are now in subdirectory ``bin``.
Version 1.7: Minor feature additions
Add --newlines option to ooo_as_text: With this option the paragraphs in
the office document are preserved in the text output.
Fix assertion error with python2.7, thanks to Hans-Peter Jansen for the
report. Several other small fixes for python2.7 vs. 2.6.
- add --newlines option to ooo_as_text
- fix assertion error with python2.7 reported by Hans-Peter Jansen
- fix several deprecation warnings with python2.7
- remove zip compression sizes from regression test: the compressor in
python2.7 is better than the one in python2.6
Version 1.6: Minor bugfixes
Fix compression: when writing new XML-files these would be stored
instead of compressed in the OOo zip-file resulting in big documents.
Thanks to Hans-Peter Jansen for the patch. Add copyright notice to
command-line utils (SF Bug 2650042). Fix mailmerge for OOo 3.X lists (SF
Bug 2949643).
- fix compression flag, patch by Hans-Peter Jansen
- add regression test to check for compression
- now release ooo_prettyxml -- I've used this for testing for quite
some time, may be useful to others
- Add copyright (LGPL) notice to command-line utilities, fixes SF Bug
2650042
- OOo 3.X adds xml:id tags to lists, we now renumber these in the
mailmerge app., fixes SF Bug 2949643
Version 1.5: Minor feature enhancements
Add ooo_grep to search for OOo files containing a pattern. Thanks to
Mathieu Chauvinc for the reporting the problems with modified
manifest.xml.
Support python2.6, thanks to Erik Myllymaki for reporting and anonymous
contributor(s) for confirming the bug.
- New shell-script ooo_grep (does equivalent to grep -l on OOo Files)
- On deletion of an OOoPy object close it explicitly (uses __del__)
- Ensure mimetype is the first element in the resulting archive, seems
OOo is picky about this.
- When modifying the manifest the resulting .odt file could not be
opened by OOo. So when modifying manifest make sure the manifest
namespace is named "manifest" not something auto-generated by
ElementTree. I consider this a bug in OOo to require this. This now
uses the _namespace_map of ElementTree and uses the same names as OOo
for all namespaces. The META-INF/manifest.xml is now in the list of
files to which Transforms can be applied.
- When modifying (or creating) archive members, we create the OOo
archive as if it was a DOS system (type fat) and ensure we use the
current date/time (UTC). This also fixes problems with file
permissions on newer versions of pythons ZipFile.
- Fix for python2.6 behavior that __init__ of object may not take any
arguments. Fixes SF Bug 2948617.
- Finally -- since OOoPy is in production in some projects -- change the
development status to "Production/Stable".
Version 1.4: Minor bugfixes
Fix Doctest to hopefully run on windows. Thanks to Dani Budinova for
testing thoroughly under windows.
- Open output-files in "wb" mode instead of "w" in doctest to not
create corrupt OOo documents on windows.
- Use double quotes for arguments when calling system, single quotes
don't seem to work on windows.
- Dont use redirection when calling system, use -i option for input
file instead. Redirection seems to be a problem on windows.
- Explicitly call the python-interpreter, running a script directly is
not supported on windows.
Version 1.3: Minor bugfixes
Regression-test failed because some files were not distributed.
Fixes SF Bugs 1970389 and 1972900.
- Fix MANIFEST.in to include all files needed for regression test
(doctest).
Version 1.2: Major feature enhancements
Add ooo_fieldreplace, ooo_cat, ooo_mailmerge command-line utilities. Fix
ooo_as_text to allow specification of output-file. Note that handling of
non-seekable input/output (pipes) for command-line utils will work only
starting with python2.5. Minor bug-fix when concatenating documents.
- Fix _divide (used for dividing body into parts that must keep
sequence). If one of the sections was empty, body parts would change
sequence.
- Fix handling of cases where we don't have a paragraph (only list) elements
- Implement ooo_cat
- Fix ooo_as_text to include more command-line handling
- Fix reading/writing stdin/stdout for command-line utilities, this
will work reliably (reading/writing non-seekable input/output like,
e.g., pipes) only with python2.5
- implement ooo_fieldreplace and ooo_mailmerge
Version 1.1: Minor bugfixes
Small Documentation changes
- Fix css stylesheet
- Link to SF logo for Homepage
- Link to other information updated
- Version numbers in documentation fixed
- Add some checks for new API -- first parameter of Transformer is checked now
- Ship files needed for running the doctest and explain how to run it
- Usage section
Version 1.0: Major feature enhancements
Now works with version 2.X of OpenOffice.org. Minor API changes.
- Tested with python 2.3, 2.4, 2.5
- OOoPy now works for OOo version 1.X and version 2.X
- New attribute mimetype of OOoPy -- this is automatically set when
reading a document, and should be set when writing one.
- renumber_all, get_meta, set_meta are now factory functions that take
the mimetype of the open office document as a parameter.
- Since renumber_all is now a function it will (correctly) restart
numbering for each new Attribute_Access instance it returns.
- Built-in elementtree support from python2.5 is used if available
- Fix bug in optimisation of original document for concatenation
Platform: Any
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Office/Business :: Office Suites
Classifier: Topic :: Text Processing
Classifier: Topic :: Text Processing :: General
Classifier: Topic :: Text Processing :: Markup :: XML
Classifier: Topic :: Text Editors :: Word Processors

593
OOoPy-1.11/README.html Normal file
View File

@ -0,0 +1,593 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.8.1: http://docutils.sourceforge.net/" />
<title></title>
<style type="text/css">
/*
:Author: David Goodger
:Contact: goodger@users.sourceforge.net
:Date: $Date: 2007-12-21 16:51:22 +0100 (Fri, 21 Dec 2007) $
:Version: $Revision: 4316 $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
*/
/* "! important" is used here to override other ``margin-top`` and
``margin-bottom`` styles that are later in the stylesheet or
more specific. See <http://www.w3.org/TR/CSS1#the-cascade>. */
.first {
margin-top: 0 ! important }
.last {
margin-bottom: 0 ! important }
.hidden {
display: none }
a.toc-backref {
text-decoration: none ;
color: black }
a.reference img {
border-width: 0px ;
}
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em }
div.footer, div.header {
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin-left: 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font-family: serif ;
font-size: 100% }
pre.line-block {
font-family: serif ;
font-size: 100% }
pre.literal-block, pre.doctest-block {
margin-left: 2em ;
margin-right: 2em ;
background-color: #eeeeee }
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
table.citation {
border-left: solid thin gray }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid thin black }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
th.docinfo-name, th.field-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap }
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
tt.docutils {
background-color: #eeeeee }
ul.auto-toc {
list-style-type: none }
body {
background-color: #F0F0FF }
p img {
vertical-align: text-top }
</style>
</head>
<body>
<div class="document">
<a class="reference external image-reference" href="http://sourceforge.net/projects/ooopy/"><img alt="SourceForge.net Logo" src="http://sflogo.sourceforge.net/sflogo.php?group_id=134329&amp;type=7" style="width: 210px; height: 62px;" /></a>
<div class="section" id="ooopy-modify-openoffice-org-documents-in-python">
<h1>OOoPy: Modify OpenOffice.org documents in Python</h1>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Author:</th><td class="field-body">Ralf Schlatterbeck &lt;<a class="reference external" href="mailto:rsc&#64;runtux.com">rsc&#64;runtux.com</a>&gt;</td>
</tr>
</tbody>
</table>
<p>OpenOffice.org (OOo) documents are ZIP archives containing several XML
files. Therefore it is easy to inspect, create, or modify OOo
documents. OOoPy is a library in Python for these tasks with OOo
documents. To not reinvent the wheel, OOoPy uses an existing XML
library, <a class="reference external" href="http://effbot.org/zone/element-index.htm">ElementTree</a> by Fredrik Lundh. OOoPy is a thin wrapper around
<a class="reference external" href="http://effbot.org/zone/element-index.htm">ElementTree</a> using Python's ZipFile to read and write OOo documents.</p>
<p>In addition to being a wrapper for <a class="reference external" href="http://effbot.org/zone/element-index.htm">ElementTree</a>, OOoPy contains a
framework for applying XML transforms to OOo documents. Several
Transforms for OOo documents exist, e.g., for changing OOo fields (OOo
Insert-Fields menu) or using OOo fields for a mail merge application.
Some other transformations for modifying OOo settings and meta
information are also given as examples.</p>
<p>Applications like this come in handy in applications where calling
native OOo is not an option, e.g., in server-side Web applications.</p>
<p>If the mailmerge transform doesn't work for your document: The OOo
format is well documented but there are ordering constraints in the body
of an OOo document.
I've not yet figured out all the tags and their order in the
OOo body. Individual elements in an OOo document (like e.g., frames,
sections, tables) need to have their own unique names. After a mailmerge,
there are duplicate names for some items. So far I'm renumbering only
frames, sections, and tables. See the renumber objects at the end of
ooopy/Transforms.py. So if you encounter missing parts of the mailmerged
document, check if there are some renumberings missing or send me a <a class="reference external" href="http://ooopy.sourceforge.net/#reporting-bugs">bug
report</a>.</p>
<p>There is currently not much documentation except for a python doctest in
OOoPy.py and Transformer.py and the command-line <a class="reference internal" href="#utilities">utilities</a>.
For running these test, after installing
ooopy (assuming here you installed using python into /usr/local):</p>
<pre class="literal-block">
cd /usr/local/share/ooopy
python run_doctest.py /usr/local/lib/python2.X/site-packages/ooopy/Transformer.py
python run_doctest.py /usr/local/lib/python2.X/site-packages/ooopy/OOoPy.py
</pre>
<p>Both should report no failed tests.
For running the doctest on python2.3 with the metaclass trickery of
autosuper, see the file run_doctest.py. For later versions of python the
bug in doctest is already fixed.</p>
<div class="section" id="usage">
<h2>Usage</h2>
<p>There were some slight changes to the API when supporting the open
document format introduced with OOo 2.0. See below if you get a traceback
when upgrading from an old version.</p>
<p>See the online documentation, e.g.:</p>
<pre class="literal-block">
% python
&gt;&gt;&gt; from ooopy.OOoPy import OOoPy
&gt;&gt;&gt; help (OOoPy)
&gt;&gt;&gt; from ooopy.Transformer import Transformer
&gt;&gt;&gt; help (Transformer)
</pre>
<p>Help, I'm getting an AssertionError traceback from Transformer, e.g.:</p>
<pre class="literal-block">
Traceback (most recent call last):
File &quot;./replace.py&quot;, line 17, in ?
t = Transformer(Field_Replace(replace = replace_dictionary))
File &quot;/usr/local/lib/python2.4/site-packages/ooopy/Transformer.py&quot;, line 1226, in __init__
assert (mimetype in mimetypes)
AssertionError
</pre>
<p>The API changed slightly when implementing handling of different
versions of OOo files. Now the first parameter you pass to the
Transformer constructor is the mimetype of the OpenOffice.org document
you intend to transform. The mimetype can be fetched from another opened
OOo document, e.g.:</p>
<pre class="literal-block">
ooo = OOoPy (infile = 'test.odt', outfile = 'test_out.odt')
t = Transformer(ooo.mimetype, ...
</pre>
</div>
<div class="section" id="usage-of-command-line-utilities">
<h2>Usage of Command-Line Utilities</h2>
<p>A, well, there are command-line <span class="target" id="utilities">utilities</span> now:</p>
<ul class="simple">
<li>ooo_cat for concatenating several OOo files into one</li>
<li>ooo_grep to do equivalent of grep -l on OOo files -- only runs on
Unix-like operating systems, probably only with the GNU version of grep
(it's a shell-script using ooo_as_text)</li>
<li>ooo_fieldreplace for replacing fields in an OOo document</li>
<li>ooo_mailmerge for doing a mailmerge from a template OOo document and a
CSV (comma separated values) input</li>
<li>ooo_as_text for getting the text from an OOo-File (e.g., for doing a
&quot;grep&quot; on the output).</li>
<li>ooo_prettyxml for pretty-printing the XML nodes of one of the XML
files inside an OOo document. Mainly useful for debugging.</li>
</ul>
<p>All utilities take a <tt class="docutils literal"><span class="pre">--help</span></tt> option.</p>
</div>
<div class="section" id="resources">
<h2>Resources</h2>
<p>Project information and download from <a class="reference external" href="http://sourceforge.net/projects/ooopy/">Sourceforge main page</a></p>
<p>You need at least version 2.3 of python.</p>
<p>For using OOoPy with Python versions below 2.5, you need to download and
install the
<a class="reference external" href="http://effbot.org/downloads/#elementtree">ElementTree Library</a> by Fredrik Lundh. For documentation about the OOo
XML file format, see the book by J. David Eisenberg called
<a class="reference external" href="http://books.evc-cit.info/">OASIS OpenDocument Essentials</a> which is under the Gnu Free
Documentation License and is also available <a class="reference external" href="http://www.lulu.com/product/paperback/oasis-opendocument-essentials/392512">in print</a>. For a reference
document you may want to check out the <a class="reference external" href="http://xml.openoffice.org/xml_specification.pdf">XML File Format Specification</a>
(PDF) by OpenOffice.org.</p>
<p>A german page for OOoPy exists at <a class="reference external" href="http://www.runtux.com/ooopy.html">runtux.com</a></p>
</div>
<div class="section" id="reporting-bugs">
<h2>Reporting Bugs</h2>
<p>Please use the <a class="reference external" href="http://sourceforge.net/tracker/?group_id=134329&amp;atid=729727">Sourceforge Bug Tracker</a> and</p>
<blockquote>
<ul class="simple">
<li>attach the OOo document that reproduces your problem</li>
<li>give a short description of what you think is the correct behaviour</li>
<li>give a description of the observed behaviour</li>
<li>tell me exactly what you did.</li>
</ul>
</blockquote>
</div>
<div class="section" id="changes">
<h2>Changes</h2>
<p>Version 1.11: Small Bug fix ooo_mailmerge</p>
<p>Now ooo_mailmerge uses the delimiter option, it was ignored before.
Thanks to Bob Danek for report and test.</p>
<blockquote>
<ul class="simple">
<li>Fix setting csv delimiter in ooo_mailmerge</li>
</ul>
</blockquote>
<p>Version 1.10: Fix table styles when concatenating</p>
<p>Now ooo_cat fixes tables styles when concatenating (renaming): We
optimize style usage by re-using existing styles. But for some table
styles the original names were not renamed to the re-used ones.
Fixes SF Bug 10, thanks to Claudio Girlanda for reporting.</p>
<blockquote>
<ul class="simple">
<li>Fix style renaming for table styles when concatenating documents</li>
<li>Add some missing namespaces (ooo 2009)</li>
</ul>
</blockquote>
<p>Version 1.9: Add Picture Handling for Concatenation</p>
<p>Now ooo_cat supports pictures, thanks to Antonio Sánchez for reporting
that this wasn't working.</p>
<blockquote>
<ul class="simple">
<li>Add a list of filenames + contents to Transformer</li>
<li>Update this file-list in Concatenate</li>
<li>Add Manifest_Append transform to update META-INF/manifest.xml with
added filenames</li>
<li>Add hook in OOoPy for adding files</li>
<li>Update tests</li>
<li>Update ooo_cat to use new transform</li>
<li>This is the first release after migration of the version control from
Subversion to GIT</li>
</ul>
</blockquote>
<p>Version 1.8: Minor bugfixes</p>
<p>Distribute a missing file that is used in the doctest. Fix directory
structure. Thanks to Michael Nagel for suggesting the change and
reporting the bug.</p>
<blockquote>
<ul class="simple">
<li>The file <tt class="docutils literal">testenum.odt</tt> was missing from MANIFEST.in</li>
<li>All OOo files and other files needed for testing are now in the
subdirectory <tt class="docutils literal">testfiles</tt>.</li>
<li>All command line utilities are now in subdirectory <tt class="docutils literal">bin</tt>.</li>
</ul>
</blockquote>
<p>Version 1.7: Minor feature additions</p>
<p>Add --newlines option to ooo_as_text: With this option the paragraphs in
the office document are preserved in the text output.
Fix assertion error with python2.7, thanks to Hans-Peter Jansen for the
report. Several other small fixes for python2.7 vs. 2.6.</p>
<blockquote>
<ul class="simple">
<li>add --newlines option to ooo_as_text</li>
<li>fix assertion error with python2.7 reported by Hans-Peter Jansen</li>
<li>fix several deprecation warnings with python2.7</li>
<li>remove zip compression sizes from regression test: the compressor in
python2.7 is better than the one in python2.6</li>
</ul>
</blockquote>
<p>Version 1.6: Minor bugfixes</p>
<p>Fix compression: when writing new XML-files these would be stored
instead of compressed in the OOo zip-file resulting in big documents.
Thanks to Hans-Peter Jansen for the patch. Add copyright notice to
command-line utils (SF Bug 2650042). Fix mailmerge for OOo 3.X lists (SF
Bug 2949643).</p>
<blockquote>
<ul class="simple">
<li>fix compression flag, patch by Hans-Peter Jansen</li>
<li>add regression test to check for compression</li>
<li>now release ooo_prettyxml -- I've used this for testing for quite
some time, may be useful to others</li>
<li>Add copyright (LGPL) notice to command-line utilities, fixes SF Bug
2650042</li>
<li>OOo 3.X adds xml:id tags to lists, we now renumber these in the
mailmerge app., fixes SF Bug 2949643</li>
</ul>
</blockquote>
<p>Version 1.5: Minor feature enhancements</p>
<p>Add ooo_grep to search for OOo files containing a pattern. Thanks to
Mathieu Chauvinc for the reporting the problems with modified
manifest.xml.
Support python2.6, thanks to Erik Myllymaki for reporting and anonymous
contributor(s) for confirming the bug.</p>
<blockquote>
<ul class="simple">
<li>New shell-script ooo_grep (does equivalent to grep -l on OOo Files)</li>
<li>On deletion of an OOoPy object close it explicitly (uses __del__)</li>
<li>Ensure mimetype is the first element in the resulting archive, seems
OOo is picky about this.</li>
<li>When modifying the manifest the resulting .odt file could not be
opened by OOo. So when modifying manifest make sure the manifest
namespace is named &quot;manifest&quot; not something auto-generated by
ElementTree. I consider this a bug in OOo to require this. This now
uses the _namespace_map of ElementTree and uses the same names as OOo
for all namespaces. The META-INF/manifest.xml is now in the list of
files to which Transforms can be applied.</li>
<li>When modifying (or creating) archive members, we create the OOo
archive as if it was a DOS system (type fat) and ensure we use the
current date/time (UTC). This also fixes problems with file
permissions on newer versions of pythons ZipFile.</li>
<li>Fix for python2.6 behavior that __init__ of object may not take any
arguments. Fixes SF Bug 2948617.</li>
<li>Finally -- since OOoPy is in production in some projects -- change the
development status to &quot;Production/Stable&quot;.</li>
</ul>
</blockquote>
<p>Version 1.4: Minor bugfixes</p>
<p>Fix Doctest to hopefully run on windows. Thanks to Dani Budinova for
testing thoroughly under windows.</p>
<blockquote>
<ul class="simple">
<li>Open output-files in &quot;wb&quot; mode instead of &quot;w&quot; in doctest to not
create corrupt OOo documents on windows.</li>
<li>Use double quotes for arguments when calling system, single quotes
don't seem to work on windows.</li>
<li>Dont use redirection when calling system, use -i option for input
file instead. Redirection seems to be a problem on windows.</li>
<li>Explicitly call the python-interpreter, running a script directly is
not supported on windows.</li>
</ul>
</blockquote>
<p>Version 1.3: Minor bugfixes</p>
<p>Regression-test failed because some files were not distributed.
Fixes SF Bugs 1970389 and 1972900.</p>
<blockquote>
<ul class="simple">
<li>Fix MANIFEST.in to include all files needed for regression test
(doctest).</li>
</ul>
</blockquote>
<p>Version 1.2: Major feature enhancements</p>
<p>Add ooo_fieldreplace, ooo_cat, ooo_mailmerge command-line utilities. Fix
ooo_as_text to allow specification of output-file. Note that handling of
non-seekable input/output (pipes) for command-line utils will work only
starting with python2.5. Minor bug-fix when concatenating documents.</p>
<blockquote>
<ul class="simple">
<li>Fix _divide (used for dividing body into parts that must keep
sequence). If one of the sections was empty, body parts would change
sequence.</li>
<li>Fix handling of cases where we don't have a paragraph (only list) elements</li>
<li>Implement ooo_cat</li>
<li>Fix ooo_as_text to include more command-line handling</li>
<li>Fix reading/writing stdin/stdout for command-line utilities, this
will work reliably (reading/writing non-seekable input/output like,
e.g., pipes) only with python2.5</li>
<li>implement ooo_fieldreplace and ooo_mailmerge</li>
</ul>
</blockquote>
<p>Version 1.1: Minor bugfixes</p>
<p>Small Documentation changes</p>
<blockquote>
<ul class="simple">
<li>Fix css stylesheet</li>
<li>Link to SF logo for Homepage</li>
<li>Link to other information updated</li>
<li>Version numbers in documentation fixed</li>
<li>Add some checks for new API -- first parameter of Transformer is checked now</li>
<li>Ship files needed for running the doctest and explain how to run it</li>
<li>Usage section</li>
</ul>
</blockquote>
<p>Version 1.0: Major feature enhancements</p>
<p>Now works with version 2.X of OpenOffice.org. Minor API changes.</p>
<blockquote>
<ul class="simple">
<li>Tested with python 2.3, 2.4, 2.5</li>
<li>OOoPy now works for OOo version 1.X and version 2.X</li>
<li>New attribute mimetype of OOoPy -- this is automatically set when
reading a document, and should be set when writing one.</li>
<li>renumber_all, get_meta, set_meta are now factory functions that take
the mimetype of the open office document as a parameter.</li>
<li>Since renumber_all is now a function it will (correctly) restart
numbering for each new Attribute_Access instance it returns.</li>
<li>Built-in elementtree support from python2.5 is used if available</li>
<li>Fix bug in optimisation of original document for concatenation</li>
</ul>
</blockquote>
</div>
</div>
</div>
</body>
</html>

320
OOoPy-1.11/README.rst Normal file
View File

@ -0,0 +1,320 @@
.. image:: http://sflogo.sourceforge.net/sflogo.php?group_id=134329&type=7
:height: 62
:width: 210
:alt: SourceForge.net Logo
:target: http://sourceforge.net/projects/ooopy/
OOoPy: Modify OpenOffice.org documents in Python
================================================
:Author: Ralf Schlatterbeck <rsc@runtux.com>
OpenOffice.org (OOo) documents are ZIP archives containing several XML
files. Therefore it is easy to inspect, create, or modify OOo
documents. OOoPy is a library in Python for these tasks with OOo
documents. To not reinvent the wheel, OOoPy uses an existing XML
library, ElementTree_ by Fredrik Lundh. OOoPy is a thin wrapper around
ElementTree_ using Python's ZipFile to read and write OOo documents.
.. _ElementTree: http://effbot.org/zone/element-index.htm
In addition to being a wrapper for ElementTree_, OOoPy contains a
framework for applying XML transforms to OOo documents. Several
Transforms for OOo documents exist, e.g., for changing OOo fields (OOo
Insert-Fields menu) or using OOo fields for a mail merge application.
Some other transformations for modifying OOo settings and meta
information are also given as examples.
Applications like this come in handy in applications where calling
native OOo is not an option, e.g., in server-side Web applications.
If the mailmerge transform doesn't work for your document: The OOo
format is well documented but there are ordering constraints in the body
of an OOo document.
I've not yet figured out all the tags and their order in the
OOo body. Individual elements in an OOo document (like e.g., frames,
sections, tables) need to have their own unique names. After a mailmerge,
there are duplicate names for some items. So far I'm renumbering only
frames, sections, and tables. See the renumber objects at the end of
ooopy/Transforms.py. So if you encounter missing parts of the mailmerged
document, check if there are some renumberings missing or send me a `bug
report`_.
.. _`bug report`: http://ooopy.sourceforge.net/#reporting-bugs
There is currently not much documentation except for a python doctest in
OOoPy.py and Transformer.py and the command-line utilities_.
For running these test, after installing
ooopy (assuming here you installed using python into /usr/local)::
cd /usr/local/share/ooopy
python run_doctest.py /usr/local/lib/python2.X/site-packages/ooopy/Transformer.py
python run_doctest.py /usr/local/lib/python2.X/site-packages/ooopy/OOoPy.py
Both should report no failed tests.
For running the doctest on python2.3 with the metaclass trickery of
autosuper, see the file run_doctest.py. For later versions of python the
bug in doctest is already fixed.
Usage
-----
There were some slight changes to the API when supporting the open
document format introduced with OOo 2.0. See below if you get a traceback
when upgrading from an old version.
See the online documentation, e.g.::
% python
>>> from ooopy.OOoPy import OOoPy
>>> help (OOoPy)
>>> from ooopy.Transformer import Transformer
>>> help (Transformer)
Help, I'm getting an AssertionError traceback from Transformer, e.g.::
Traceback (most recent call last):
File "./replace.py", line 17, in ?
t = Transformer(Field_Replace(replace = replace_dictionary))
File "/usr/local/lib/python2.4/site-packages/ooopy/Transformer.py", line 1226, in __init__
assert (mimetype in mimetypes)
AssertionError
The API changed slightly when implementing handling of different
versions of OOo files. Now the first parameter you pass to the
Transformer constructor is the mimetype of the OpenOffice.org document
you intend to transform. The mimetype can be fetched from another opened
OOo document, e.g.::
ooo = OOoPy (infile = 'test.odt', outfile = 'test_out.odt')
t = Transformer(ooo.mimetype, ...
Usage of Command-Line Utilities
-------------------------------
A, well, there are command-line _`utilities` now:
- ooo_cat for concatenating several OOo files into one
- ooo_grep to do equivalent of grep -l on OOo files -- only runs on
Unix-like operating systems, probably only with the GNU version of grep
(it's a shell-script using ooo_as_text)
- ooo_fieldreplace for replacing fields in an OOo document
- ooo_mailmerge for doing a mailmerge from a template OOo document and a
CSV (comma separated values) input
- ooo_as_text for getting the text from an OOo-File (e.g., for doing a
"grep" on the output).
- ooo_prettyxml for pretty-printing the XML nodes of one of the XML
files inside an OOo document. Mainly useful for debugging.
All utilities take a ``--help`` option.
Resources
---------
Project information and download from `Sourceforge main page`_
.. _`Sourceforge main page`: http://sourceforge.net/projects/ooopy/
You need at least version 2.3 of python.
For using OOoPy with Python versions below 2.5, you need to download and
install the
`ElementTree Library`_ by Fredrik Lundh. For documentation about the OOo
XML file format, see the book by J. David Eisenberg called
`OASIS OpenDocument Essentials`_ which is under the Gnu Free
Documentation License and is also available `in print`_. For a reference
document you may want to check out the `XML File Format Specification`_
(PDF) by OpenOffice.org.
A german page for OOoPy exists at `runtux.com`_
.. _`ElementTree Library`: http://effbot.org/downloads/#elementtree
.. _`OASIS OpenDocument Essentials`: http://books.evc-cit.info/
.. _`in print`:
http://www.lulu.com/product/paperback/oasis-opendocument-essentials/392512
.. _`XML File Format Specification`:
http://xml.openoffice.org/xml_specification.pdf
.. _`runtux.com`: http://www.runtux.com/ooopy.html
Reporting Bugs
--------------
Please use the `Sourceforge Bug Tracker`_ and
- attach the OOo document that reproduces your problem
- give a short description of what you think is the correct behaviour
- give a description of the observed behaviour
- tell me exactly what you did.
.. _`Sourceforge Bug Tracker`:
http://sourceforge.net/tracker/?group_id=134329&atid=729727
Changes
-------
Version 1.11: Small Bug fix ooo_mailmerge
Now ooo_mailmerge uses the delimiter option, it was ignored before.
Thanks to Bob Danek for report and test.
- Fix setting csv delimiter in ooo_mailmerge
Version 1.10: Fix table styles when concatenating
Now ooo_cat fixes tables styles when concatenating (renaming): We
optimize style usage by re-using existing styles. But for some table
styles the original names were not renamed to the re-used ones.
Fixes SF Bug 10, thanks to Claudio Girlanda for reporting.
- Fix style renaming for table styles when concatenating documents
- Add some missing namespaces (ooo 2009)
Version 1.9: Add Picture Handling for Concatenation
Now ooo_cat supports pictures, thanks to Antonio Sánchez for reporting
that this wasn't working.
- Add a list of filenames + contents to Transformer
- Update this file-list in Concatenate
- Add Manifest_Append transform to update META-INF/manifest.xml with
added filenames
- Add hook in OOoPy for adding files
- Update tests
- Update ooo_cat to use new transform
- This is the first release after migration of the version control from
Subversion to GIT
Version 1.8: Minor bugfixes
Distribute a missing file that is used in the doctest. Fix directory
structure. Thanks to Michael Nagel for suggesting the change and
reporting the bug.
- The file ``testenum.odt`` was missing from MANIFEST.in
- All OOo files and other files needed for testing are now in the
subdirectory ``testfiles``.
- All command line utilities are now in subdirectory ``bin``.
Version 1.7: Minor feature additions
Add --newlines option to ooo_as_text: With this option the paragraphs in
the office document are preserved in the text output.
Fix assertion error with python2.7, thanks to Hans-Peter Jansen for the
report. Several other small fixes for python2.7 vs. 2.6.
- add --newlines option to ooo_as_text
- fix assertion error with python2.7 reported by Hans-Peter Jansen
- fix several deprecation warnings with python2.7
- remove zip compression sizes from regression test: the compressor in
python2.7 is better than the one in python2.6
Version 1.6: Minor bugfixes
Fix compression: when writing new XML-files these would be stored
instead of compressed in the OOo zip-file resulting in big documents.
Thanks to Hans-Peter Jansen for the patch. Add copyright notice to
command-line utils (SF Bug 2650042). Fix mailmerge for OOo 3.X lists (SF
Bug 2949643).
- fix compression flag, patch by Hans-Peter Jansen
- add regression test to check for compression
- now release ooo_prettyxml -- I've used this for testing for quite
some time, may be useful to others
- Add copyright (LGPL) notice to command-line utilities, fixes SF Bug
2650042
- OOo 3.X adds xml:id tags to lists, we now renumber these in the
mailmerge app., fixes SF Bug 2949643
Version 1.5: Minor feature enhancements
Add ooo_grep to search for OOo files containing a pattern. Thanks to
Mathieu Chauvinc for the reporting the problems with modified
manifest.xml.
Support python2.6, thanks to Erik Myllymaki for reporting and anonymous
contributor(s) for confirming the bug.
- New shell-script ooo_grep (does equivalent to grep -l on OOo Files)
- On deletion of an OOoPy object close it explicitly (uses __del__)
- Ensure mimetype is the first element in the resulting archive, seems
OOo is picky about this.
- When modifying the manifest the resulting .odt file could not be
opened by OOo. So when modifying manifest make sure the manifest
namespace is named "manifest" not something auto-generated by
ElementTree. I consider this a bug in OOo to require this. This now
uses the _namespace_map of ElementTree and uses the same names as OOo
for all namespaces. The META-INF/manifest.xml is now in the list of
files to which Transforms can be applied.
- When modifying (or creating) archive members, we create the OOo
archive as if it was a DOS system (type fat) and ensure we use the
current date/time (UTC). This also fixes problems with file
permissions on newer versions of pythons ZipFile.
- Fix for python2.6 behavior that __init__ of object may not take any
arguments. Fixes SF Bug 2948617.
- Finally -- since OOoPy is in production in some projects -- change the
development status to "Production/Stable".
Version 1.4: Minor bugfixes
Fix Doctest to hopefully run on windows. Thanks to Dani Budinova for
testing thoroughly under windows.
- Open output-files in "wb" mode instead of "w" in doctest to not
create corrupt OOo documents on windows.
- Use double quotes for arguments when calling system, single quotes
don't seem to work on windows.
- Dont use redirection when calling system, use -i option for input
file instead. Redirection seems to be a problem on windows.
- Explicitly call the python-interpreter, running a script directly is
not supported on windows.
Version 1.3: Minor bugfixes
Regression-test failed because some files were not distributed.
Fixes SF Bugs 1970389 and 1972900.
- Fix MANIFEST.in to include all files needed for regression test
(doctest).
Version 1.2: Major feature enhancements
Add ooo_fieldreplace, ooo_cat, ooo_mailmerge command-line utilities. Fix
ooo_as_text to allow specification of output-file. Note that handling of
non-seekable input/output (pipes) for command-line utils will work only
starting with python2.5. Minor bug-fix when concatenating documents.
- Fix _divide (used for dividing body into parts that must keep
sequence). If one of the sections was empty, body parts would change
sequence.
- Fix handling of cases where we don't have a paragraph (only list) elements
- Implement ooo_cat
- Fix ooo_as_text to include more command-line handling
- Fix reading/writing stdin/stdout for command-line utilities, this
will work reliably (reading/writing non-seekable input/output like,
e.g., pipes) only with python2.5
- implement ooo_fieldreplace and ooo_mailmerge
Version 1.1: Minor bugfixes
Small Documentation changes
- Fix css stylesheet
- Link to SF logo for Homepage
- Link to other information updated
- Version numbers in documentation fixed
- Add some checks for new API -- first parameter of Transformer is checked now
- Ship files needed for running the doctest and explain how to run it
- Usage section
Version 1.0: Major feature enhancements
Now works with version 2.X of OpenOffice.org. Minor API changes.
- Tested with python 2.3, 2.4, 2.5
- OOoPy now works for OOo version 1.X and version 2.X
- New attribute mimetype of OOoPy -- this is automatically set when
reading a document, and should be set when writing one.
- renumber_all, get_meta, set_meta are now factory functions that take
the mimetype of the open office document as a parameter.
- Since renumber_all is now a function it will (correctly) restart
numbering for each new Attribute_Access instance it returns.
- Built-in elementtree support from python2.5 is used if available
- Fix bug in optimisation of original document for concatenation

66
OOoPy-1.11/bin/ooo_as_text Executable file
View File

@ -0,0 +1,66 @@
#!/usr/bin/env python
# Copyright (C) 2007-10 Dr. Ralf Schlatterbeck Open Source Consulting.
# Reichergasse 131, A-3411 Weidling.
# Web: http://www.runtux.com Email: office@runtux.com
# All rights reserved
# ****************************************************************************
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# ****************************************************************************
import sys
from optparse import OptionParser
from StringIO import StringIO
from ooopy.OOoPy import OOoPy
from ooopy.Transforms import OOo_Tag
def as_text (node, out, mimetype, newlines=False) :
if node.text is not None :
print >> out, node.text.encode ('utf-8'),
for subnode in node :
as_text (subnode, out, mimetype, newlines)
if node.tail is not None :
print >> out, node.tail.encode ('utf-8'),
if newlines and node.tag == OOo_Tag ('text', 'p', mimetype) :
print >> out, ""
if __name__ == '__main__' :
usage = '%prog [-o|--output-file <filename>] [file, ...]'
parser = OptionParser (usage = usage)
parser.add_option \
( "-o", "--output-file"
, dest = "output_file"
, help = "Output file (defaults to stdout)"
, default = None
)
parser.add_option \
( "-n", "--newlines"
, help = "Add newlines after paragraphs"
, action = "store_true"
)
(options, args) = parser.parse_args ()
if options.output_file is None :
outfile = sys.stdout
else :
outfile = open (options.output_file, "w")
if len (args) < 1 :
infiles = [StringIO (sys.stdin.read ())]
else :
infiles = args
for f in infiles :
o = OOoPy (infile = f)
e = o.read ('content.xml')
as_text (e.getroot (), outfile, o.mimetype, options.newlines)

61
OOoPy-1.11/bin/ooo_cat Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env python
# Copyright (C) 2008-14 Dr. Ralf Schlatterbeck Open Source Consulting.
# Reichergasse 131, A-3411 Weidling.
# Web: http://www.runtux.com Email: office@runtux.com
# All rights reserved
# ****************************************************************************
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# ****************************************************************************
import sys
from optparse import OptionParser
from StringIO import StringIO
from ooopy.OOoPy import OOoPy
from ooopy.Transformer import Transformer
import ooopy.Transforms as Transforms
if __name__ == '__main__' :
usage = '%prog [-o|--output-file <filename>] [file, ...]'
parser = OptionParser (usage = usage)
parser.add_option \
( "-o", "--output-file"
, dest = "output_file"
, help = "Output file (defaults to stdout)"
, default = None
)
(options, args) = parser.parse_args ()
if len (args) < 1 :
infiles = [StringIO (sys.stdin.read ())]
else :
infiles = args
outfile = options.output_file
if outfile is None :
outfile = StringIO ()
o = OOoPy (infile = infiles [0], outfile = outfile)
if len (infiles) > 1 :
t = Transformer \
( o.mimetype
, Transforms.get_meta (o.mimetype)
, Transforms.Concatenate (* (infiles [1:]))
, Transforms.renumber_all (o.mimetype)
, Transforms.set_meta (o.mimetype)
, Transforms.Fix_OOo_Tag ()
, Transforms.Manifest_Append ()
)
t.transform (o)
o.close ()
if options.output_file is None :
sys.stdout.write (outfile.getvalue ())

65
OOoPy-1.11/bin/ooo_fieldreplace Executable file
View File

@ -0,0 +1,65 @@
#!/usr/bin/env python
# Copyright (C) 2008-10 Dr. Ralf Schlatterbeck Open Source Consulting.
# Reichergasse 131, A-3411 Weidling.
# Web: http://www.runtux.com Email: office@runtux.com
# All rights reserved
# ****************************************************************************
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# ****************************************************************************
import sys
from optparse import OptionParser
from StringIO import StringIO
from ooopy.OOoPy import OOoPy
from ooopy.Transformer import Transformer
import ooopy.Transforms as Transforms
if __name__ == '__main__' :
usage = \
'''%prog [-i|--input-file <filename>]
[-o|--output-file <filename>] [name=value, ...]'''
parser = OptionParser (usage = usage)
parser.add_option \
( "-i", "--input-file"
, dest = "input_file"
, help = "Input file (defaults to stdin)"
, default = None
)
parser.add_option \
( "-o", "--output-file"
, dest = "output_file"
, help = "Output file (defaults to stdout)"
, default = None
)
(options, args) = parser.parse_args ()
fields = dict (arg.split ('=', 1) for arg in args)
infile = options.input_file
outfile = options.output_file
if infile is None :
infile = StringIO (sys.stdin.read ())
if outfile is None :
outfile = StringIO ()
o = OOoPy (infile = infile, outfile = outfile)
t = Transformer \
( o.mimetype
, Transforms.Editinfo ()
, Transforms.Field_Replace (replace = fields)
, Transforms.Fix_OOo_Tag ()
)
t.transform (o)
o.close ()
if options.output_file is None :
sys.stdout.write (outfile.getvalue ())

104
OOoPy-1.11/bin/ooo_from_csv Executable file
View File

@ -0,0 +1,104 @@
#!/usr/bin/env python
# Copyright (C) 2010 Dr. Ralf Schlatterbeck Open Source Consulting.
# Reichergasse 131, A-3411 Weidling.
# Web: http://www.runtux.com Email: office@runtux.com
# All rights reserved
# ****************************************************************************
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# ****************************************************************************
import sys
from csv import reader
from optparse import OptionParser
from StringIO import StringIO
from ooopy.OOoPy import OOoPy, OOoElementTree, mimetypes
from ooopy.Transformer import OOo_Tag
from ooopy.Transforms import Element, SubElement
def from_csv (ooopy, incsv) :
""" Produce ElementTree from the CSV, then convert the Tree to the
content.csv file inside the given ooopy container
"""
mt = mimetypes [1]
root = Element (OOo_Tag ('office', 'document-content', mt))
body = SubElement (root, OOo_Tag ('office', 'body', mt))
#scrpt = SubElement (body, OOo_Tag ('office', 'scripts'))
#decl = SubElement (body, OOo_Tag ('office', 'font-face-decls'))
sheet = SubElement (body, OOo_Tag ('office', 'spreadsheet', mt))
table = SubElement (sheet, OOo_Tag ('table', 'table', mt), name = 'Sheet1')
tree = OOoElementTree (ooopy, 'content.xml', root)
for line in incsv :
row = SubElement (table, OOo_Tag ('table', 'table-row', mt))
for element in line :
cell = SubElement \
( row
, OOo_Tag ('table', 'table-cell', mt)
, {OOo_Tag ('office', 'value-type', mt) : "string"}
)
p = SubElement (cell, OOo_Tag ('text', 'p', mt))
p.text = element
tree.write ()
# Add META-INF/manifest.xml
root = Element (OOo_Tag ('manifest', 'manifest', mt))
SubElement \
( root, OOo_Tag ('manifest', 'file-entry', mt)
, { OOo_Tag ('manifest', 'media-type', mt) :
'application/vnd.oasis.opendocument.spreadsheet'
, OOo_Tag ('manifest', 'full-path', mt) : '/'
}
)
SubElement \
( root, OOo_Tag ('manifest', 'file-entry', mt)
, { OOo_Tag ('manifest', 'media-type', mt) : 'text/xml'
, OOo_Tag ('manifest', 'full-path', mt) : 'content.xml'
}
)
tree = OOoElementTree (ooopy, 'META-INF/manifest.xml', root)
tree.write ()
# end def from_csv
if __name__ == '__main__' :
parser = OptionParser ()
parser.add_option \
( "-i", "--input-file"
, dest = "input_file"
, help = "CSV Input file (defaults to stdin)"
, default = None
)
parser.add_option \
( "-o", "--output-file"
, dest = "output_file"
, help = "Output file (defaults to stdout)"
, default = None
)
parser.add_option \
( "-d", "--delimiter"
, help = "Delimiter of CSV file"
, default = ','
)
(opt, args) = parser.parse_args ()
outfile = opt.output_file
if opt.input_file :
incsv = reader (open (opt.input_file), delimiter = opt.delimiter)
else :
incsv = reader (sys.stdin, delimiter = opt.delimiter)
if outfile is None :
outfile = StringIO ()
o = OOoPy (outfile = outfile, mimetype = mimetypes [1])
from_csv (o, incsv)
o.close ()
if opt.output_file is None :
sys.stdout.write (outfile.getvalue ())

32
OOoPy-1.11/bin/ooo_grep Executable file
View File

@ -0,0 +1,32 @@
#!/bin/sh
# Copyright (C) 2008-10 Dr. Ralf Schlatterbeck Open Source Consulting.
# Reichergasse 131, A-3411 Weidling.
# Web: http://www.runtux.com Email: office@runtux.com
# All rights reserved
# ****************************************************************************
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# ****************************************************************************
# Run all given ooo files through ooo_as_text and grep -l for pattern
if [ $# -lt 2 ] ; then
echo "Usage: $0 <pattern> <ooofile> ..." 2>&1
exit 42
fi
pattern=$1
shift
for k in "$@" ; do
ooo_as_text "$k" | grep -l --label="$k" "$pattern"
done

69
OOoPy-1.11/bin/ooo_mailmerge Executable file
View File

@ -0,0 +1,69 @@
#!/usr/bin/env python
# Copyright (C) 2008-10 Dr. Ralf Schlatterbeck Open Source Consulting.
# Reichergasse 131, A-3411 Weidling.
# Web: http://www.runtux.com Email: office@runtux.com
# All rights reserved
# ****************************************************************************
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# ****************************************************************************
import sys
from optparse import OptionParser
from csv import DictReader
from StringIO import StringIO
from ooopy.OOoPy import OOoPy
from ooopy.Transformer import Transformer
import ooopy.Transforms as Transforms
if __name__ == '__main__' :
usage = \
'''%prog [-d|--delimiter X] [-o|--output-file <filename>]
<inputfile> <csv-file>'''
parser = OptionParser (usage = usage)
parser.add_option \
( "-d", "--delimiter"
, dest = "delimiter"
, help = "Delimiter of cvs-format (Default Tab)"
, default = '\t'
)
parser.add_option \
( "-o", "--output-file"
, dest = "output_file"
, help = "Output file (defaults to stdout)"
, default = None
)
(options, args) = parser.parse_args ()
if len (args) != 2 :
parser.error ('Missing arguments')
sys.exit (1)
outfile = options.output_file
if outfile is None :
outfile = StringIO ()
d = DictReader (open (args [1]), delimiter = options.delimiter)
o = OOoPy (infile = args [0], outfile = outfile)
t = Transformer \
( o.mimetype
, Transforms.get_meta (o.mimetype)
, Transforms.Addpagebreak_Style ()
, Transforms.Mailmerge (iterator = d)
, Transforms.renumber_all (o.mimetype)
, Transforms.set_meta (o.mimetype)
, Transforms.Fix_OOo_Tag ()
)
t.transform (o)
o.close ()
if options.output_file is None :
sys.stdout.write (outfile.getvalue ())

80
OOoPy-1.11/bin/ooo_prettyxml Executable file
View File

@ -0,0 +1,80 @@
#!/usr/bin/env python
# Copyright (C) 2005-10 Dr. Ralf Schlatterbeck Open Source Consulting.
# Reichergasse 131, A-3411 Weidling.
# Web: http://www.runtux.com Email: office@runtux.com
# All rights reserved
# ****************************************************************************
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# ****************************************************************************
import sys
from optparse import OptionParser
from ooopy.OOoPy import OOoPy
from ooopy.Transformer import split_tag
def cleantag (tag) :
return ':'.join (split_tag (tag))
def pretty (n, indent = 0, with_text = False, ext_ns = False) :
s = [" " * indent]
clean = cleantag
if ext_ns :
clean = lambda x : x
s.append (clean (n.tag))
attrkeys = n.attrib.keys ()
attrkeys.sort ()
for a in attrkeys :
s.append (' %s="%s"' % (clean (a), n.attrib [a]))
if with_text and n.text is not None :
s.append (' TEXT="%s"' % n.text)
if with_text and n.tail is not None :
s.append (' TAIL="%s"' % n.tail)
print ''.join (s).encode ('utf-8')
for sub in n :
pretty (sub, indent + 1, with_text, ext_ns)
if __name__ == '__main__' :
usage = "%prog [options] file ..."
parser = OptionParser (usage = usage)
parser.add_option \
( "-f", "--file"
, dest = "ooofile"
, help = "XML-File inside OOo File"
, default = 'content.xml'
)
parser.add_option \
( "-t", "--with-text"
, dest = "with_text"
, action = "store_true"
, help = "Print text of xml nodes"
, default = False
)
parser.add_option \
( "-x", "--extend_namespaces"
, dest = "ext_ns"
, action = "store_true"
, help = "Print full text of namespace name"
, default = False
)
(opt, args) = parser.parse_args ()
if len (args) < 1 :
parser.print_help (sys.stderr)
sys.exit (23)
for f in args :
o = OOoPy (infile = f)
e = o.read (opt.ooofile)
pretty (e.getroot (), with_text