Skip to content

Commit

Permalink
chore: replace strtobool by custom impl
Browse files Browse the repository at this point in the history
  • Loading branch information
psegedy authored and jdobes committed Jan 15, 2024
1 parent 3eb7776 commit 0cb451e
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion vmaas/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
Common VMaaS configuration.
"""
import os
from distutils.util import strtobool

import app_common_python

from vmaas.common.strtobool import strtobool


class Singleton(type):
"""Singleton object."""
Expand Down
2 changes: 1 addition & 1 deletion vmaas/common/logging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import logging
import os
import time
from distutils.util import strtobool # pylint: disable=import-error, no-name-in-module
from threading import Lock

import watchtower
from boto3 import client
from botocore.exceptions import ClientError

from vmaas.common.config import Config
from vmaas.common.strtobool import strtobool


class OneLineExceptionFormatter(logging.Formatter):
Expand Down
21 changes: 21 additions & 0 deletions vmaas/common/strtobool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Module providing `strtobool` function as replacement of distutils.strtobool."""


def strtobool(val: str) -> bool:
"""Convert a string representation of truth to bool.
True values are y, yes, t, true, on and 1; false values are n, no, f, false, off and 0.
Raises TypeError if `val` is not string.
Raises ValueError if `val` is anything else.
"""
if not isinstance(val, str):
raise TypeError(f"`{val}` is not of type str")
trues = ("y", "yes", "t", "true", "on", "1")
falses = ("n", "no", "f", "false", "off", "0")

val = val.lower()
if val in trues:
return True
if val in falses:
return False
raise ValueError(f"`{val}` not in {trues + falses}")
2 changes: 1 addition & 1 deletion vmaas/reposcan/redhatcsaf/csaf_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import os
import shutil
import tempfile
from distutils.util import strtobool
from pathlib import Path

from vmaas.common.batch_list import BatchList
from vmaas.common.logging_utils import get_logger
from vmaas.common.strtobool import strtobool
from vmaas.reposcan.database.csaf_store import CsafStore
from vmaas.reposcan.download.downloader import DownloadItem
from vmaas.reposcan.download.downloader import FileDownloader
Expand Down
2 changes: 1 addition & 1 deletion vmaas/reposcan/redhatoval/oval_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import tempfile
import json
import re
from distutils.util import strtobool

from vmaas.common.batch_list import BatchList
from vmaas.common.logging_utils import get_logger
from vmaas.common.date_utils import parse_datetime
from vmaas.common.strtobool import strtobool

from vmaas.reposcan.database.oval_store import OvalStore
from vmaas.reposcan.download.downloader import FileDownloader, DownloadItem, VALID_HTTP_CODES
Expand Down
2 changes: 1 addition & 1 deletion vmaas/reposcan/repodata/updateinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# pylint: disable=too-many-nested-blocks, too-many-branches
# I really don't want to do that but, the way how updateinfo XML is done it's unfortuntately needed
from datetime import datetime
from distutils.util import strtobool
import re
import xml.etree.ElementTree as eT

from vmaas.common.string import text_strip
from vmaas.common.utc import UTC
from vmaas.common.strtobool import strtobool

DATETIME_PATTERNS = {
"%Y-%m-%d %H:%M:%S": re.compile(r"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$"),
Expand Down
2 changes: 1 addition & 1 deletion vmaas/reposcan/reposcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from contextlib import contextmanager
from multiprocessing.pool import Pool
from functools import reduce
from distutils.util import strtobool

import connexion
import git
Expand All @@ -24,6 +23,7 @@

from vmaas.common.constants import VMAAS_VERSION
from vmaas.common.logging_utils import get_logger, init_logging
from vmaas.common.strtobool import strtobool
from vmaas.reposcan.database.database_handler import DatabaseHandler, init_db
from vmaas.reposcan.database.product_store import ProductStore
from vmaas.reposcan.dbchange import DbChangeAPI
Expand Down
2 changes: 1 addition & 1 deletion vmaas/webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import sre_constants
import ssl
import time
from distutils.util import strtobool
from json import loads

import connexion
Expand Down Expand Up @@ -38,6 +37,7 @@
from vmaas.common.config import Config
from vmaas.common.constants import VMAAS_VERSION
from vmaas.common.logging_utils import get_logger
from vmaas.common.strtobool import strtobool

# pylint: disable=too-many-lines
CFG = Config()
Expand Down

0 comments on commit 0cb451e

Please sign in to comment.