CK-InoDrive-API 0.2.9__tar.gz → 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CK_InoDrive_API.egg-info/PKG-INFO +3 -3
  2. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CK_InoDrive_API.egg-info/SOURCES.txt +3 -0
  3. ck_inodrive_api-1.0.1/CK_InoDrive_API.egg-info/requires.txt +3 -0
  4. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CkInoDriveAPI/IO.py +26 -23
  5. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CkInoDriveAPI/__init__.py +2 -0
  6. ck_inodrive_api-1.0.1/CkInoDriveAPI/_version.py +17 -0
  7. ck_inodrive_api-1.0.1/CkInoDriveAPI/callback.py +87 -0
  8. ck_inodrive_api-1.0.1/CkInoDriveAPI/ck_ca.crt +15 -0
  9. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CkInoDriveAPI/discoverLan.py +9 -120
  10. ck_inodrive_api-1.0.1/CkInoDriveAPI/discoverWs.py +42 -0
  11. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CkInoDriveAPI/file.py +29 -26
  12. ck_inodrive_api-1.0.1/CkInoDriveAPI/inoDrive.py +147 -0
  13. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CkInoDriveAPI/sysControl.py +8 -5
  14. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CkInoDriveAPI/userApp.py +292 -196
  15. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CkInoDriveAPI/utils.py +175 -45
  16. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CkInoDriveAPI/wsHandle.py +199 -140
  17. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/PKG-INFO +3 -3
  18. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/README.txt +55 -48
  19. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/setup.py +26 -8
  20. CK-InoDrive-API-0.2.9/CK_InoDrive_API.egg-info/requires.txt +0 -3
  21. CK-InoDrive-API-0.2.9/CkInoDriveAPI/discoverWs.py +0 -152
  22. CK-InoDrive-API-0.2.9/CkInoDriveAPI/inoDrive.py +0 -56
  23. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CK_InoDrive_API.egg-info/dependency_links.txt +0 -0
  24. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CK_InoDrive_API.egg-info/top_level.txt +0 -0
  25. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/CkInoDriveAPI/defines.py +0 -0
  26. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/LICENSE.txt +0 -0
  27. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CK-InoDrive-API
3
- Version: 0.2.9
3
+ Version: 1.0.1
4
4
  Summary: InoDrive API Library
5
5
  Home-page: https://cardinalkinetic.com
6
6
  Author: Cardinal Kinetic
@@ -18,9 +18,9 @@ Classifier: Programming Language :: Python :: 3.12
18
18
  Description-Content-Type: text/markdown
19
19
  License-File: LICENSE.txt
20
20
  License-File: README.txt
21
- Requires-Dist: websocket-client==1.6.4
21
+ Requires-Dist: websocket-client==1.8.0
22
22
  Requires-Dist: ifaddr==0.2.0
23
- Requires-Dist: msgpack==1.0.7
23
+ Requires-Dist: msgpack==1.1.0
24
24
 
25
25
  #### **Installation**
26
26
 
@@ -8,6 +8,9 @@ CK_InoDrive_API.egg-info/requires.txt
8
8
  CK_InoDrive_API.egg-info/top_level.txt
9
9
  CkInoDriveAPI/IO.py
10
10
  CkInoDriveAPI/__init__.py
11
+ CkInoDriveAPI/_version.py
12
+ CkInoDriveAPI/callback.py
13
+ CkInoDriveAPI/ck_ca.crt
11
14
  CkInoDriveAPI/defines.py
12
15
  CkInoDriveAPI/discoverLan.py
13
16
  CkInoDriveAPI/discoverWs.py
@@ -0,0 +1,3 @@
1
+ websocket-client==1.8.0
2
+ ifaddr==0.2.0
3
+ msgpack==1.1.0
@@ -1,13 +1,16 @@
1
1
  import logging
2
2
 
3
- from .wsHandle import InoDriveWS
4
3
  from .defines import CK
5
4
  from .defines import OP_STATE
6
5
 
7
6
 
8
7
  class IO(object):
9
8
  def __init__(self, **kwargs):
10
- self._connection_handle: InoDriveWS = kwargs.get('connection_handle')
9
+ self._get_connection_handle = kwargs.get('getConnectionHandle')
10
+
11
+ @property
12
+ def _connection_handle(self):
13
+ return self._get_connection_handle()
11
14
 
12
15
  def dispose(self):
13
16
  return
@@ -17,7 +20,7 @@ class IO(object):
17
20
  response = self._connection_handle.msg_pack_request([CK.MSG_PACK.GET_METRICS])
18
21
 
19
22
  if response.get('error'):
20
- return {'success': False, 'Error': f'InoDrive GetMetrics Error: {str(response.get("error"))}'}
23
+ return {'success': False, 'Error': f"InoDrive GetMetrics Error: {str(response.get('error'))}"}
21
24
 
22
25
  data = response['data'][0]
23
26
 
@@ -102,7 +105,7 @@ class IO(object):
102
105
  response = self._connection_handle.msg_pack_request([CK.MSG_PACK.GET_INPUTS])
103
106
 
104
107
  if response.get('error'):
105
- return {'success': False, 'Error': f'InoDrive GetInputData Error: {str(response.get("error"))}'}
108
+ return {'success': False, 'Error': f"InoDrive GetInputData Error: {str(response.get('error'))}"}
106
109
 
107
110
  data = response['data'][0]
108
111
  data.update({'success': True})
@@ -130,7 +133,7 @@ class IO(object):
130
133
  logging.error(data['error'])
131
134
  return None
132
135
 
133
- if type(input) == int and input >= 0 and input <= 3:
136
+ if type(input) is int and 0 <= input <= 3:
134
137
  return 1 if (data['digital'] >> input) & 0x1 else 0
135
138
  else:
136
139
  return data['digital']
@@ -146,7 +149,7 @@ class IO(object):
146
149
  logging.error(data['error'])
147
150
  return None
148
151
 
149
- if type(input) == int and input >= 0 and input <= 1:
152
+ if type(input) is int and 0 <= input <= 1:
150
153
  return 1 if (data['safety'] >> input) & 0x1 else 0
151
154
  else:
152
155
  return data['safety']
@@ -173,25 +176,25 @@ class IO(object):
173
176
 
174
177
  if target == 'all' and state is not None:
175
178
  target = -1
176
- if type(state) == str:
179
+ if type(state) is str:
177
180
  state = 0xf if state.upper() == 'NPN' else 0x0
178
181
  else:
179
182
  state = 0xf if state else 0x0
180
- elif target == 'val' and type(state) == int:
183
+ elif target == 'val' and type(state) is int:
181
184
  target = -1
182
- elif type(target) == int and target >= 0 and target <= 3 and state is not None:
183
- if type(state) == str:
185
+ elif type(target) is int and 0 <= target <= 3 and state is not None:
186
+ if type(state) is str:
184
187
  state = 0x1 if state.upper() == 'NPN' else 0x0
185
188
  else:
186
189
  state = 0x1 if state else 0x0
187
190
  else:
188
- logging.error(f'InoDrive SetInputPolarity Error: target or state not supported...')
191
+ logging.error(f"InoDrive SetInputPolarity Error: target or state not supported...")
189
192
  return None
190
193
 
191
194
  response = self._connection_handle.msg_pack_request([CK.MSG_PACK.SET_INPUT_POLARITY, target, state])
192
195
 
193
196
  if response.get('error'):
194
- logging.error(f'InoDrive SetInputPolarity Error: {str(response)}')
197
+ logging.error(f"InoDrive SetInputPolarity Error: {str(response)}")
195
198
  return None
196
199
 
197
200
  return True
@@ -207,7 +210,7 @@ class IO(object):
207
210
  logging.error(data['error'])
208
211
  return None
209
212
 
210
- if type(input) == int and input >= 0 and input <= 3:
213
+ if type(input) is int and 0 <= input <= 3:
211
214
  return 'NPN' if (data['polarity'] >> input) & 0x1 else 'PNP'
212
215
  else:
213
216
  return data['polarity']
@@ -221,7 +224,7 @@ class IO(object):
221
224
  response = self._connection_handle.msg_pack_request([CK.MSG_PACK.GET_OUTPUTS])
222
225
 
223
226
  if response.get('error'):
224
- return {'success': False, 'Error': f'InoDrive GetOutputData Error: {str(response.get("error"))}'}
227
+ return {'success': False, 'Error': f"InoDrive GetOutputData Error: {str(response.get('error'))}"}
225
228
 
226
229
  data = response['data'][0]
227
230
  data.update({'success': True})
@@ -235,19 +238,19 @@ class IO(object):
235
238
  if target == 'all' and state is not None:
236
239
  target = -1
237
240
  state = 0x7 if state else 0x0
238
- elif target == 'val' and type(state) == int:
241
+ elif target == 'val' and type(state) is int:
239
242
  target = -1
240
- elif type(target) == int and target >= 0 and target <= 2 and state is not None:
243
+ elif type(target) is int and 0 <= target <= 2 and state is not None:
241
244
  state = 0x1 if state else 0x0
242
245
  else:
243
- logging.error(f'InoDrive SetOutput Error: target os state not supported...')
246
+ logging.error(f"InoDrive SetOutput Error: target os state not supported...")
244
247
  return None
245
248
 
246
249
  response = self._connection_handle.msg_pack_request([CK.MSG_PACK.SET_OUTPUTS, target, state])
247
250
 
248
251
  if response.get('error'):
249
- logging.error(f'InoDrive SetOutput Error: {str(response)}')
250
- return None
252
+ logging.error(f"InoDrive SetOutput Error: {str(response)}")
253
+ return False
251
254
 
252
255
  return True
253
256
  except Exception as ex:
@@ -263,7 +266,7 @@ class IO(object):
263
266
  logging.error(data['error'])
264
267
  return None
265
268
 
266
- if type(output) == int and output >= 0 and output <= 2:
269
+ if type(output) is int and 0 <= output <= 2:
267
270
  return 1 if (data['digital'] >> output) & 0x1 else 0
268
271
  else:
269
272
  return data['digital']
@@ -281,7 +284,7 @@ class IO(object):
281
284
  logging.error(data['error'])
282
285
  return None
283
286
 
284
- if type(output) == int and output >= 0 and output <= 2:
287
+ if type(output) is int and 0 <= output <= 2:
285
288
  return 1 if (data['digital_faults'] >> output) & 0x1 else 0
286
289
  else:
287
290
  return data['digital_faults']
@@ -297,8 +300,8 @@ class IO(object):
297
300
  response = self._connection_handle.msg_pack_request([CK.MSG_PACK.SET_HOLDING_BRAKE, True if state else False])
298
301
 
299
302
  if response.get('error'):
300
- logging.error(f'InoDrive GetOutputFault Error: {str(response)}')
301
- return None
303
+ logging.error(f"InoDrive SetHoldingBrake Error: {str(response)}")
304
+ return False
302
305
 
303
306
  return True
304
307
  except Exception as ex:
@@ -2,3 +2,5 @@ from .inoDrive import InoDrive
2
2
  from .discoverLan import id_discover_lan
3
3
 
4
4
  discover = id_discover_lan
5
+ __version__ = '1.0.1'
6
+ __version__ = '1.0.1'
@@ -0,0 +1,17 @@
1
+ from pathlib import Path
2
+ import sys
3
+ import os
4
+
5
+
6
+ def get_version_number():
7
+ try:
8
+ dir_path = str(Path(os.path.dirname(__file__)).parent)
9
+ sys.path.append(dir_path)
10
+
11
+ from versions import get_latest_number
12
+ version = get_latest_number()
13
+ except ImportError:
14
+ from .__init__ import __version__
15
+ version = __version__
16
+
17
+ return version
@@ -0,0 +1,87 @@
1
+ import logging
2
+
3
+
4
+ class Callback(object):
5
+ _context = None
6
+ _callbacks = {}
7
+
8
+ def __init__(self, **kwargs):
9
+ self._context = kwargs.get('context', self)
10
+
11
+ def on(self, name=None, func=None):
12
+ try:
13
+ callbacks = {}
14
+
15
+ if type(name) is dict:
16
+ callbacks = name
17
+ elif type(name) is str and callable(func):
18
+ callbacks[name] = func
19
+ else:
20
+ return
21
+
22
+ for callback_name, callback_function in callbacks.items():
23
+ if type(callback_name) is not str:
24
+ continue
25
+
26
+ if not callable(callback_function):
27
+ continue
28
+
29
+ if callback_name not in self._callbacks:
30
+ # Callback does not exist
31
+ self._callbacks[callback_name] = [callback_function]
32
+ continue
33
+
34
+ if callback_function not in self._callbacks[callback_name]:
35
+ # Function is not in callback group
36
+ self._callbacks[callback_name].append(callback_function)
37
+ continue
38
+
39
+ except Exception as ex:
40
+ logging.exception(ex)
41
+
42
+ def remove(self, name=None, func=None):
43
+ try:
44
+ if type(name) is not str:
45
+ return
46
+
47
+ if not callable(func):
48
+ return
49
+
50
+ if self._callbacks[name] and func in self._callbacks[name]:
51
+ # Function exist so we need to remove it - removing callback.
52
+ self._callbacks[name].pop(self._callbacks[name].index(func))
53
+
54
+ if len(self._callbacks[name]) == 0:
55
+ # There are no more functions in the group - remove the group
56
+ del self._callbacks[name]
57
+
58
+ except Exception as ex:
59
+ logging.exception(ex)
60
+
61
+ def dispatch(self, callback_name=None, *args):
62
+ try:
63
+ # Get call back group
64
+ if callback_name in self._callbacks:
65
+ callbacks = self._callbacks[callback_name]
66
+ if callbacks is not None:
67
+ for callback in callbacks:
68
+ # Call each callback
69
+ if callable(callback):
70
+ callback(*args)
71
+
72
+ except Exception as ex:
73
+ logging.exception(ex)
74
+
75
+ def dispatch_with_context(self, context=None, callback_name=None, *args):
76
+ try:
77
+ # Get call back group
78
+ if callback_name in self._callbacks:
79
+ callbacks = self._callbacks[callback_name]
80
+ if callbacks is not None:
81
+ for callback in callbacks:
82
+ # Call each callback
83
+ if callable(callback):
84
+ callback(context, *args)
85
+
86
+ except Exception as ex:
87
+ logging.exception(ex)
@@ -0,0 +1,15 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICUTCCAdigAwIBAgIUKSVqbARTYaxckTUEA7Gby+uWD8IwCgYIKoZIzj0EAwIw
3
+ VzELMAkGA1UEBhMCVVMxETAPBgNVBAgMCEtlbnR1Y2t5MRgwFgYDVQQKDA9DYXJk
4
+ aW5hbEtpbmV0aWMxGzAZBgNVBAMMEkNhcmRpbmFsS2luZXRpYy1DQTAgFw0yNDA3
5
+ MTUxODM1NTVaGA8yMDk5MDQxMzE4MzU1NVowVzELMAkGA1UEBhMCVVMxETAPBgNV
6
+ BAgMCEtlbnR1Y2t5MRgwFgYDVQQKDA9DYXJkaW5hbEtpbmV0aWMxGzAZBgNVBAMM
7
+ EkNhcmRpbmFsS2luZXRpYy1DQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABGvtdcSO
8
+ PH4qPKdA/wSbraw88KgoiBmJMaD3ko4Gaix6iZSBTEK1TU+Oxp0XwVuaQxa0J7hp
9
+ xcjuy3BLYDhfF5e5Fp/Tjc4qaQNDZs9Z0MbVytZeNtrm7u4lwKWsjIjhUqNjMGEw
10
+ HQYDVR0OBBYEFOQ3kaz6Bd2kAHicNWlIoWdSYclMMB8GA1UdIwQYMBaAFOQ3kaz6
11
+ Bd2kAHicNWlIoWdSYclMMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGG
12
+ MAoGCCqGSM49BAMCA2cAMGQCMFhAt55Z+O88sJ60Z2FcGmYztu6QF18tdj04YlQX
13
+ SBWZ8tdpWofMsJi6yHwKlhqqQgIwVEpeh5RSuVSGmZAfYNFLLSnAYV0LnkKEAmuZ
14
+ 2YwmOc7BTjgjgnZrhb9538baKIaG
15
+ -----END CERTIFICATE-----
@@ -174,105 +174,12 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
174
174
  # Remove 9 bytes header
175
175
  data = resp[9:]
176
176
 
177
- # Discover version
178
- # =======================================================================
179
- item_size = 1
180
- discover_version = Utils.get_typed_value(data[0:item_size], 'uint8')
181
- data = data[item_size:]
182
- # =======================================================================
177
+ module_object = Utils.decode_discover_data(data)
178
+ sn = None
183
179
 
184
- # SN
185
- # =======================================================================
186
- item_size = 25
187
- sn = Utils.get_typed_value(data[0:item_size], 'string')
188
- data = data[item_size:]
189
- # =======================================================================
190
-
191
- # PN
192
- # =======================================================================
193
- item_size = 25
194
- pn = Utils.get_typed_value(data[0:item_size], 'string')
195
- data = data[item_size:]
196
- # =======================================================================
197
-
198
- # Name
199
- # =======================================================================
200
- item_size = 33
201
- name = Utils.get_typed_value(data[0:item_size], 'string')
202
- data = data[item_size:]
203
- # =======================================================================
204
-
205
- # Firmware version
206
- # =======================================================================
207
- item_size = 1
208
- fw_major = Utils.get_typed_value(data[0:item_size], 'uint8')
209
- data = data[item_size:]
210
-
211
- item_size = 1
212
- fw_minor = Utils.get_typed_value(data[0:item_size], 'uint8')
213
- data = data[item_size:]
214
-
215
- item_size = 1
216
- fw_build = Utils.get_typed_value(data[0:item_size], 'uint8')
217
- data = data[item_size:]
218
-
219
- item_size = 1
220
- fw_type = Utils.get_typed_value(data[0:item_size], 'uint8')
221
- data = data[item_size:]
222
-
223
- firmware_flags = Utils.get_firmware_flags(fw_type)
224
- # =======================================================================
225
-
226
- # Networking
227
- # =======================================================================
228
- item_size = 6
229
- mac_address = Utils.get_typed_value(data[0:item_size], 'macAddress')
230
- data = data[item_size:]
231
-
232
- item_size = 4
233
- ip_address = Utils.get_typed_value(data[0:item_size], 'ipV4')
234
- data = data[item_size:]
235
-
236
- item_size = 4
237
- net_mask = Utils.get_typed_value(data[0:item_size], 'ipV4')
238
- data = data[item_size:]
239
-
240
- item_size = 4
241
- gateway = Utils.get_typed_value(data[0:item_size], 'ipV4')
242
- data = data[item_size:]
243
-
244
- item_size = 4
245
- dns = Utils.get_typed_value(data[0:item_size], 'ipV4')
246
- data = data[item_size:]
247
- # =======================================================================
248
-
249
- # PCB Version
250
- # =======================================================================
251
- pcb_major = 1
252
- pcb_minor = 1
253
- pcb_build = 1
254
- pcb_type = 0
255
-
256
- if discover_version >= 2:
257
- item_size = 1
258
- pcb_major = Utils.get_typed_value(data[0:item_size], 'uint8')
259
- data = data[item_size:]
260
-
261
- item_size = 1
262
- pcb_minor = Utils.get_typed_value(data[0:item_size], 'uint8')
263
- data = data[item_size:]
264
-
265
- item_size = 1
266
- pcb_build = Utils.get_typed_value(data[0:item_size], 'uint8')
267
- data = data[item_size:]
268
-
269
- if discover_version >= 3:
270
- item_size = 1
271
- pcb_type = Utils.get_typed_value(data[0:item_size], 'uint8')
272
- data = data[item_size:]
273
-
274
- pcb_flags = Utils.get_pcb_flags(pcb_type)
275
- # =======================================================================
180
+ if module_object is not None:
181
+ module_object['netif'] = netif_ip_tuple[0]
182
+ sn = module_object['sn']
276
183
 
277
184
  except struct.error:
278
185
  continue
@@ -281,25 +188,7 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
281
188
  continue
282
189
 
283
190
  if sn not in modules_found:
284
- new_module_d = {
285
- 'discoverVersion': discover_version,
286
- 'sn': sn,
287
- 'pn': pn,
288
- 'name': name,
289
- 'firmware': '.'.join([str(fw_major), str(fw_minor), str(fw_build)]),
290
- 'firmwareFlags': firmware_flags,
291
- 'network': {
292
- 'ip': ip_address,
293
- 'mask': net_mask,
294
- 'gw': gateway,
295
- 'dns': dns,
296
- 'mac': mac_address,
297
- },
298
- 'pcb': '.'.join([str(pcb_major), str(pcb_minor), str(pcb_build)]),
299
- 'pcbFlags': pcb_flags,
300
- "netif": netif_ip_tuple[0]
301
- }
302
- modules_found[sn] = new_module_d
191
+ modules_found[sn] = module_object
303
192
  # for resp in response_list:
304
193
  # for iteration in range(num_attempts):
305
194
 
@@ -338,6 +227,6 @@ def id_discover_lan(net_adapter_ip=None, num_attempts=2):
338
227
  pass
339
228
 
340
229
  # Return a stripped down version of the dictionary because the serial number key is no longer needed.
341
- results_list = list(all_modules_on_all_ifs.values())
342
- logging.info(f'Total modules found: {len(results_list)}')
343
- return results_list
230
+ results = list(all_modules_on_all_ifs.values())
231
+ logging.info(f"Total modules found: {len(results)}")
232
+ return results
@@ -0,0 +1,42 @@
1
+ import logging
2
+
3
+ from .defines import CK
4
+ from .utils import Utils
5
+
6
+
7
+ class DiscoverWs(object):
8
+ def __init__(self, **kwargs):
9
+ self._get_connection_handle = kwargs.get('getConnectionHandle')
10
+
11
+ @property
12
+ def _connection_handle(self):
13
+ return self._get_connection_handle()
14
+
15
+ def dispose(self):
16
+ return
17
+
18
+ def get_info(self):
19
+ try:
20
+ # Send request and wait for response
21
+ resp = self._connection_handle.request(Utils.get_tlv(CK.SPECIAL.GET_DISCOVER_INFO))
22
+
23
+ if resp.get('error'):
24
+ logging.error(f"Retrieving discover info failed...")
25
+ return None
26
+
27
+ result = None
28
+
29
+ resp_items = resp.get('items')
30
+ if resp_items and len(resp_items) > 0:
31
+ data = resp_items[0].get('data')
32
+ result = Utils.decode_discover_data(data)
33
+
34
+ if result is None:
35
+ logging.exception("Message decoding error")
36
+ return None
37
+
38
+ return result
39
+ except Exception as ex:
40
+ logging.exception(ex)
41
+
42
+ return None
@@ -1,14 +1,17 @@
1
1
  import json
2
2
  import logging
3
3
 
4
- from .wsHandle import InoDriveWS
5
4
  from .defines import CK
6
5
  from .utils import Utils
7
6
 
8
7
 
9
8
  class File(object):
10
9
  def __init__(self, **kwargs):
11
- self._connection_handle: InoDriveWS = kwargs.get('connection_handle')
10
+ self._get_connection_handle = kwargs.get('getConnectionHandle')
11
+
12
+ @property
13
+ def _connection_handle(self):
14
+ return self._get_connection_handle()
12
15
 
13
16
  def dispose(self):
14
17
  return
@@ -16,27 +19,27 @@ class File(object):
16
19
  def read(self, files=None, transfer_type=None):
17
20
  try:
18
21
  if files is None:
19
- logging.error(f'Files is None...')
22
+ logging.error(f"Files is None...")
20
23
  return None
21
24
 
22
- if type(files) != list:
25
+ if type(files) is not list:
23
26
  files = [files]
24
27
 
25
28
  files_content = []
26
29
 
27
30
  # Upload uApp and firmware are specifying different types
28
- transfer_type = transfer_type if type(transfer_type) == int else CK.FILE.TRANSFER
31
+ transfer_type = transfer_type if type(transfer_type) is int else CK.FILE.TRANSFER
29
32
 
30
33
  for file in files:
31
- if type(file) != dict:
32
- logging.error(f'File is not a dict...')
34
+ if type(file) is not dict:
35
+ logging.error(f"File is not a dict...")
33
36
  return None
34
37
 
35
38
  file_path = file.get('path')
36
39
  content = file.get('content', 'bytes')
37
40
 
38
- if type(file_path) != str:
39
- logging.error(f'File path is not a string...')
41
+ if type(file_path) is not str:
42
+ logging.error(f"File path is not a string...")
40
43
  return None
41
44
 
42
45
  file_path = file_path.replace('\\', '/')
@@ -45,7 +48,7 @@ class File(object):
45
48
  file_path = file_path[1:]
46
49
 
47
50
  if file_path[0] != '/':
48
- file_path = f'/{file_path}'
51
+ file_path = f"/{file_path}"
49
52
 
50
53
  file_path = file_path.replace('\\', '/')
51
54
 
@@ -80,18 +83,18 @@ class File(object):
80
83
  def write(self, files=None, transfer_type=None):
81
84
  try:
82
85
  if files is None:
83
- logging.error(f'Files is None...')
86
+ logging.error(f"Files not provided...")
84
87
  return False
85
88
 
86
- if type(files) != list:
89
+ if type(files) is not list:
87
90
  files = [files]
88
91
 
89
92
  # Upload uApp and firmware are specifying different types
90
- transfer_type = transfer_type if type(transfer_type) == int else CK.FILE.TRANSFER
93
+ transfer_type = transfer_type if type(transfer_type) is int else CK.FILE.TRANSFER
91
94
 
92
95
  for file in files:
93
- if type(file) != dict:
94
- logging.error(f'File is not a dict...')
96
+ if type(file) is not dict:
97
+ logging.error(f"File is not a dict...")
95
98
  return False
96
99
 
97
100
  file_path = file.get('path')
@@ -102,20 +105,20 @@ class File(object):
102
105
  file_path = file_path[1:]
103
106
 
104
107
  if file_path[0] != '/':
105
- file_path = f'/{file_path}'
108
+ file_path = f"/{file_path}"
106
109
 
107
110
  file_path = file_path.replace('\\', '/')
108
111
 
109
112
  file_content = file.get('content')
110
113
 
111
- if type(file_content) == dict:
114
+ if type(file_content) is dict:
112
115
  file_content = json.dumps(file_content)
113
116
 
114
- if type(file_content) == str:
117
+ if type(file_content) is str:
115
118
  file_content = bytes(file_content, 'utf-8')
116
119
 
117
- if file_content is None or type(file_content) != bytes:
118
- logging.error(f'File content is not bytes...')
120
+ if file_content is None or type(file_content) is not bytes:
121
+ logging.error(f"File content is not bytes...")
119
122
  return False
120
123
 
121
124
  msg = b''
@@ -130,7 +133,7 @@ class File(object):
130
133
  resp = self._connection_handle.request(msg)
131
134
 
132
135
  if resp.get('error'):
133
- logging.error(f'File [{file_path}] write error: {resp.get("error")}')
136
+ logging.error(f"File [{file_path}] write error: {resp.get('error')}")
134
137
  return False
135
138
 
136
139
  return True
@@ -145,7 +148,7 @@ class File(object):
145
148
  resp = self._connection_handle.request(Utils.get_tlv(CK.SPECIAL.DELETE_UAPP))
146
149
 
147
150
  if resp.get('error'):
148
- logging.error(f'Deleting User Application failed...')
151
+ logging.error(f"Deleting User Application failed...")
149
152
  return False
150
153
 
151
154
  return True
@@ -156,19 +159,19 @@ class File(object):
156
159
 
157
160
  def upload_user_app(self, content=None):
158
161
  try:
159
- return self.write({'path': "/uapp/application.idsol", 'content': content}, CK.FILE.UAPP_TRANSFER)
162
+ return self.write([{'path': "/uapp/application.idsol", 'content': content}], CK.FILE.UAPP_TRANSFER)
160
163
  except Exception as ex:
161
164
  logging.exception(ex)
162
165
 
163
166
  def upload_firmware(self, content=None):
164
167
  try:
165
- return self.write({'path': "/firmware/firmware.ckfw", 'content': content}, CK.FILE.FIRMWARE_TRANSFER)
168
+ return self.write([{'path': "/firmware/firmware.ckfw", 'content': content}], CK.FILE.FIRMWARE_TRANSFER)
166
169
  except Exception as ex:
167
170
  logging.exception(ex)
168
171
 
169
172
  def upload_webpage(self, content=None):
170
173
  try:
171
- return self.write({'path': "web.bfb", 'content': content}, CK.FILE.WEBPAGE_TRANSFER)
174
+ return self.write([{'path': "web.bfb", 'content': content}], CK.FILE.WEBPAGE_TRANSFER)
172
175
  except Exception as ex:
173
176
  logging.exception(ex)
174
177
 
@@ -180,7 +183,7 @@ class File(object):
180
183
 
181
184
  def write_module_config(self, content=None):
182
185
  try:
183
- if type(content) != dict:
186
+ if type(content) is not dict:
184
187
  logging.error('Content type is not dictionary')
185
188
  return False
186
189