connectors/ConnectorBase.py
author Schlumpf <schlumpf@kr-ll.de>
Fri, 15 Mar 2019 17:34:24 +0100
branchgenerate-button
changeset 2531 f5891ce3228e
parent 2492 7dd551ac2fa0
child 2540 fca79ca84272
permissions -rw-r--r--
Add "Generate Program" to toolbar in PLCOpenEditor standalone mode.

Currently you can find the "Generate Program" action only in the file menu,
but this action is very often used in standalone mode, so I added toolbuffon.
#!/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)