Exemplo n.º 1
0
    def runConversion(self, job_id, source, target, format='pdf'):
        tempdir = filepath.FilePath(tempfile.mkdtemp(suffix='-unoconv'))
        tempsrc = tempdir.child(source.basename())

        source.copyTo(tempsrc)

        bin = "unoconv"

        args = ["-v"] * 5 + [
            "-f", format,
            #"-T", "10",
            tempsrc.path,
        ]

        yield self.queue.acquire()

        log.msg("JID {0} - Spawning conversion process".format(job_id))

        try:
            d = defer.Deferred()
            prot = ConverterProcessProtocol(d, job_id)
            print " ".join([bin] + args)
            reactor.spawnProcess(prot, bin, [bin] + args, env=os.environ)
            d.addCallback(self.handleResult, tempsrc, target)
            d.addErrback(self.handleError, job_id, tempdir)
            result = yield d
        except Exception as e:
            print "ERROR"
            print e
            raise
        finally:
            # Release the lock only after some time to make sure all uno
            # resources are freed before restarting the service.
            utils.sleep(10).addCallback(lambda _: self.queue.release())

        defer.returnValue(result)
Exemplo n.º 2
0
    def getUpload(self, upload_id):
        # 1. Santiy check and initialization
        source = settings.completed_root.globChildren(upload_id + '.*')
        if not source:
            # Before raising an InvalidUploadID exception, let some grace
            # period to allow to close the ftp connection/move the file if the
            # client is too fast.

            yield sleep(2)

            source = settings.completed_root.globChildren(upload_id + '.*')

            # If the file still does not exists, throw the exception
            if not source:
                raise error.InvalidUploadID(upload_id)
        defer.returnValue(source[0])
Exemplo n.º 3
0
 def _unreg(result, task):
     d = sleep(self.remove_timeout)
     d.addCallback(lambda _: self.unregister(task))
     return result