mattharrison / rst2odp

Create OpenOffice.org (impress) slideshows from restructured text (rst) or python
MIT License
27 stars 16 forks source link

Some templates do not apply #14

Closed raphink closed 12 years ago

raphink commented 12 years ago

When using rst2odp with the --template-file option, some templates fail to apply:

rst2odp --traceback --template-file /usr/lib/libreoffice/share/template/common/layout/lyt-roundedrect.otp intro.rst intro.odp 
Traceback (most recent call last):
  File "/usr/local/bin/rst2odp", line 5, in <module>
    pkg_resources.run_script('rst2odp==0.2.3', 'rst2odp')
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 499, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1235, in run_script
    execfile(script_filename, namespace, namespace)
  File "/usr/local/lib/python2.7/dist-packages/rst2odp-0.2.3-py2.7.egg/EGG-INFO/scripts/rst2odp", line 992, in <module>
    sys.exit(main(sys.argv) or 0)
  File "/usr/local/lib/python2.7/dist-packages/rst2odp-0.2.3-py2.7.egg/EGG-INFO/scripts/rst2odp", line 979, in main
    enable_exit_status=enable_exit_status)
  File "/usr/lib/python2.7/dist-packages/docutils/core.py", line 213, in publish
    output = self.writer.write(self.document, self.destination)
  File "/usr/lib/python2.7/dist-packages/docutils/writers/__init__.py", line 77, in write
    self.translate()
  File "/usr/local/lib/python2.7/dist-packages/rst2odp-0.2.3-py2.7.egg/EGG-INFO/scripts/rst2odp", line 123, in translate
    self.visitor = self.translator_class(self.document)
  File "/usr/local/lib/python2.7/dist-packages/rst2odp-0.2.3-py2.7.egg/EGG-INFO/scripts/rst2odp", line 138, in __init__
    self.preso.set_template(self.settings.template_file)
  File "/usr/local/lib/python2.7/dist-packages/rst2odp-0.2.3-py2.7.egg/odplib/preso.py", line 203, in set_template
    title_name, normal_name = list(self.get_master_page_names(style.cat('content.xml')))[:2]
ValueError: need more than 1 value to unpack

Other templates work fine though.

This is on Ubuntu 12.04 with LibreOffice 3.5.3, using rst2odp from git (@ 3eb80009fdb70915f65631fda59bcdf0c3c96873).

raphink commented 12 years ago

In some cases, styles only have one name. The simple fix for this is:

--- a/odplib/preso.py
+++ b/odplib/preso.py
@@ -200,7 +200,11 @@ class Preso(object):

     def set_template(self, style_file):
         style = zipwrap.ZipWrap(style_file)
-        title_name, normal_name = list(self.get_master_page_names(style.cat('content.xml')))[:2]
+       names = list(self.get_master_page_names(style.cat('content.xml')))[:2]
+       if len(names) == 2:
+            title_name, normal_name = names
+       else:
+           title_name, normal_name = names[0], names[0]
         self.master_page_name_cover = title_name
         self.master_page_name_normal = normal_name
raphink commented 12 years ago

See PR https://github.com/mattharrison/rst2odp/pull/15