Skip to content

Commit

Permalink
add base structure
Browse files Browse the repository at this point in the history
  • Loading branch information
not-a-feature committed Mar 2, 2024
1 parent 86a8107 commit c66430b
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 158 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exclude: '^docs/conf.py'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
Expand Down Expand Up @@ -36,12 +36,12 @@ repos:
# ]

- repo: https://github.com/PyCQA/isort
rev: 5.11.5
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: stable
rev: 24.2.0
hooks:
- id: black
language_version: python3
Expand All @@ -54,7 +54,7 @@ repos:
# additional_dependencies: [black]

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 7.0.0
hooks:
- id: flake8
## You can add flake8 plugins via `additional_dependencies`:
Expand Down
10 changes: 5 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[metadata]
name = wd_fw_update
description = Add a short description here!
description = Updates the firmware of Western Digital SSDs on Ubuntu / Linux Mint.
author = Jules Kreuer
author_email = [email protected]
license = GPL-3.0-or-later
Expand Down Expand Up @@ -68,9 +68,9 @@ testing =
pytest-cov

[options.entry_points]
# Add here console scripts like:
# console_scripts =
# script_name = wd_fw_update.module:function
console_scripts =
wd_fw_update = wd_fw_update.main:run

# For example:
# console_scripts =
# fibonacci = wd_fw_update.skeleton:run
Expand Down Expand Up @@ -105,7 +105,7 @@ formats = bdist_wheel

[flake8]
# Some sane defaults for the code style checker flake8
max_line_length = 88
max_line_length = 100
extend_ignore = E203, W503
# ^ Black-compatible
# E203 and W503 have edge cases handled by black
Expand Down
133 changes: 133 additions & 0 deletions src/wd_fw_update/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import argparse
import logging
import sys

from wd_fw_update import __version__

__author__ = "Jules Kreuer"
__copyright__ = "Jules Kreuer"
__license__ = "GPL-3.0-or-later"

_logger = logging.getLogger(__name__)


def parse_args(args):
"""Parse command line parameters
Args:
args (List[str]): command line parameters as list of strings
(for example ``["--help"]``).
Returns:
:obj:`argparse.Namespace`: command line parameters namespace
"""
parser = argparse.ArgumentParser(description="Just a Fibonacci demonstration")
parser.add_argument(
"--version",
action="version",
version=f"wd_fw_update {__version__}",
)
parser.add_argument(dest="n", help="n-th Fibonacci number", type=int, metavar="INT")
parser.add_argument(
"-v",
"--verbose",
dest="loglevel",
help="set loglevel to INFO",
action="store_const",
const=logging.INFO,
)
parser.add_argument(
"-vv",
"--very-verbose",
dest="loglevel",
help="set loglevel to DEBUG",
action="store_const",
const=logging.DEBUG,
)
return parser.parse_args(args)


def setup_logging(loglevel):
"""Setup basic logging
Args:
loglevel (int): minimum loglevel for emitting messages
"""
logformat = "[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
logging.basicConfig(
level=loglevel,
stream=sys.stdout,
format=logformat,
datefmt="[%Y-%m-%d %H:%M:%S]",
)


def check_dependencies():
return


def get_model():
return


def get_fw_url():
return


def download_fw():
return


def update_fw():
return


def wd_fw_update():
"""Updates the firmware of Western Digital SSDs on Ubuntu / Linux Mint."""

# Step 0: Check dependencies

# Step 1: Get model number and firmware version

# Step 2: Fetch the device list and find the firmware URL

# Step 3: Check firmware version dependencies

# Step 4: Download firmware file

# Step 5: Update the firmware


def main(args):
"""Wrapper allowing :func:`wd_fw_update` to be called with string arguments in a CLI fashion
Instead of returning the value from :func:`wd_fw_update`, it prints the result to the
``stdout`` in a nicely formatted message.
Args:
args (List[str]): command line parameters as list of strings
(for example ``["--verbose", "--help"]``).
"""
args = parse_args(args)
setup_logging(args.loglevel)
_logger.debug(args)

wd_fw_update()

_logger.info("[END of script]")


def run():
"""Calls :func:`main` passing the CLI arguments extracted from :obj:`sys.argv`
This function is used as entry point to create console scripts with setuptools.
"""
main(sys.argv[1:])


if __name__ == "__main__":
# ^ This is a guard statement that will prevent the following code from
# being executed in the case someone imports this file instead of
# executing it as a script.
# https://docs.python.org/3/library/__main__.html
run()
149 changes: 0 additions & 149 deletions src/wd_fw_update/skeleton.py

This file was deleted.

0 comments on commit c66430b

Please sign in to comment.