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

refactor: update barcalendar.py script #455

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions barcalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,34 @@

"""

import atexit
import colorsys
import datetime
import itertools
import logging
import re
import time

import atexit
import logging
import requests
import yaml


def setup_custom_logging():
"""
Creating a custom logger to flush all Warning logs at the end of the script
Create a custom logger to flush all Warning logs at the end of the script
to avoid breaking the console script being generated by the script
"""
class DelayedLogHandler(logging.Handler):
def __init__(self):
super().__init__()
self.log_messages = []
self.log_records = []

def emit(self, record):
self.log_messages.append(record)
self.log_records.append(f"// {record}")

def _flush_log_messages(handler):
for message in handler.log_messages:
print(message)
def _flush_log_records(handler):
for record in handler.log_records:
print(record)

# Create a custom log handler
custom_log_handler = DelayedLogHandler()
Expand All @@ -52,8 +53,8 @@ def _flush_log_messages(handler):
eol_logger = logging.getLogger("eol_logger")
eol_logger.addHandler(custom_log_handler)

# Register a function to flush log messages at exit
atexit.register(_flush_log_messages, custom_log_handler)
# Register a function to flush log records at exit
atexit.register(_flush_log_records, custom_log_handler)

# Return custom logger to use in the script
return eol_logger
Expand Down Expand Up @@ -97,7 +98,7 @@ def validate_version_date(project, version, year, month, check_start=False):
if (year, month) == (int(eol_year), int(eol_month)):
return (year, month)
else:
eol_logger.warning(f"Invalid EOL: Update {project} {version} {date_type} to {eol_year}/{eol_month} instead")
eol_logger.warning(f"Invalid EOL: Update {project} {version} {date_type} to {eol_month}/{eol_year} instead")
return (int(eol_year), int(eol_month))
except requests.exceptions.RequestException as e:
eol_logger.error(f"API request failed with an exception: {str(e)}")
Expand Down