author | Edouard Tisserant |
Wed, 29 Nov 2023 11:54:56 +0100 | |
changeset 3861 | 7e17f7e02a2b |
parent 2621 | af09744a468e |
child 3881 | 0b3ac94f494c |
permissions | -rw-r--r-- |
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 |
|
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
6 |
from __future__ import absolute_import |
2540
fca79ca84272
Replace md5 module with hashlib
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2492
diff
changeset
|
7 |
import hashlib |
3861
7e17f7e02a2b
Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents:
2621
diff
changeset
|
8 |
from runtime import PlcStatus |
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff
changeset
|
9 |
|
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
10 |
|
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff
changeset
|
11 |
class ConnectorBase(object): |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff
changeset
|
12 |
|
2465 | 13 |
chuncksize = 1024*1024 |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
14 |
|
3861
7e17f7e02a2b
Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents:
2621
diff
changeset
|
15 |
PLCObjDefaults = { |
7e17f7e02a2b
Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents:
2621
diff
changeset
|
16 |
"StartPLC": False, |
7e17f7e02a2b
Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents:
2621
diff
changeset
|
17 |
"GetTraceVariables": (PlcStatus.Broken, None), |
7e17f7e02a2b
Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents:
2621
diff
changeset
|
18 |
"GetPLCstatus": (PlcStatus.Broken, None), |
7e17f7e02a2b
Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents:
2621
diff
changeset
|
19 |
"RemoteExec": (-1, "RemoteExec script failed!"), |
7e17f7e02a2b
Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents:
2621
diff
changeset
|
20 |
"GetVersions": "*** Unknown ***" |
7e17f7e02a2b
Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents:
2621
diff
changeset
|
21 |
} |
7e17f7e02a2b
Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents:
2621
diff
changeset
|
22 |
|
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
|
23 |
def BlobFromFile(self, filepath, seed): |
2540
fca79ca84272
Replace md5 module with hashlib
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2492
diff
changeset
|
24 |
s = hashlib.new('md5') |
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
|
25 |
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
|
26 |
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
|
27 |
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
|
28 |
while blobID == s.digest(): |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
29 |
chunk = f.read(self.chuncksize) |
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
30 |
if len(chunk) == 0: |
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
31 |
return blobID |
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
diff
changeset
|
32 |
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
|
33 |
s.update(chunk) |
2621
af09744a468e
Better error handling when blob transfer fail
Edouard Tisserant
parents:
2542
diff
changeset
|
34 |
raise IOError("Data corrupted during transfer or connection lost") |