connectors/ConnectorBase.py
author Edouard Tisserant
Wed, 13 Feb 2019 13:08:26 +0100
changeset 2488 889c43872f4c
parent 2487 6a4f9a061994
child 2492 7dd551ac2fa0
permissions -rw-r--r--
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
     3
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
     4
# See COPYING file for copyrights details.
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
     5
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
     6
import md5
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
     7
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
     8
class ConnectorBase(object):
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
     9
2465
47d3aea2be30 Bigger chunks, from 16k to 1M
Edouard Tisserant
parents: 2463
diff changeset
    10
    #chuncksize = 16384
47d3aea2be30 Bigger chunks, from 16k to 1M
Edouard Tisserant
parents: 2463
diff changeset
    11
    chuncksize = 1024*1024
2487
6a4f9a061994 Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents: 2465
diff changeset
    12
    def BlobFromFile(self, filepath, seed):
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
    13
        s = md5.new()
2487
6a4f9a061994 Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents: 2465
diff changeset
    14
        s.update(seed)
6a4f9a061994 Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents: 2465
diff changeset
    15
        blobID = self.SeedBlob(seed)
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
    16
        with open(filepath, "rb") as f:
2487
6a4f9a061994 Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents: 2465
diff changeset
    17
            while blobID == s.digest():
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
    18
                chunk = f.read(self.chuncksize) 
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
    19
                if len(chunk) == 0: return blobID
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
    20
                blobID = self.AppendChunkToBlob(chunk, blobID)
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
    21
                s.update(chunk)
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff changeset
    22