Skip to content
Open
Show file tree
Hide file tree
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
45 changes: 24 additions & 21 deletions cache_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import rss2irc
from lib import CachedData
from lib import utils

BUCKET_COUNT = 10

Expand Down Expand Up @@ -57,7 +58,9 @@ def calc_distribution(
def get_timestamp(data) -> int:
"""Convert input data to int.

:raises: KeyError, TypeError, ValueError
:raises KeyError: raised when expected key is not found in data
:raises TypeError: raised for unsupported data types
:raises ValueError: raised when conversion of value to int fails
"""
if isinstance(data, (int, float)):
return int(data)
Expand Down Expand Up @@ -85,11 +88,8 @@ def get_timestamp_minmax(
logger.debug("%s", traceback.format_exc())
continue

if timestamp < ts_min:
ts_min = timestamp

if timestamp > ts_max:
ts_max = timestamp
ts_min = min(ts_min, timestamp)
ts_max = max(ts_max, timestamp)

return ts_min, ts_max, error_cnt

Expand Down Expand Up @@ -119,15 +119,16 @@ def generate_buckets(

def main():
"""Read cache file and print-out stats."""
args = parse_args()
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
logger = logging.getLogger("cache_stats")
args = parse_args()
if args.verbosity:
logger.setLevel(logging.DEBUG)
logger.setLevel(args.log_level)

cache = rss2irc.read_cache(logger, args.cache)
cache = rss2irc.read_cache(logger, args.cache_file)
logger.info(
"Number of items in cache '%s' is %d.", args.cache, len(cache.items)
"Number of items in cache '%s' is %d.",
args.cache_file,
len(cache.items),
)
if not cache.items:
logger.info("Nothing to do.")
Expand Down Expand Up @@ -168,23 +169,25 @@ def main():
def parse_args() -> argparse.Namespace:
"""Return parsed CLI args."""
parser = argparse.ArgumentParser()
parser.add_argument(
"-v",
"--verbose",
dest="verbosity",
action="store_true",
default=False,
help="Increase logging verbosity.",
)
parser.add_argument(
"--cache",
dest="cache",
dest="cache_file",
type=str,
default=None,
required=True,
help="File which contains cache.",
)
return parser.parse_args()
parser.add_argument(
"-v",
"--verbose",
action="count",
default=0,
help="Increase log level verbosity. Can be passed multiple times.",
)
args = parser.parse_args()
args.log_level = utils.calc_log_level(args.verbose)

return args


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion ci/run-reorder-python-imports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -u
cd "$(dirname "${0}")/.."

find . ! -path '*/\.*' -name '*.py' -print0 | \
xargs -0 -- reorder-python-imports --py311-plus
xargs -0 -- reorder-python-imports --py313-plus
Loading