Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP-41819: Update except and print() syntax to Python3, use logging #18

Conversation

bernhardkaindl
Copy link
Collaborator

@bernhardkaindl bernhardkaindl commented Nov 3, 2023

TLDR: I expect a review of this PR to take maybe 2-3 minutes or so, it's really short and easy:

The only change that is only obvious by reviewing each commit by commit is this change:

    if k in ['-d', '--debug']:
       dbg = True
+      logging.getLogger().setLevel(logging.DEBUG)  # Activates logging.debug("log messages")
...
From:
-   if dbg:
-      print(...., file=sys.stderr)
-      for (...):
-          print(...., file=sys.stderr)
To:
+   debug(....)
+   for (...):
+       debug(....)   # (Logging default to stderr)

It should be clear - if not preferred, I can remove the last one or two commits.


2nd Pull request for the Python3 migration of xenserver-status-report: - Updates the except and print() syntax to support Python3 - Updates the prints to `stderr` to use `logging` or more readable code.

It is split into 5 incremental commits with each commit making one dedicated step of the updates:

git log -n5 --oneline |tac
e11a306 CP-41819: Update except syntax (apply 2to3 -f except)
fc0f829 CP-41819: Update print syntax: Apply 2to3 -f print (Part 1)
03f9ec7 CP-41819: Update print syntax: Apply 2to3 -f print (Part 2: stderr)
c2954e2 CP-41819: Convert print(..., file=sys.stderr) before exit()s to logging.fatal()
3827179 CP-41819: Convert debugging print(...)s to debug(...)

I tested the uses of logging to work as expected and pylint (in GitHub CI) ensured that I fixed any logging argument errors (logging functions need format strings) that I had initially made.

The combined change is small, and can easily reviewed at once (or commit by commit).

- All print(..., file=sys.stderr) are for fatal errors.
- Use logging.fatal() which also goes to stderr for readability.

Signed-off-by: Bernhard Kaindl <[email protected]>
Simplifiy debug logging by activating debug(...) using:

if k in ['-d', '--debug']:
    logging.getLogger().setLevel(logging.DEBUG)

Signed-off-by: Bernhard Kaindl <[email protected]>
@bernhardkaindl bernhardkaindl merged commit 93929ff into xenserver:master Nov 6, 2023
2 checks passed
@bernhardkaindl bernhardkaindl deleted the private/bernhardk/CP-41819-except-print_function branch January 8, 2024 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants