Skip to content

Commit

Permalink
refactor: apply black formatting to python files
Browse files Browse the repository at this point in the history
ran the cmd: `black swupdateclient`
  • Loading branch information
janfeemers committed Sep 8, 2023
1 parent ec4fb46 commit ed6a534
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
14 changes: 7 additions & 7 deletions tools/python/swupdateclient/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from setuptools import setup, find_packages

setup(
name='swupdateclient',
version='0.1',
name="swupdateclient",
version="0.1",
packages=find_packages(),
url='https://github.com/sbabic/swupdate/tree/master/tools/python/swupdateclient',
license='GPL-2.0-only',
author='Stefano Babic',
author_email='[email protected]',
description='Python Client to update SWUpdate based devices',
url="https://github.com/sbabic/swupdate/tree/master/tools/python/swupdateclient",
license="GPL-2.0-only",
author="Stefano Babic",
author_email="[email protected]",
description="Python Client to update SWUpdate based devices",
entry_points={
"console_scripts": [
"swupdateclient=swupdateclient.main:main",
Expand Down
54 changes: 36 additions & 18 deletions tools/python/swupdateclient/swupdateclient/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ class ColorFormatter(logging.Formatter):
}

def format(self, record):
return logging.Formatter(colored(
"%(levelname)s:%(name)s:%(message)s",
self.COLORS[record.levelno],
attrs=self.ATTRIBUTES[record.levelno])
return logging.Formatter(
colored(
"%(levelname)s:%(name)s:%(message)s",
self.COLORS[record.levelno],
attrs=self.ATTRIBUTES[record.levelno],
)
).format(record)


Expand All @@ -59,7 +61,15 @@ class SWUpdater:
url_upload = "http://{}:{}{}/upload"
url_status = "ws://{}:{}{}/ws"

def __init__(self, path_image, host_name, port=8080, route="", logger=None, log_level=logging.DEBUG):
def __init__(
self,
path_image,
host_name,
port=8080,
route="",
logger=None,
log_level=logging.DEBUG,
):
self._image = path_image
self._host_name = host_name
self._port = port
Expand Down Expand Up @@ -99,9 +109,7 @@ async def wait_update_finished(self):
if data["type"] != "message":
continue

self._logger.log(
LOGGING_MAPPING[data["level"]],
data["text"])
self._logger.log(LOGGING_MAPPING[data["level"]], data["text"])

if "SWUPDATE successful" in data["text"]:
return True
Expand Down Expand Up @@ -130,8 +138,8 @@ async def upload(self, timeout):

if response.status_code != 200:
self._logger.error(
"Cannot upload software image: %s",
response.status_code)
"Cannot upload software image: %s", response.status_code
)
return False

self._logger.info(
Expand Down Expand Up @@ -168,7 +176,7 @@ def update(self, timeout=300):
return asyncio.run(self.start_tasks(timeout))


def client (args: List[str]) -> None:
def client(args: List[str]) -> None:
parser = argparse.ArgumentParser()
parser.add_argument("swu_file", help="Path to swu image")
parser.add_argument("host_name", help="Host name")
Expand All @@ -178,7 +186,7 @@ def client (args: List[str]) -> None:
help="Name of the API route (e.g. /ROUTE)",
type=str,
default="",
nargs="?"
nargs="?",
)
parser.add_argument(
"--timeout",
Expand All @@ -188,13 +196,20 @@ def client (args: List[str]) -> None:
nargs="?",
)
parser.add_argument(
"--log-level", help="change log level (error, info, warning, debug)",
type=str, metavar="[LEVEL]",
choices=["error", "info", "warning", "debug"], default="debug"
"--log-level",
help="change log level (error, info, warning, debug)",
type=str,
metavar="[LEVEL]",
choices=["error", "info", "warning", "debug"],
default="debug",
)
parser.add_argument(
"--color", help="colorize messages (auto, always or never)", type=str,
metavar="[WHEN]", choices=["auto", "always", "never"], default="auto"
"--color",
help="colorize messages (auto, always or never)",
type=str,
metavar="[WHEN]",
choices=["auto", "always", "never"],
default="auto",
)

args = parser.parse_args()
Expand All @@ -210,11 +225,14 @@ def client (args: List[str]) -> None:
args.host_name,
args.port,
args.route,
log_level=args.log_level.upper())
log_level=args.log_level.upper(),
)
updater.update(timeout=args.timeout)


def main():
client(sys.argv[1:])


if __name__ == "__main__":
main()

0 comments on commit ed6a534

Please sign in to comment.