mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-22 21:25:43 -05:00
devices/device: extract sanitize_device_name() into own function
This commit is contained in:
parent
bfce7c466d
commit
7425356f10
1 changed files with 15 additions and 8 deletions
|
@ -135,6 +135,20 @@ def parse_device_pkg(pkgbuild: Pkgbuild) -> Device:
|
||||||
return Device(name=name, arch=arch, package=pkgbuild, deviceinfo=None)
|
return Device(name=name, arch=arch, package=pkgbuild, deviceinfo=None)
|
||||||
|
|
||||||
|
|
||||||
|
def sanitize_device_name(name: str, warn: bool = True) -> str:
|
||||||
|
if name not in DEVICE_DEPRECATIONS:
|
||||||
|
return name
|
||||||
|
warning = f"Deprecated device {name}"
|
||||||
|
replacement = DEVICE_DEPRECATIONS[name]
|
||||||
|
if replacement:
|
||||||
|
warning += (f': Device has been renamed to {replacement}! Please adjust your profile config!\n'
|
||||||
|
'This will become an error in a future version!')
|
||||||
|
name = replacement
|
||||||
|
if warn:
|
||||||
|
logging.warning(warning)
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
_device_cache: dict[str, Device] = {}
|
_device_cache: dict[str, Device] = {}
|
||||||
_device_cache_populated: bool = False
|
_device_cache_populated: bool = False
|
||||||
|
|
||||||
|
@ -159,14 +173,7 @@ def get_devices(pkgbuilds: Optional[dict[str, Pkgbuild]] = None, lazy: bool = Tr
|
||||||
def get_device(name: str, pkgbuilds: Optional[dict[str, Pkgbuild]] = None, lazy: bool = True, scan_all=False) -> Device:
|
def get_device(name: str, pkgbuilds: Optional[dict[str, Pkgbuild]] = None, lazy: bool = True, scan_all=False) -> Device:
|
||||||
global _device_cache, _device_cache_populated
|
global _device_cache, _device_cache_populated
|
||||||
assert lazy or pkgbuilds
|
assert lazy or pkgbuilds
|
||||||
if name in DEVICE_DEPRECATIONS:
|
name = sanitize_device_name(name)
|
||||||
warning = f"Deprecated device {name}"
|
|
||||||
replacement = DEVICE_DEPRECATIONS[name]
|
|
||||||
if replacement:
|
|
||||||
warning += (f': Device has been renamed to {replacement}! Please adjust your profile config!\n'
|
|
||||||
'This will become an error in a future version!')
|
|
||||||
name = replacement
|
|
||||||
logging.warning(warning)
|
|
||||||
if lazy and name in _device_cache:
|
if lazy and name in _device_cache:
|
||||||
return _device_cache[name]
|
return _device_cache[name]
|
||||||
if scan_all:
|
if scan_all:
|
||||||
|
|
Loading…
Add table
Reference in a new issue