/
ilya.petrash
/
SimplePyScripts
Обзор
Документация
Войти
/
ilya.petrash
/
SimplePyScripts
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
job_compassplus/tx_parse_xml/get_layer_version.py
46 строк
998 B
gil9red
Bugfix
15 фев 2024, 11:03
15 фев 2024, 11:03
c02f43a
Код
Авторство
О чём код?
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = "ipetrash" import re from pathlib import Path def get_layer_version(path: Path) -> str: path = path.resolve() if not path.is_dir(): raise Exception(f"Path {str(path)!r} must be directory") path = path / "layer.xml" if not path.exists(): raise Exception(f"Path {str(path)!r} is not exists!") m = re.search(r'\bReleaseNumber="(.+?)"', path.read_text("utf-8")) if not m: raise Exception(f'Not found "ReleaseNumber" in path {str(path)!r}!') return m.group(1) def process(path: Path): print(get_layer_version(path)) if __name__ == "__main__": import argparse parser = argparse.ArgumentParser( description="Print a layer version" ) parser.add_argument( "path", metavar="/PATH/TO/LAYER", type=Path, help="Path to layer (the directory containing layer.xml)", ) args = parser.parse_args() process(args.path)