Ejemplo n.º 1
0
Archivo: local.py Proyecto: moldit/mold
 def copyFile(self, path, producer):
     """
     Copy a file to this machine.
     """
     fh = open(path, 'wb', 0)
     #from StringIO import StringIO
     #fh = StringIO()
     consumer = FileConsumer(fh)
     consumer.registerProducer(producer, True)
     return producer.startProducing(consumer)
Ejemplo n.º 2
0
        def writeFile_cb(data):
            # path = <OwnerPBoxId>/<FileId>
            if not os.path.exists(str(pboxid)):
                os.mkdir(str(pboxid))
            file = open(str(pboxid) + "/" + str(data[0][0]), "w")
            prod = FD2FileProducer(request)
            cons = FileConsumer(file)
            cons.registerProducer(prod, True)
            d = prod.startProducing(cons)
            d.addCallback(finishRequest_cb, file)

            return NOT_DONE_YET
Ejemplo n.º 3
0
        def writeFile_cb(data):
            # path = <OwnerPBoxId>/<FileId>
            if not os.path.exists(str(pboxid)):
                os.mkdir(str(pboxid))
            file = open(str(pboxid) + "/" + str(data[0][0]) ,"w")
            prod = FD2FileProducer(request)
            cons = FileConsumer(file)
            cons.registerProducer(prod, True)
            d = prod.startProducing(cons)
            d.addCallback(finishRequest_cb, file)

            return NOT_DONE_YET
Ejemplo n.º 4
0
 def handleGetShared_cb(response, f):
     finished = Deferred()
     finished.addCallback(self.writeFile_cb, s)
     cons = FileConsumer(f)
     response.deliverBody(FileDownload(finished, cons))
     print "Downloading file..."
     return finished
Ejemplo n.º 5
0
        def writeFile_cb(data, ownerid):
            if len(data) != 0:
                error = { 'status': {'error': "Invalid Request",
                        'message': "File unreachable."} }
                request.write(json.dumps(error, sort_keys=True, encoding="utf-8"))
                request.finish()
                return

            # path = <OwnerPBoxId>/<FileId>
            file = open(str(ownerid) + "/" + fileid ,"w")
            prod = FD2FileProducer(request)
            cons = FileConsumer(file)
            cons.registerProducer(prod, True)
            d = prod.startProducing(cons)
            d.addCallback(finishRequest_cb, file)

            return NOT_DONE_YET
Ejemplo n.º 6
0
def cbRequest(response, file):
    print 'Response version:', response.version
    print 'Response code:', response.code
    print 'Response phrase:', response.phrase
    print 'Response headers:'
    print pformat(list(response.headers.getAllRawHeaders()))
    finished = Deferred()
    cons = FileConsumer(file)
    response.deliverBody(FileDownload(finished, cons))
    return finished
Ejemplo n.º 7
0
        def writeFile_cb(data, ownerid):
            if len(data) != 0:
                error = {
                    'status': {
                        'error': "Invalid Request",
                        'message': "File unreachable."
                    }
                }
                request.write(
                    json.dumps(error, sort_keys=True, encoding="utf-8"))
                request.finish()
                return

            # path = <OwnerPBoxId>/<FileId>
            file = open(str(ownerid) + "/" + fileid, "w")
            prod = FD2FileProducer(request)
            cons = FileConsumer(file)
            cons.registerProducer(prod, True)
            d = prod.startProducing(cons)
            d.addCallback(finishRequest_cb, file)

            return NOT_DONE_YET