connectors/ConnectorBase.py
author Edouard Tisserant
Fri, 22 Mar 2019 10:57:04 +0100
branchsearch_in_CTN
changeset 2528 6bfc8a9bf0e7
parent 2492 7dd551ac2fa0
child 2540 fca79ca84272
permissions -rw-r--r--
WIP adding searching capabilities in python files. was done :
- added search in body of Code File Tree Nodes (moved editor code so that we CTN search can have the same sections text layout as editor to search in)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# See COPYING file for copyrights details.

from __future__ import absolute_import
import md5


class ConnectorBase(object):

    chuncksize = 1024*1024

    def BlobFromFile(self, filepath, seed):
        s = md5.new()
        s.update(seed)
        blobID = self.SeedBlob(seed)
        with open(filepath, "rb") as f:
            while blobID == s.digest():
                chunk = f.read(self.chuncksize)
                if len(chunk) == 0:
                    return blobID
                blobID = self.AppendChunkToBlob(chunk, blobID)
                s.update(chunk)