#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2008 Søren Roug, European Environment Agency
#
# This is free software.  You may redistribute it under the terms
# of the Apache license and the GNU General Public License Version
# 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#
# Contributor(s):
#
#

# OpenDocument can be a complete office document in a single
# XML document. This script will create such a document.
import sys, getopt
from odf.opendocument import load

def usage():
   sys.stderr.write("Usage: %s [-o outputfile] [inputfile]\n" % sys.argv[0])


if __name__ == "__main__":
    try:
        opts, args = getopt.getopt(sys.argv[1:], "o:", ["output="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    outputfile = '-'

    for o, a in opts:
        if o in ("-o", "--output"):
            outputfile = a

    if len(args) > 1:
        usage()
        sys.exit(2)
    if len(args) == 0:
        d = load(sys.stdin)
    else:
        d = load(args[0])
    xml = d.xml()
    if outputfile == '-':
        sys.stdout.write(xml)
    else:
        open(outputfile,"w").write(xml)
