tinytoolslib 0.3.4__tar.gz → 0.4.0__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.
@@ -1,12 +1,12 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: tinytoolslib
3
- Version: 0.3.4
3
+ Version: 0.4.0
4
4
  Summary: Set of tools for use with Tinycontrol devices like LK2.X, LK3.X, LK4.X or tcPDU.
5
5
  Author-email: Bartek Barszczewski <tinycontrol.software@gmail.com>
6
+ License-Expression: Apache-2.0
6
7
  Keywords: tinycontrol,lk,tcpdu
7
8
  Classifier: Programming Language :: Python :: 3
8
9
  Classifier: Operating System :: OS Independent
9
- Classifier: License :: OSI Approved :: Apache Software License
10
10
  Requires-Python: >=3.7
11
11
  Description-Content-Type: text/markdown
12
12
  Requires-Dist: aiohttp<4,>=3.9.3
@@ -4,16 +4,16 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tinytoolslib"
7
- version = "0.3.4"
7
+ version = "0.4.0"
8
8
  authors = [
9
9
  { name="Bartek Barszczewski", email="tinycontrol.software@gmail.com" },
10
10
  ]
11
+ license = "Apache-2.0"
11
12
  description = "Set of tools for use with Tinycontrol devices like LK2.X, LK3.X, LK4.X or tcPDU."
12
13
  requires-python = ">=3.7"
13
14
  classifiers = [
14
15
  "Programming Language :: Python :: 3",
15
16
  "Operating System :: OS Independent",
16
- "License :: OSI Approved :: Apache Software License",
17
17
  ]
18
18
  dependencies = [
19
19
  "aiohttp >= 3.9.3, < 4",
@@ -0,0 +1 @@
1
+ __version__ = '0.4.0'
@@ -276,9 +276,10 @@ class Flasher:
276
276
  self,
277
277
  firmware_path: str,
278
278
  host: str,
279
- username: str,
280
- password: str,
281
279
  port: int = 80,
280
+ schema: str = "http",
281
+ username: str = "",
282
+ password: str = "",
282
283
  callback_progress: Union[Callable[[int, int, float, str], None], None] = None,
283
284
  callback_cancel: Union[Callable[[], bool], None] = None,
284
285
  ) -> bool:
@@ -295,17 +296,14 @@ class Flasher:
295
296
  and os.path.isfile(firmware_path)
296
297
  ):
297
298
  with self._session:
298
- # Try to check what device type are we working with. For now,
299
- # assume that lk4/tcpdu always respond via HTTP.
300
- version_info = get_version(host, port, username, password)
301
- if (
302
- version_info
303
- and version_info["network_info"].get("schema") == "https"
304
- ):
305
- schema = "https"
306
- port = 443
307
- else:
308
- schema = "http"
299
+ # Try to get device version. Note that get_version may return
300
+ # different port and schema than given ones, eg. for http:80,
301
+ # may return http:80 or https:443.
302
+ # It also assumes that lk4/tcpdu always respond via HTTP.
303
+ version_info = get_version(host, port, schema, username, password)
304
+ if version_info and "network_info" in version_info:
305
+ schema = version_info["network_info"]["schema"]
306
+ port = version_info["network_info"]["port"]
309
307
  if (
310
308
  version_info
311
309
  and version_info.get("fw_update_method") == FWUpdateMethod.HTTP
@@ -347,7 +345,12 @@ def check_for_latest_firmware(fw_url: str) -> Tuple[bool, Union[Dict[str, Any],
347
345
 
348
346
 
349
347
  def get_latest_firmware(
350
- host: str, username: str, password: str, firmware_directory: str
348
+ host: str,
349
+ port: int,
350
+ schema: str,
351
+ username: str,
352
+ password: str,
353
+ firmware_directory: str,
351
354
  ) -> Tuple[bool, Union[Dict[str, Any], str]]:
352
355
  """Get latest firmware for device.
353
356
 
@@ -355,7 +358,7 @@ def get_latest_firmware(
355
358
  (True, {**get_version(), path: str, new_sw: str})
356
359
  (False, str) - str is an error message
357
360
  """
358
- version_info = get_version(host, username=username, password=password)
361
+ version_info = get_version(host, port, schema, username=username, password=password)
359
362
  if version_info:
360
363
  latest_version = check_for_latest_firmware(version_info.get("fw_url"))
361
364
  if latest_version[0]:
@@ -398,9 +401,10 @@ def download_firmware(download_url: str, save_location: str) -> bool:
398
401
  def run_flash(
399
402
  firmware_path: str,
400
403
  host: str,
401
- username: str,
402
- password: str,
403
404
  port: int = 80,
405
+ schema: str = "http",
406
+ username: str = "",
407
+ password: str = "",
404
408
  callback_progress: Union[Callable[[int, int, float, str], None], None] = None,
405
409
  callback_cancel: Union[Callable[[], bool], None] = None,
406
410
  ) -> bool:
@@ -409,9 +413,10 @@ def run_flash(
409
413
  return flasher.run(
410
414
  firmware_path,
411
415
  host,
416
+ port,
417
+ schema,
412
418
  username,
413
419
  password,
414
- port,
415
420
  callback_progress,
416
421
  callback_cancel,
417
422
  )
@@ -1630,7 +1630,7 @@ def _get_version_initial(
1630
1630
  exc: Exception, schema: str, port: int, silent: bool
1631
1631
  ) -> Tuple[str, str, int]:
1632
1632
  """Handle first response in get_version - prepare data for second request."""
1633
- schema, path = "http", ""
1633
+ path = ""
1634
1634
  try:
1635
1635
  raise exc
1636
1636
  except TinyToolsRequestNotFound:
@@ -1658,6 +1658,7 @@ def _get_version_initial(
1658
1658
  def get_version(
1659
1659
  host: str,
1660
1660
  port: int = 80,
1661
+ schema: str = "http",
1661
1662
  username: str = "",
1662
1663
  password: str = "",
1663
1664
  with_info: bool = True,
@@ -1666,15 +1667,14 @@ def get_version(
1666
1667
  ) -> Union[Dict[str, Any], None]:
1667
1668
  """Query device for version and optionally device model.
1668
1669
 
1669
- NOTE: Might not work properly with https and port different than 443,
1670
- eg. proxy, as LK always uses 443 for https.
1671
- TODO: Might add schema parameter so it would work to handle proxy.
1670
+ To work with https on port different than 443, schema has to be set to https.
1671
+ Normally LK always uses port 443 for https.
1672
1672
  """
1673
1673
  response = None
1674
1674
  try:
1675
- response = get(host, "/st2.xml", "http", port, username, password)
1675
+ response = get(host, "/st2.xml", schema, port, username, password)
1676
1676
  except TinyToolsRequestError as exc:
1677
- path, schema, port = _get_version_initial(exc, "http", port, silent)
1677
+ path, schema, port = _get_version_initial(exc, schema, port, silent)
1678
1678
  if path:
1679
1679
  response = get(host, path, schema, port, username, password, silent=silent)
1680
1680
  return _get_version(
@@ -1685,6 +1685,7 @@ def get_version(
1685
1685
  async def async_get_version(
1686
1686
  host: str,
1687
1687
  port: int = 80,
1688
+ schema: str = "http",
1688
1689
  username: str = "",
1689
1690
  password: str = "",
1690
1691
  with_info: bool = True,
@@ -1695,10 +1696,10 @@ async def async_get_version(
1695
1696
  response = None
1696
1697
  try:
1697
1698
  response = await async_get(
1698
- host, "/st2.xml", "http", port, username, password, session=session
1699
+ host, "/st2.xml", schema, port, username, password, session=session
1699
1700
  )
1700
1701
  except TinyToolsRequestError as exc:
1701
- path, schema, port = _get_version_initial(exc, "http", port, silent)
1702
+ path, schema, port = _get_version_initial(exc, schema, port, silent)
1702
1703
  if path:
1703
1704
  response = await async_get(
1704
1705
  host,
@@ -1,12 +1,12 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: tinytoolslib
3
- Version: 0.3.4
3
+ Version: 0.4.0
4
4
  Summary: Set of tools for use with Tinycontrol devices like LK2.X, LK3.X, LK4.X or tcPDU.
5
5
  Author-email: Bartek Barszczewski <tinycontrol.software@gmail.com>
6
+ License-Expression: Apache-2.0
6
7
  Keywords: tinycontrol,lk,tcpdu
7
8
  Classifier: Programming Language :: Python :: 3
8
9
  Classifier: Operating System :: OS Independent
9
- Classifier: License :: OSI Approved :: Apache Software License
10
10
  Requires-Python: >=3.7
11
11
  Description-Content-Type: text/markdown
12
12
  Requires-Dist: aiohttp<4,>=3.9.3
@@ -1,4 +1,5 @@
1
1
  dist
2
2
  docs
3
+ fws
3
4
  public
4
5
  tinytoolslib
@@ -1 +0,0 @@
1
- __version__ = '0.3.4'
File without changes
File without changes