odf2xhtml 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2007 Søren Roug, European Environment Agency
  4. #
  5. # This is free software. You may redistribute it under the terms
  6. # of the Apache license and the GNU General Public License Version
  7. # 2 or at your option any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public
  15. # License along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. #
  18. # Contributor(s):
  19. #
  20. from odf.odf2xhtml import ODF2XHTML
  21. import sys, getopt
  22. if sys.version_info[0]==3: unicode=str
  23. from io import StringIO
  24. def usage():
  25. sys.stderr.write("Usage: %s [-p] inputfile\n" % sys.argv[0])
  26. try:
  27. opts, args = getopt.getopt(sys.argv[1:], "ep", ["plain","embedable"])
  28. except getopt.GetoptError:
  29. usage()
  30. sys.exit(2)
  31. generatecss = True
  32. embedable = False
  33. for o, a in opts:
  34. if o in ("-p", "--plain"):
  35. generatecss = False
  36. if o in ("-e", "--embedable"):
  37. embedable = True
  38. if len(args) != 1:
  39. usage()
  40. sys.exit(2)
  41. odhandler = ODF2XHTML(generatecss, embedable)
  42. try:
  43. result = odhandler.odf2xhtml(unicode(args[0]))
  44. except:
  45. sys.stderr.write("Unable to open file %s or file is not OpenDocument\n" % args[0])
  46. sys.exit(1)
  47. sys.stdout.write(result)
  48. # Local Variables: ***
  49. # mode: python ***
  50. # End: ***