Beispiel #1
0
 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)
Beispiel #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
Beispiel #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
 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
Beispiel #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
Beispiel #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
Beispiel #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