-
Notifications
You must be signed in to change notification settings - Fork 969
/
versions.py
60 lines (47 loc) · 1.8 KB
/
versions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Mobile Verification Toolkit (MVT)
# Copyright (c) 2021-2023 The MVT Authors.
# Use of this software is governed by the MVT License 1.1 that can be found at
# https://license.mvt.re/1.1/
import json
import pkgutil
from logging import Logger
from typing import Dict, Optional
import packaging
IPHONE_MODELS = json.loads(pkgutil.get_data("mvt", "ios/data/ios_models.json"))
IPHONE_IOS_VERSIONS = json.loads(pkgutil.get_data("mvt", "ios/data/ios_versions.json"))
def get_device_desc_from_id(identifier: str, devices_list: list = IPHONE_MODELS) -> str:
for model in devices_list:
if identifier == model["identifier"]:
return model["description"]
return ""
def find_version_by_build(build: str) -> str:
build = build.upper()
for version in IPHONE_IOS_VERSIONS:
if build == version["build"]:
return version["version"]
return ""
def latest_ios_version() -> Dict[str, str]:
return IPHONE_IOS_VERSIONS[-1]
def is_ios_version_outdated(version: str, log: Optional[Logger] = None) -> bool:
"""
Check if the given version is below the latest version
version can be a build number or version number
Returns true if outdated for sure, false otherwise
"""
# Check if it is a build
if "." not in version:
version = find_version_by_build(version)
# If we can't find it
if version == "":
return False
latest_parsed = packaging.version.parse(latest_ios_version()["version"])
current_parsed = packaging.version.parse(version)
if current_parsed < latest_parsed:
if log:
log.warning(
"This phone is running an outdated iOS version: %s (latest is %s)",
version,
latest_ios_version()["version"],
)
return True
return False