Example #1
0
class BlobDbBackendExporter(BaseDocProcessor):
    def __init__(self, slug, domain):
        from corehq.blobs.zipdb import ZipBlobDB
        self.slug = slug
        self.db = ZipBlobDB(self.slug, domain)
        self.total_blobs = 0
        self.not_found = 0

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.db.close()
        self.processing_complete()

    def process_object(self, meta):
        from_db = get_blob_db()
        self.total_blobs += 1
        try:
            content = from_db.get(key=meta.key)
        except NotFound:
            self.not_found += 1
        else:
            with content:
                self.db.copy_blob(content, key=meta.key)
        return True

    def processing_complete(self):
        if self.not_found:
            print(
                PROCESSING_COMPLETE_MESSAGE.format(self.not_found,
                                                   self.total_blobs))
Example #2
0
class BlobDbBackendExporter(BaseDocProcessor):
    def __init__(self, slug, domain, couchdb, blob_helper=BlobHelper):
        from corehq.blobs.zipdb import ZipBlobDB
        self.slug = slug
        self.blob_helper = blob_helper
        self.db = ZipBlobDB(self.slug, domain)
        self.total_blobs = 0
        self.not_found = 0
        self.domain = domain
        self.couchdb = couchdb

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.db.close()

    def process_doc(self, doc):
        obj = self.blob_helper(doc, self.couchdb)
        bucket = obj._blobdb_bucket()
        assert obj.external_blobs and obj.external_blobs == obj.blobs, doc
        from_db = get_blob_db()
        for name, meta in six.iteritems(obj.blobs):
            self.total_blobs += 1
            try:
                content = from_db.get(meta.id, bucket)
            except NotFound:
                self.not_found += 1
            else:
                with content:
                    self.db.copy_blob(content, meta.info, bucket)
        return True

    def processing_complete(self, skipped):
        if self.not_found:
            print(
                PROCESSING_COMPLETE_MESSAGE.format(self.not_found,
                                                   self.total_blobs))

    def should_process(self, doc):
        return self.blob_helper.get_external_blobs(doc)
Example #3
0
class BlobDbBackendExporter(BaseDocProcessor):

    def __init__(self, slug, domain, couchdb):
        from corehq.blobs.zipdb import ZipBlobDB
        self.slug = slug
        self.db = ZipBlobDB(self.slug, domain)
        self.total_blobs = 0
        self.not_found = 0
        self.domain = domain
        self.couchdb = couchdb

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.db.close()

    def process_doc(self, doc):
        obj = BlobHelper(doc, self.couchdb)
        bucket = obj._blobdb_bucket()
        assert obj.external_blobs and obj.external_blobs == obj.blobs, doc
        from_db = get_blob_db()
        for name, meta in obj.blobs.iteritems():
            self.total_blobs += 1
            try:
                content = from_db.get(meta.id, bucket)
            except NotFound:
                self.not_found += 1
            else:
                with content:
                    self.db.copy_blob(content, meta.info, bucket)
        return True

    def processing_complete(self, skipped):
        if self.not_found:
            print(PROCESSING_COMPLETE_MESSAGE.format(self.not_found, self.total_blobs))

    def should_process(self, doc):
        return doc.get("external_blobs")