From: Jan Fajerski Date: Thu, 6 Aug 2020 13:51:58 +0000 (+0200) Subject: pybind/mgr/snap_schedule: add type hint for mypy, fix import X-Git-Tag: v16.1.0~1299^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=39cf0d9e734fb24eacc7039990b78ed2d87d0c35;p=ceph.git pybind/mgr/snap_schedule: add type hint for mypy, fix import Signed-off-by: Jan Fajerski --- diff --git a/src/pybind/mgr/snap_schedule/__init__.py b/src/pybind/mgr/snap_schedule/__init__.py index f2d056fedeb56..34b7ffbb037e7 100644 --- a/src/pybind/mgr/snap_schedule/__init__.py +++ b/src/pybind/mgr/snap_schedule/__init__.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -import os +from os import environ -if 'UNITTEST' in os.environ: +if 'UNITTEST' in environ: import tests from .module import Module diff --git a/src/pybind/mgr/snap_schedule/fs/schedule.py b/src/pybind/mgr/snap_schedule/fs/schedule.py index c919316af24fd..59fec351a6550 100644 --- a/src/pybind/mgr/snap_schedule/fs/schedule.py +++ b/src/pybind/mgr/snap_schedule/fs/schedule.py @@ -8,6 +8,7 @@ import json import logging import re import sqlite3 +from typing import Tuple, Any log = logging.getLogger(__name__) @@ -24,8 +25,10 @@ def parse_retention(retention): log.debug(f'parse_retention({retention}) -> {ret}') return ret + RETENTION_MULTIPLIERS = ['n', 'M', 'h', 'd', 'w', 'm', 'y'] + def dump_retention(retention): ret = '' for mult in RETENTION_MULTIPLIERS: @@ -33,6 +36,7 @@ def dump_retention(retention): ret += str(retention[mult]) + mult return ret + class Schedule(object): ''' Wrapper to work with schedules stored in sqlite @@ -161,7 +165,7 @@ class Schedule(object): @classmethod def get_db_schedules(cls, path, db, fs, repeat=None, start=None): query = cls.GET_SCHEDULES - data = (path,) + data: Tuple[Any, ...] = (path,) if repeat: query += ' AND sm.repeat = ?' data += (repeat,) diff --git a/src/pybind/mgr/snap_schedule/tests/conftest.py b/src/pybind/mgr/snap_schedule/tests/conftest.py index 727d723f3dd90..35255b8d486b0 100644 --- a/src/pybind/mgr/snap_schedule/tests/conftest.py +++ b/src/pybind/mgr/snap_schedule/tests/conftest.py @@ -1,6 +1,6 @@ import pytest import sqlite3 -from fs.schedule import Schedule +from ..fs.schedule import Schedule # simple_schedule fixture returns schedules without any timing arguments