Exemplo n.º 1
0
 def testConvertDocToOdt(self):
     """Test convert DOC to ODT"""
     data = encodestring(open("data/test.doc").read())
     handler = Handler(self.tmp_url, decodestring(data), 'doc')
     doc_exported = handler.convert("odt")
     self._assert_document_output(
         doc_exported, "application/vnd.oasis.opendocument.text")
Exemplo n.º 2
0
 def testConvertWithOpenOfficeStopped(self):
     """Test convert with openoffice stopped"""
     openoffice.stop()
     data = encodestring(open("data/test.doc").read())
     handler = Handler(self.tmp_url, decodestring(data), "doc")
     doc_exported = handler.convert("odt")
     self._assert_document_output(doc_exported, "application/vnd.oasis.opendocument.text")
Exemplo n.º 3
0
  def testRefreshOdt(self):
    """Test refresh argument"""
    # Check when refreshing is disabled
    data = encodestring(open("data/test_fields.odt").read())
    handler = Handler(self.tmp_url,
                        decodestring(data),
                        'odt',
                        refresh=False)
    doc_exported = handler.convert("odt")
    document_output_url = path.join(self.tmp_url, "testExport.odt")
    self._save_document(document_output_url, doc_exported)
    zip_handler = ZipFile(document_output_url)
    content_tree = etree.fromstring(zip_handler.read('content.xml'))
    self.assertFalse(content_tree.xpath('//text:variable-get[text() = "DISPLAY ME"]',
                                       namespaces=content_tree.nsmap))

    # Check when refreshing is enabled
    data = encodestring(open("data/test_fields.odt").read())
    handler = Handler(self.tmp_url,
                        decodestring(data),
                        'odt',
                        refresh=True)
    doc_exported = handler.convert("odt")
    document_output_url = path.join(self.tmp_url, "testExport.odt")
    self._save_document(document_output_url, doc_exported)
    zip_handler = ZipFile(document_output_url)
    content_tree = etree.fromstring(zip_handler.read('content.xml'))
    self.assertTrue(content_tree.xpath('//text:variable-get[text() = "DISPLAY ME"]',
                                       namespaces=content_tree.nsmap))
Exemplo n.º 4
0
 def testConvertOdtToDoc(self):
   """Test convert ODT to DOC"""
   data = encodestring(open("data/test.odt").read())
   handler = Handler(self.tmp_url,
                       decodestring(data),
                       'odt')
   doc_exported = handler.convert("doc")
   self._assert_document_output(doc_exported, "application/msword")
Exemplo n.º 5
0
 def testGetMetadataWithOpenOfficeStopped(self):
     """Test getMetadata with openoffice stopped"""
     openoffice.stop()
     data = encodestring(open("data/test.odt").read())
     handler = Handler(self.tmp_url, decodestring(data), "odt")
     metadata = handler.getMetadata()
     self.assertEquals(metadata.get("Title"), "title")
     self.assertEquals(metadata.get("MIMEType"), "application/vnd.oasis.opendocument.text")
Exemplo n.º 6
0
 def testConvertWithOpenOfficeStopped(self):
     """Test convert with openoffice stopped"""
     openoffice.stop()
     data = encodestring(open("data/test.doc").read())
     handler = Handler(self.tmp_url, decodestring(data), 'doc')
     doc_exported = handler.convert("odt")
     self._assert_document_output(
         doc_exported, "application/vnd.oasis.opendocument.text")
Exemplo n.º 7
0
 def testGetMetadata(self):
     """Test getMetadata"""
     data = encodestring(open("data/test.odt").read())
     handler = Handler(self.tmp_url, decodestring(data), "odt")
     metadata = handler.getMetadata()
     self.assertEquals(metadata.get("MIMEType"), "application/vnd.oasis.opendocument.text")
     handler.document.restoreOriginal()
     metadata = handler.getMetadata(True)
     self.assertNotEquals(metadata.get("Data"), "")
Exemplo n.º 8
0
 def testGetMetadataWithOpenOfficeStopped(self):
     """Test getMetadata with openoffice stopped"""
     openoffice.stop()
     data = encodestring(open("data/test.odt").read())
     handler = Handler(self.tmp_url, decodestring(data), 'odt')
     metadata = handler.getMetadata()
     self.assertEquals(metadata.get('Title'), 'title')
     self.assertEquals(metadata.get('MIMEType'),
                       'application/vnd.oasis.opendocument.text')
Exemplo n.º 9
0
 def testSetMetadataWithOpenOfficeStopped(self):
     """Test setMetadata with openoffice stopped"""
     openoffice.stop()
     data = encodestring(open("data/test.doc").read())
     handler = Handler(self.tmp_url, decodestring(data), "doc")
     new_data = handler.setMetadata({"Title": "cloudooo Test -"})
     new_handler = Handler(self.tmp_url, new_data, "doc")
     metadata = new_handler.getMetadata()
     self.assertEquals(metadata.get("Title"), "cloudooo Test -")
Exemplo n.º 10
0
 def testConvertDocToOdt(self):
   """Test convert DOC to ODT"""
   data = encodestring(open("data/test.doc").read())
   handler = Handler(self.tmp_url,
                       decodestring(data),
                       'doc')
   doc_exported = handler.convert("odt")
   self._assert_document_output(doc_exported,
                         "application/vnd.oasis.opendocument.text")
Exemplo n.º 11
0
 def testGetMetadata(self):
     """Test getMetadata"""
     data = encodestring(open("data/test.odt").read())
     handler = Handler(self.tmp_url, decodestring(data), 'odt')
     metadata = handler.getMetadata()
     self.assertEquals(metadata.get('MIMEType'),
                       'application/vnd.oasis.opendocument.text')
     handler.document.restoreOriginal()
     metadata = handler.getMetadata(True)
     self.assertNotEquals(metadata.get('Data'), '')
Exemplo n.º 12
0
 def testGetAllowedConversionFormatList_TextCsv(self):
   """Test allowed conversion format for text/csv"""
   self.assertEquals(
     sorted(Handler.getAllowedConversionFormatList("text/csv;ignored=param")),
     [ ('application/msword', 'Microsoft Word 97-2003'),
       ('application/pdf', 'PDF - Portable Document Format'),
       ('application/rtf', 'Rich Text'),
       ('application/vnd.ms-excel', 'Microsoft Excel 97-2003'),
       ('application/vnd.ms-excel.sheet.macroEnabled.12', 'Microsoft Excel 2007-2016 XML (macro enabled)'),
       ('application/vnd.oasis.opendocument.spreadsheet', 'ODF Spreadsheet'),
       ('application/vnd.oasis.opendocument.text', 'ODF Text Document'),
       ('application/vnd.oasis.opendocument.text', 'Text (Writer/Web)'),
       ('application/vnd.oasis.opendocument.text-flat-xml', 'Flat XML ODF Text Document'),
       ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'Microsoft Excel 2007-2013 XML'),
       ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'Office Open XML Spreadsheet'),
       ('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'Microsoft Word 2007-2013 XML'),
       ('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'Office Open XML Text'),
       ('application/vnd.sun.xml.writer', 'OpenOffice.org 1.0 Text Document (Writer/Web)'),
       ('image/jpeg', 'JPEG - Joint Photographic Experts Group'),
       ('image/png', 'PNG - Portable Network Graphic'),
       ('text/html', 'HTML Document'),
       ('text/html', 'HTML Document (Calc)'),
       ('text/html', 'HTML Document (Writer)'),
       ('text/plain', 'Text (Writer/Web)'),
       ('text/plain', 'Text - Choose Encoding'),
       ('text/plain', 'Text - Choose Encoding (Writer/Web)') ])
Exemplo n.º 13
0
 def testGetAllowedConversionFormatList_ApplicationVndMsPowerpoint(self):
     """Test allowed conversion format for application/vnd.ms-powerpoint"""
     self.assertEquals(
         sorted(
             Handler.getAllowedConversionFormatList(
                 "application/vnd.ms-powerpoint;ignored=param")),
         [('application/pdf', 'PDF - Portable Document Format'),
          ('application/postscript', 'EPS - Encapsulated PostScript'),
          ('application/vnd.ms-powerpoint', 'Microsoft PowerPoint 97-2003'),
          ('application/vnd.ms-powerpoint',
           'Microsoft PowerPoint 97-2003 AutoPlay'),
          ('application/vnd.oasis.opendocument.graphics',
           'ODF Drawing (Impress)'),
          ('application/vnd.oasis.opendocument.presentation',
           'ODF Presentation'),
          ('application/vnd.openxmlformats-officedocument.presentationml.presentation',
           'Microsoft PowerPoint 2007-2013 XML'),
          ('application/vnd.openxmlformats-officedocument.presentationml.presentation',
           'Office Open XML Presentation'),
          ('application/vnd.openxmlformats-officedocument.presentationml.slideshow',
           'Microsoft PowerPoint 2007-2013 XML AutoPlay'),
          ('application/vnd.openxmlformats-officedocument.presentationml.slideshow',
           'Office Open XML Presentation AutoPlay'),
          ('image/gif', 'GIF - Graphics Interchange Format'),
          ('image/jpeg', 'JPEG - Joint Photographic Experts Group'),
          ('image/png', 'PNG - Portable Network Graphic'),
          ('image/svg+xml', 'SVG - Scalable Vector Graphics'),
          ('image/tiff', 'TIFF - Tagged Image File Format'),
          ('image/x-ms-bmp', 'BMP - Windows Bitmap'),
          ('text/html', 'HTML Document (Impress)')])
Exemplo n.º 14
0
 def testGetAllowedConversionFormatList_ApplicationVndMsPowerpoint(self):
   """Test allowed conversion format for application/vnd.ms-powerpoint"""
   self.maxDiff = None
   self.assertEquals(
     sorted(Handler.getAllowedConversionFormatList("application/vnd.ms-powerpoint;ignored=param")),
     [ ('application/pdf', 'PDF - Portable Document Format'),
       ('application/postscript', 'EPS - Encapsulated PostScript'),
       ('application/vnd.oasis.opendocument.graphics', 'ODF Drawing (Impress)'),
       ('application/vnd.oasis.opendocument.presentation', 'ODF Presentation'),
       ('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'Microsoft PowerPoint 2007-2013 XML'),
       ('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'Office Open XML Presentation'),
       ('application/vnd.openxmlformats-officedocument.presentationml.slideshow', 'Microsoft PowerPoint 2007-2013 XML AutoPlay'),
       ('application/vnd.openxmlformats-officedocument.presentationml.slideshow', 'Office Open XML Presentation AutoPlay'),
       ('image/gif', 'GIF - Graphics Interchange Format'),
       ('image/jpeg', 'JPEG - Joint Photographic Experts Group'),
       ('image/png', 'PNG - Portable Network Graphic'),
       ('image/svg+xml', 'SVG - Scalable Vector Graphics'),
       ('image/tiff', 'TIFF - Tagged Image File Format'),
       ('image/x-cmu-raster', 'RAS - Sun Raster Image'),
       ('image/x-ms-bmp', 'BMP - Windows Bitmap'),
       ('image/x-portable-bitmap', 'PBM - Portable Bitmap'),
       ('image/x-portable-graymap', 'PGM - Portable Graymap'),
       ('image/x-portable-pixmap', 'PPM - Portable Pixelmap'),
       ('image/x-xpixmap', 'XPM - X PixMap'),
       ('text/html', 'HTML Document (Impress)') ])
Exemplo n.º 15
0
 def testGetAllowedConversionFormatList_ApplicationVndMsExcelSheetMacroenabled12(
         self):
     """Test allowed conversion format for application/vnd.ms-excel.sheet.macroEnabled.12"""
     self.assertEquals(
         sorted(
             Handler.getAllowedConversionFormatList(
                 "application/vnd.ms-excel.sheet.macroEnabled.12;ignored=param"
             )), [])
Exemplo n.º 16
0
 def testGetAllowedConversionFormatList_ApplicationVndOasisOpendocumentTextFlatXml(
         self):
     """Test allowed conversion format for application/vnd.oasis.opendocument.text-flat-xml"""
     self.assertEquals(
         sorted(
             Handler.getAllowedConversionFormatList(
                 "application/vnd.oasis.opendocument.text-flat-xml;ignored=param"
             )), [])
Exemplo n.º 17
0
 def testGetAllowedConversionFormatList_ApplicationVndOpenXmlFormatsOfficedocumentSpreadsheetmlSheet(self):
   """Test allowed conversion format for application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"""
   self.assertEquals(
     sorted(Handler.getAllowedConversionFormatList("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;ignored=param")),
     [ ('application/pdf', 'PDF - Portable Document Format'),
       ('application/vnd.ms-excel', 'Microsoft Excel 97-2003'),
       ('application/vnd.ms-excel.sheet.macroEnabled.12', 'Microsoft Excel 2007-2016 XML (macro enabled)'),
       ('application/vnd.oasis.opendocument.spreadsheet', 'ODF Spreadsheet'),
       ('image/png', 'PNG - Portable Network Graphic'),
       ('text/csv', 'Text CSV'),
       ('text/html', 'HTML Document (Calc)') ])
Exemplo n.º 18
0
 def testSetMetadata(self):
     """Test setMetadata"""
     data = encodestring(open("data/test.odt").read())
     handler = Handler(self.tmp_url, decodestring(data), "odt")
     new_data = handler.setMetadata({"Title": "cloudooo Test -"})
     new_handler = Handler(self.tmp_url, new_data, "odt")
     metadata = new_handler.getMetadata()
     self.assertEquals(metadata.get("Title"), "cloudooo Test -")
     handler = Handler(self.tmp_url, decodestring(data), "odt")
     new_data = handler.setMetadata({"Title": "Namie's working record"})
     new_handler = Handler(self.tmp_url, new_data, "odt")
     metadata = new_handler.getMetadata()
     self.assertEquals(metadata.get("Title"), "Namie's working record")
Exemplo n.º 19
0
    def testRefreshOdt(self):
        """Test refresh argument"""
        # Check when refreshing is disabled
        data = encodestring(open("data/test_fields.odt").read())
        handler = Handler(self.tmp_url,
                          decodestring(data),
                          'odt',
                          refresh=False)
        doc_exported = handler.convert("odt")
        document_output_url = path.join(self.tmp_url, "testExport.odt")
        self._save_document(document_output_url, doc_exported)
        zip_handler = ZipFile(document_output_url)
        content_tree = etree.fromstring(zip_handler.read('content.xml'))
        self.assertFalse(
            content_tree.xpath('//text:variable-get[text() = "DISPLAY ME"]',
                               namespaces=content_tree.nsmap))

        # Check when refreshing is enabled
        data = encodestring(open("data/test_fields.odt").read())
        handler = Handler(self.tmp_url,
                          decodestring(data),
                          'odt',
                          refresh=True)
        doc_exported = handler.convert("odt")
        document_output_url = path.join(self.tmp_url, "testExport.odt")
        self._save_document(document_output_url, doc_exported)
        zip_handler = ZipFile(document_output_url)
        content_tree = etree.fromstring(zip_handler.read('content.xml'))
        self.assertTrue(
            content_tree.xpath('//text:variable-get[text() = "DISPLAY ME"]',
                               namespaces=content_tree.nsmap))
Exemplo n.º 20
0
 def testGetAllowedConversionFormatList_ApplicationVndOpenxmlformatsOfficedocumentWordprocessingmlDocument(self):
   """Test allowed conversion format for application/vnd.openxmlformats-officedocument.wordprocessingml.document"""
   self.assertEquals(
     sorted(Handler.getAllowedConversionFormatList("application/vnd.openxmlformats-officedocument.wordprocessingml.document;ignored=param")),
     [ ('application/msword', 'Microsoft Word 97-2003'),
       ('application/pdf', 'PDF - Portable Document Format'),
       ('application/rtf', 'Rich Text'),
       ('application/vnd.oasis.opendocument.text', 'ODF Text Document'),
       ('application/vnd.oasis.opendocument.text-flat-xml', 'Flat XML ODF Text Document'),
       ('image/jpeg', 'JPEG - Joint Photographic Experts Group'),
       ('image/png', 'PNG - Portable Network Graphic'),
       ('text/html', 'HTML Document (Writer)'),
       ('text/plain', 'Text - Choose Encoding') ])
Exemplo n.º 21
0
 def testSetMetadataWithOpenOfficeStopped(self):
     """Test setMetadata with openoffice stopped"""
     openoffice.stop()
     data = encodestring(open("data/test.doc").read())
     handler = Handler(self.tmp_url, decodestring(data), 'doc')
     new_data = handler.setMetadata({"Title": "cloudooo Test -"})
     new_handler = Handler(self.tmp_url, new_data, 'doc')
     metadata = new_handler.getMetadata()
     self.assertEquals(metadata.get('Title'), "cloudooo Test -")
Exemplo n.º 22
0
 def testGetAllowedConversionFormatList_ImageXXpixmap(self):
     """Test allowed conversion format for image/x-xpixmap"""
     self.assertEquals(
         sorted(
             Handler.getAllowedConversionFormatList(
                 "image/x-xpixmap;ignored=param")),
         [('application/pdf', 'PDF - Portable Document Format'),
          ('application/postscript', 'EPS - Encapsulated PostScript'),
          ('application/vnd.oasis.opendocument.graphics', 'ODF Drawing'),
          ('image/gif', 'GIF - Graphics Interchange Format'),
          ('image/jpeg', 'JPEG - Joint Photographic Experts Group'),
          ('image/png', 'PNG - Portable Network Graphic'),
          ('image/svg+xml', 'SVG - Scalable Vector Graphics'),
          ('image/tiff', 'TIFF - Tagged Image File Format'),
          ('image/x-ms-bmp', 'BMP - Windows Bitmap'),
          ('text/html', 'HTML Document (Draw)')])
Exemplo n.º 23
0
 def testGetAllowedConversionFormatList_ImageXXpixmap(self):
   """Test allowed conversion format for image/x-xpixmap"""
   self.assertEquals(
     sorted(Handler.getAllowedConversionFormatList("image/x-xpixmap;ignored=param")),
     [ ('application/pdf', 'PDF - Portable Document Format'),
       ('application/postscript', 'EPS - Encapsulated PostScript'),
       ('application/vnd.oasis.opendocument.graphics', 'ODF Drawing'),
       ('image/gif', 'GIF - Graphics Interchange Format'),
       ('image/jpeg', 'JPEG - Joint Photographic Experts Group'),
       ('image/png', 'PNG - Portable Network Graphic'),
       ('image/svg+xml', 'SVG - Scalable Vector Graphics'),
       ('image/tiff', 'TIFF - Tagged Image File Format'),
       ('image/x-cmu-raster', 'RAS - Sun Raster Image'),
       ('image/x-ms-bmp', 'BMP - Windows Bitmap'),
       ('image/x-portable-bitmap', 'PBM - Portable Bitmap'),
       ('image/x-portable-graymap', 'PGM - Portable Graymap'),
       ('image/x-portable-pixmap', 'PPM - Portable Pixelmap'),
       ('text/html', 'HTML Document (Draw)') ])
Exemplo n.º 24
0
 def testGetAllowedConversionFormatList_ApplicationVndMsExcel(self):
     """Test allowed conversion format for application/vnd.ms-excel"""
     self.assertEquals(
         sorted(
             Handler.getAllowedConversionFormatList(
                 "application/vnd.ms-excel;ignored=param")),
         [('application/pdf', 'PDF - Portable Document Format'),
          ('application/vnd.ms-excel', 'Microsoft Excel 97-2003'),
          ('application/vnd.ms-excel.sheet.macroEnabled.12',
           'Microsoft Excel 2007-2016 XML (macro enabled)'),
          ('application/vnd.oasis.opendocument.spreadsheet',
           'ODF Spreadsheet'),
          ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
           'Microsoft Excel 2007-2013 XML'),
          ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
           'Office Open XML Spreadsheet'),
          ('image/png', 'PNG - Portable Network Graphic'),
          ('text/csv', 'Text CSV'), ('text/html', 'HTML Document (Calc)')])
Exemplo n.º 25
0
 def testGetAllowedConversionFormatList_ApplicationVndSunXmlWriter(self):
     """Test allowed conversion format for application/vnd.sun.xml.writer"""
     self.assertEquals(
         sorted(
             Handler.getAllowedConversionFormatList(
                 "application/vnd.sun.xml.writer;ignored=param")),
         [('application/msword', 'Microsoft Word 97-2003'),
          ('application/pdf', 'PDF - Portable Document Format'),
          ('application/rtf', 'Rich Text'),
          ('application/vnd.oasis.opendocument.text', 'ODF Text Document'),
          ('application/vnd.oasis.opendocument.text-flat-xml',
           'Flat XML ODF Text Document'),
          ('application/vnd.openxmlformats-officedocument.wordprocessingml.document',
           'Microsoft Word 2007-2013 XML'),
          ('application/vnd.openxmlformats-officedocument.wordprocessingml.document',
           'Office Open XML Text'),
          ('image/jpeg', 'JPEG - Joint Photographic Experts Group'),
          ('image/png', 'PNG - Portable Network Graphic'),
          ('text/html', 'HTML Document (Writer)'),
          ('text/plain', 'Text - Choose Encoding')])
Exemplo n.º 26
0
 def testGetAllowedConversionFormatList_TextCsv(self):
     """Test allowed conversion format for text/csv"""
     self.assertEquals(
         sorted(
             Handler.getAllowedConversionFormatList(
                 "text/csv;ignored=param")),
         [('application/msword', 'Microsoft Word 97-2003'),
          ('application/pdf', 'PDF - Portable Document Format'),
          ('application/rtf', 'Rich Text'),
          ('application/vnd.ms-excel', 'Microsoft Excel 97-2003'),
          ('application/vnd.ms-excel.sheet.macroEnabled.12',
           'Microsoft Excel 2007-2016 XML (macro enabled)'),
          ('application/vnd.oasis.opendocument.spreadsheet',
           'ODF Spreadsheet'),
          ('application/vnd.oasis.opendocument.text', 'ODF Text Document'),
          ('application/vnd.oasis.opendocument.text', 'Text (Writer/Web)'),
          ('application/vnd.oasis.opendocument.text-flat-xml',
           'Flat XML ODF Text Document'),
          ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
           'Microsoft Excel 2007-2013 XML'),
          ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
           'Office Open XML Spreadsheet'),
          ('application/vnd.openxmlformats-officedocument.wordprocessingml.document',
           'Microsoft Word 2007-2013 XML'),
          ('application/vnd.openxmlformats-officedocument.wordprocessingml.document',
           'Office Open XML Text'),
          ('application/vnd.sun.xml.writer',
           'OpenOffice.org 1.0 Text Document (Writer/Web)'),
          ('image/jpeg', 'JPEG - Joint Photographic Experts Group'),
          ('image/png', 'PNG - Portable Network Graphic'),
          ('text/csv', 'Text CSV'), ('text/html', 'HTML Document'),
          ('text/html', 'HTML Document (Calc)'),
          ('text/html', 'HTML Document (Writer)'),
          ('text/plain', 'Text (Writer/Web)'),
          ('text/plain', 'Text - Choose Encoding'),
          ('text/plain', 'Text - Choose Encoding (Writer/Web)')])
Exemplo n.º 27
0
 def testGetAllowedConversionFormatList_ApplicationVndOasisOpendocumentTextFlatXml(self):
   """Test allowed conversion format for application/vnd.oasis.opendocument.text-flat-xml"""
   self.assertEquals(
     sorted(Handler.getAllowedConversionFormatList("application/vnd.oasis.opendocument.text-flat-xml;ignored=param")),
     [])
Exemplo n.º 28
0
 def testConvertOdtToDoc(self):
     """Test convert ODT to DOC"""
     data = encodestring(open("data/test.odt").read())
     handler = Handler(self.tmp_url, decodestring(data), 'odt')
     doc_exported = handler.convert("doc")
     self._assert_document_output(doc_exported, "application/msword")
Exemplo n.º 29
0
  def convert(self, destination_format=None, **kw):
    """ Convert the inputed file to output as format that were informed """
    source_format = self.file.source_format
    logger.debug("x2t convert: %s > %s" % (source_format, destination_format))

    # init vars and xml configuration file
    in_format = format_code_map[source_format]
    out_format = format_code_map_output.get(destination_format,
                                            format_code_map[destination_format])
    root_dir = self.file.directory_name
    input_dir = os.path.join(root_dir, "input");
    input_file_name = self.file.getUrl()
    output_file_name = os.path.join(root_dir, "document.%s" % destination_format)
    config_file_name = os.path.join(root_dir, "config.xml")
    metadata = None
    output_data = None

    if source_format in yformat_tuple:
      if self._data.startswith("PK\x03\x04"):
        os.mkdir(input_dir)
        unzip(self.file.getUrl(), input_dir)
        input_file_name = os.path.join(input_dir, "body.txt")
        if not os.path.isfile(input_file_name):
          input_file_name = os.path.join(input_dir, "Editor.bin")
          if not os.path.isfile(input_file_name):
            raise RuntimeError("input format incorrect: Editor.bin absent in zip archive")
        metadata_file_name = os.path.join(input_dir, "metadata.json")
        if os.path.isfile(metadata_file_name):
          with open(metadata_file_name) as metadata_file:
            metadata = json.loads(metadata_file.read())

    with open(config_file_name, "w") as config_file:
      config = {
        # 'm_sKey': 'from',
        'm_sFileFrom': input_file_name,
        'm_nFormatFrom': str(in_format),
        'm_sFileTo': output_file_name,
        'm_nFormatTo': str(out_format),
        # 'm_bPaid': 'true',
        # 'm_bEmbeddedFonts': 'false',
        # 'm_bFromChanges': 'false',
        # 'm_sFontDir': '/usr/share/fonts',
        # 'm_sThemeDir': '/var/www/onlyoffice/documentserver/FileConverterService/presentationthemes',
      }
      root = ElementTree.Element('root')
      for key, value in config.items():
        ElementTree.SubElement(root, key).text = value
      ElementTree.ElementTree(root).write(config_file, encoding='utf-8', xml_declaration=True,
                                          default_namespace=None, method="xml")

    # run convertion binary
    p = Popen(
      ["x2t", config_file.name],
      stdout=PIPE,
      stderr=PIPE,
      close_fds=True,
      env=self.environment,
    )
    stdout, stderr = p.communicate()
    if p.returncode != 0:
      raise RuntimeError("x2t: exit code %d != 0\n+ %s\n> stdout: %s\n> stderr: %s@ x2t xml:\n%s"
                         % (p.returncode, " ".join(["x2t", config_file.name]), stdout, stderr,
                            "  " + open(config_file.name).read().replace("\n", "\n  ")))

    self.file.reload(output_file_name)
    try:
      if source_format in yformat_tuple:
        if metadata:
          output_data = OOoHandler(self.base_folder_url, self.file.getContent(), source_format, **self._init_kw)\
            .setMetadata(metadata)
        else:
          output_data = self.file.getContent()
      elif destination_format in yformat_tuple:
        if not metadata:
          if source_format not in yformat_tuple:
            metadata = OOoHandler(self.base_folder_url, self._data, source_format, **self._init_kw).getMetadata()
          if not metadata:
            metadata = {}
          metadata.pop('MIMEType', None)
          metadata.pop('Generator', None)
          metadata.pop('AppVersion', None)
          metadata.pop('ImplementationName', None)
        with ZipFile(output_file_name, mode="a") as zipfile:
          zipfile.writestr("metadata.json", json.dumps(metadata))
        output_data = self.file.getContent()
    finally:
      self.file.trash()
    return output_data
Exemplo n.º 30
0
 def testGetAllowedConversionFormatList_ApplicationVndMsExcelSheetMacroenabled12(self):
   """Test allowed conversion format for application/vnd.ms-excel.sheet.macroEnabled.12"""
   self.assertEquals(
     sorted(Handler.getAllowedConversionFormatList("application/vnd.ms-excel.sheet.macroEnabled.12;ignored=param")),
     [])
Exemplo n.º 31
0
 def testGetAllowedConversionFormatList_TextRtf(self):
     """Test allowed conversion format for text/rtf"""
     self.assertEquals(
         sorted(
             Handler.getAllowedConversionFormatList(
                 "text/rtf;ignored=param")), [])
Exemplo n.º 32
0
 def get(*args, **kw):
     return sorted(Handler.getAllowedConversionFormatList(*args, **kw))
Exemplo n.º 33
0
 def testGetAllowedConversionFormatList_TextRtf(self):
   """Test allowed conversion format for text/rtf"""
   self.assertEquals(
     sorted(Handler.getAllowedConversionFormatList("text/rtf;ignored=param")),
     [])
Exemplo n.º 34
0
 def testSetMetadata(self):
     """Test setMetadata"""
     data = encodestring(open("data/test.odt").read())
     handler = Handler(self.tmp_url, decodestring(data), 'odt')
     new_data = handler.setMetadata({"Title": "cloudooo Test -"})
     new_handler = Handler(self.tmp_url, new_data, 'odt')
     metadata = new_handler.getMetadata()
     self.assertEquals(metadata.get('Title'), "cloudooo Test -")
     handler = Handler(self.tmp_url, decodestring(data), 'odt')
     new_data = handler.setMetadata({"Title": "Namie's working record"})
     new_handler = Handler(self.tmp_url, new_data, 'odt')
     metadata = new_handler.getMetadata()
     self.assertEquals(metadata.get('Title'), "Namie's working record")
Exemplo n.º 35
0
 def get(*args, **kw):
   return sorted(Handler.getAllowedConversionFormatList(*args, **kw))