def invokeCommand(self, tmpdir, fullname):
        if os.name=='posix':
            cmd = 'cd "%s" && unzip "%s" 2>error_log 1>/dev/null' % (
                tmpdir, fullname)
            p = Popen(cmd, shell = True)
            sts = os.waitpid(p.pid, 0)

            cmd = ('cd "%s" && xsltproc --novalid %s content.xml >"%s.html" '
                '2>"%s.log-xsltproc"') % (
                tmpdir, XSL_STYLESHEET, sansext(fullname), sansext(fullname))
            LOG(self.__name__, DEBUG, "cmd = %s" % cmd)
            p = Popen(cmd, shell = True)
            sts = os.waitpid(p.pid, 0)
            
            try:
                htmlfile = open(os.path.join(tmpdir, "%s.html" % sansext(fullname)),
                            'r')
                html = htmlfile.read()
                htmlfile.close()
            except:
                try:
                    return open(os.path.join(tmpdir, 'error_log'), 'r').read()
                except:
                    return ''
        return html
Пример #2
0
 def convert(self):
     """Convert the document to HTML.
     """
     if not os.name == 'posix':
         return
     name = self.name()
     cmd = 'cd "%s" && unzip "%s" 2>unzip_error.log 1>/dev/null' % (
         self.tmpdir, name)
     os.system(cmd)
     cmd = 'cd "%s" && %s --novalid "%s" content.xml '
     cmd += '> "%s.html" 2> "error.log"'
     cmd = cmd % (
         self.tmpdir, self.binary, XSL_STYLESHEET, sansext(name))
     os.system(cmd)
     try:
         htmlfile = open(os.path.join(
           self.tmpdir, "%s.html" % sansext(name)), 'r')
         html = htmlfile.read()
         htmlfile.close()
     except:
         try:
             return open(os.path.join(self.tmpdir, 'unzip_error.log'),
                         'r').read()
         except:
             return ''
     return html
Пример #3
0
 def convert(self, data, cache, **kwargs):
     base_name = sansext(kwargs.get("filename") or 'unknown.xml')
     dtds = self.config['dtds']
     tmpdir, fullname = self.initialize_tmpdir(data, filename=base_name)
     try:
         try:
             doctype = get_doctype(data)
         except DTException:
             try:
                 doctype = get_dtd(data)
             except DTException:
                 log('Unable to get doctype nor dtd in %s' % data)
                 doctype = None
         if doctype and doctype in dtds:
             data = self.invokeCommand(fullname, dtds[doctype])
         elif self.config['default_transform']:
             data = self.invokeCommand(fullname,
                                       self.config['default_transform'])
         cache.setData(data)
         path, images = self.subObjects(tmpdir)
         objects = {}
         if images:
             self.fixImages(path, images, objects)
             cache.setSubObjects(objects)
         return cache
     finally:
         self.cleanDir(tmpdir)
Пример #4
0
 def convert(self, data, cache, **kwargs):
     base_name = sansext(kwargs.get("filename") or 'unknown.xml')
     dtds = self.config['dtds']
     tmpdir, fullname = self.initialize_tmpdir(data, filename=base_name)
     try:
         try:
             doctype = get_doctype(data)
         except DTException:
             try:
                 doctype = get_dtd(data)
             except DTException:
                 log('Unable to get doctype nor dtd in %s' % data)
                 doctype = None
         if doctype and dtds.has_key(doctype):
             data = self.invokeCommand(fullname, dtds[doctype])
         elif self.config['default_transform']:
             data = self.invokeCommand(fullname, self.config['default_transform'])
         cache.setData(data)
         path, images = self.subObjects(tmpdir)
         objects = {}
         if images:
             self.fixImages(path, images, objects)
             cache.setSubObjects(objects)
         return cache
     finally:
         self.cleanDir(tmpdir)
 def invokeCommand(self, tmpdir, fullname):
     cmd = 'cd "%s" && unzip %s 2>error_log 1>/dev/null' % (
         tmpdir, fullname)
     os.system(cmd)
     cmd = ('cd "%s" && xsltproc --novalid %s content.xml >"%s.html" '
         '2>"%s.log-xsltproc"') % (
         tmpdir, XSL_STYLESHEET, sansext(fullname), sansext(fullname))
     os.system(cmd)
     try:
         htmlfile = open(os.path.join(tmpdir, "%s.html" % sansext(fullname)),
                         'r')
         html = htmlfile.read()
         htmlfile.close()
     except:
         try:
             return open(os.path.join(tmpdir, 'error_log'), 'r').read()
         except:
             return ''
     return html
Пример #6
0
 def invokeCommand(self, tmpdir, fullname):
     # FIXME: windows users...
     htmlfile = "%s/%s.html" % (tmpdir, sansext(fullname))
     cmd = 'cd "%s" && %s -o %s "%s" 2>error_log 1>/dev/null' % (tmpdir, self.binary, htmlfile, fullname)
     os.system(cmd)
     try:
         html = open(htmlfile).read()
     except:
         try:
             return open("%s/error_log" % tmpdir, "r").read()
         except:
             return ""
     return html
Пример #7
0
 def invokeCommand(self, tmpdir, fullname):
     # FIXME: windows users...
     htmlfile = "%s/%s.html" % (tmpdir, sansext(fullname))
     cmd = 'cd "%s" && %s -o %s "%s" 2>error_log 1>/dev/null' % (
         tmpdir, self.binary, htmlfile, fullname)
     os.system(cmd)
     try:
         html = open(htmlfile).read()
     except:
         try:
             return open("%s/error_log" % tmpdir, 'r').read()
         except:
             return ''
     return html
Пример #8
0
 def invokeCommand(self, tmpdir, fullname):
     # FIXME: windows users...
     textfile = "%s/%s.txt" % (tmpdir, sansext(fullname))
     cmd = 'cd "%s" && %s -enc UTF-8 "%s" "%s" 2>error_log 1>/dev/null' % (
         tmpdir, self.binary, fullname, textfile)
     os.system(cmd)
     try:
         text = open(textfile).read()
     except:
         try:
             return open("%s/error_log" % tmpdir, 'r').read()
         except:
             return ''
     return text
Пример #9
0
    def invokeCommand(self, tmpdir, fullname):
        cmd = 'cd "%s" && unzip %s 2>error_log 1>/dev/null' % (tmpdir,
                                                               fullname)
        p = Popen(cmd, shell=True)
        sts = os.waitpid(p.pid, 0)

        cmd = ('cd "%s" && xsltproc --novalid %s content.xml >"%s.html" '
               '2>"%s.log-xsltproc"') % (tmpdir, XSL_STYLESHEET,
                                         sansext(fullname), sansext(fullname))
        p = Popen(cmd, shell=True)
        sts = os.waitpid(p.pid, 0)

        try:
            htmlfile = open(
                os.path.join(tmpdir, "%s.html" % sansext(fullname)), 'r')
            html = htmlfile.read()
            htmlfile.close()
        except:
            try:
                return open(os.path.join(tmpdir, 'error_log'), 'r').read()
            except:
                return ''
        return html
Пример #10
0
 def invokeCommand(self, tmpdir, fullname):
     # FIXME: windows users...
     xmlfile = "%s/%s.xml" % (tmpdir, sansext(fullname))
     cmd = 'cd "%s" && %s -o %s "%s" 2>error_log 1>/dev/null' % (
         tmpdir, self.binary, xmlfile, fullname)
     if six.PY2:
         os.system(cmd)
     else:
         subprocess.run(cmd, shell=True)
     try:
         xml = open(xmlfile).read()
     except:
         try:
             return open("%s/error_log" % tmpdir, 'r').read()
         except:
             return ''
     return xml
Пример #11
0
 def invokeCommand(self, tmpdir, fullname):
     # FIXME: windows users...
     htmlfile = "%s/%s.html" % (tmpdir, sansext(fullname))
     cmd = 'cd "%s" && %s -o %s "%s" 2>error_log 1>/dev/null' % (
         tmpdir, self.binary, htmlfile, fullname)
     if six.PY2:
         os.system(cmd)
     else:
         subprocess.run(cmd, shell=True)
     try:
         html = open(htmlfile).read()
     except:
         try:
             return open("%s/error_log" % tmpdir, 'r').read()
         except:
             return ''
     return html
Пример #12
0
 def invokeCommand(self, tmpdir, fullname):
     if os.name=='posix':
         cmd = 'cd "%s" && %s %s "%s" 2>error_log 1>/dev/null' % (
                tmpdir, self.binary, self.binaryArgs, fullname)
     else:
         cmd = 'cd "%s" && %s %s "%s"' % (
               tmpdir, self.binary, self.binaryArgs, fullname)
     os.system(cmd)
     try:
         htmlfilename = os.path.join(tmpdir, sansext(fullname) + '.html')
         htmlfile = open(htmlfilename, 'r')
         html = htmlfile.read()
         htmlfile.close()
     except:
         try:
             return open("%s/error_log" % tmpdir, 'r').read()
         except:
             return "transform failed while running %s (maybe this pdf file doesn't support transform)" % cmd
     return html
Пример #13
0
 def invokeCommand(self, tmpdir, fullname):
     if os.name == 'posix':
         cmd = 'cd "%s" && %s %s "%s" 2>error_log 1>/dev/null' % (
             tmpdir, self.binary, self.binaryArgs, fullname)
     else:
         cmd = 'cd "%s" && %s %s "%s"' % (
               tmpdir, self.binary, self.binaryArgs, fullname)
     if six.PY2:
         os.system(cmd)
     else:
         subprocess.run(cmd, shell=True)
     try:
         htmlfilename = os.path.join(tmpdir, sansext(fullname) + '.html')
         with open(htmlfilename, 'rb') as htmlfile:
             html = htmlfile.read()
     except:
         try:
             with open("%s/error_log" % tmpdir, 'r') as fd:
                 error_log = fd.read()
             return error_log
         except:
             return ("transform failed while running %s (maybe this pdf "
                     "file doesn't support transform)" % cmd)
     return html