Skip to content

medcat.utils.check_for_updates

Classes:

Functions:

Attributes:

DEFAULT_CACHE_PATH module-attribute

DEFAULT_CACHE_PATH = home() / '.cache' / 'cogstack' / 'medcat_version.json'

DEFAULT_CHECK_INTERVAL module-attribute

DEFAULT_CHECK_INTERVAL = 7 * 24 * 3600

logger module-attribute

logger = getLogger(__name__)

UpdateCheckConfig

Bases: TypedDict

Attributes:

cache_path instance-attribute

cache_path: Path

check_interval instance-attribute

check_interval: int

enabled instance-attribute

enabled: bool

minor_threshold instance-attribute

minor_threshold: int

patch_threshold instance-attribute

patch_threshold: int

pkg_name instance-attribute

pkg_name: str

timeout instance-attribute

timeout: float

url instance-attribute

url: str

check_for_updates

check_for_updates(pkg_name: str, current_version: str)
Source code in medcat-v2/medcat/utils/check_for_updates.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def check_for_updates(pkg_name: str, current_version: str):
    cnf = _get_config(pkg_name)
    if not cnf["enabled"]:
        return

    if not _should_check(cnf["cache_path"], cnf["check_interval"]):
        return

    try:
        with urllib.request.urlopen(cnf["url"],
                                    timeout=cnf["timeout"]) as r:
            data = json.load(r)
        releases = {
            v: files for v, files in data.get("releases", {}).items()
            if files  # skip empty entries
        }
    except Exception as e:
        log_info("Unable to check for update", exc_info=e)
        return

    # cache update time
    cnf["cache_path"].parent.mkdir(parents=True, exist_ok=True)
    with open(cnf["cache_path"], "w") as f:
        json.dump({"last_check": time.time()}, f)

    _do_check(cnf, releases, current_version)

log_info

log_info(msg: str, *args, yanked: bool = False, **kwargs)
Source code in medcat-v2/medcat/utils/check_for_updates.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def log_info(msg: str, *args, yanked: bool = False, **kwargs):
    if yanked:
        lvl = os.environ.get(MEDCAT_VERSION_UPDATE_YANKED_LOG_LEVEL_ENVIRON,
                             DEFAULT_VERSION_INFO_YANKED_LEVEL).upper()
    else:
        lvl = os.environ.get(MEDCAT_VERSION_UPDATE_LOG_LEVEL_ENVIRON,
                             DEFAULT_VERSION_INFO_LEVEL).upper()
    _level_map = {
        "NOTSET": logging.NOTSET,
        "DEBUG": logging.DEBUG,
        "INFO": logging.INFO,
        "WARN": logging.WARNING,
        "WARNING": logging.WARNING,
        "ERROR": logging.ERROR,
        "CRITICAL": logging.CRITICAL,
        "FATAL": logging.FATAL,
    }
    level = _level_map.get(lvl, logging.INFO)
    logger.log(level, msg, *args, **kwargs)