Пример #1
0
 def test_wrong_options(self):
     with Office(self.lo_path) as lo:
         with lo.documentLoad(self.test_doc) as doc:
             self.assertRaises(LoKitExportError,
                               doc.saveAs,
                               self.test_out_rtf,
                               options="foobar")
Пример #2
0
 def test_filter_and_options(self):
     with Office(self.lo_path) as lo:
         with lo.documentLoad(self.test_doc) as doc:
             doc.saveAs(self.test_out_docx,
                        fmt="docx",
                        options="SkipImages")
             os.unlink(self.test_out_docx)
Пример #3
0
 def test_multiple_calls(self):
     with Office(self.lo_path) as lo:
         with lo.documentLoad(self.test_doc) as doc:
             doc.saveAs(self.test_out_docx,
                        fmt="docx",
                        options="SkipImages")
             doc.saveAs(self.test_out_pdf)
             os.unlink(self.test_out_docx)
             os.unlink(self.test_out_pdf)
         with lo.documentLoad(self.test_doc) as doc:
             doc.saveAs(self.test_out_pdf)
             os.unlink(self.test_out_pdf)
Пример #4
0
 def test_no_output_file(self):
     lo = Office(self.lo_path)
     with lo.documentLoad(self.test_doc) as doc:
         self.assertRaises(LoKitExportError, doc.saveAs, "")
Пример #5
0
 def test_no_input_file(self):
     lo = Office(self.lo_path)
     self.assertRaises(LoKitImportError, lo.documentLoad, "foo")
Пример #6
0
 def test_init(self):
     lo = Office(self.lo_path)
     self.assertIsNotNone(lo)
Пример #7
0
from lokit import Office
import argparse
import os

LO_PATH = "/opt/libreoffice4.3/program"

if __name__ == '__main__':
    parser = argparse.ArgumentParser(prog='lokitconv.py',
            description='Requires LibreOffice 4.3.0')
    parser.add_argument('-f', '--format',
            help='Known formats include:\
                For text documents: doc docx fodt html odt ott pdf txt xhtml')
    parser.add_argument('-o', '--options',
            help='Filter options, known options include: SkipImages')
    parser.add_argument('input_file')
    parser.add_argument('output_file')

    args = parser.parse_args()
    lo_path = os.getenv('LO_PATH', LO_PATH)
    lo = Office(lo_path)
    doc = lo.documentLoad(args.input_file)
    doc.saveAs(args.output_file, fmt=args.format, options=args.options)

    os._exit(0)
Пример #8
0
 def test_no_output_file(self):
     lo = Office(self.lo_path)
     with lo.documentLoad(self.test_doc) as doc:
         self.assertRaises(LoKitExportError, doc.saveAs, "")