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
|
import logging
from pathlib import Path
from typing import Dict, Any
import pytoml as toml
_LOGGER = logging.getLogger(__name__)
CONF_NAME = "sdk_packaging.toml"
_SECTION = "packaging"
# Default conf
_CONFIG = {
"package_name": "packagename",
"package_nspkg": "packagenspkg",
"package_pprint_name": "MyService Management",
"package_doc_id": "",
"is_stable": False,
"is_arm": True,
"need_msrestazure": True
}
def read_conf(folder: Path) -> Dict[str, Any]:
conf_path = folder / CONF_NAME
if not conf_path.exists():
return {}
with open(conf_path, "rb") as fd:
return toml.load(fd)[_SECTION]
def build_default_conf(folder: Path, package_name: str) -> None:
conf_path = folder / CONF_NAME
if conf_path.exists():
_LOGGER.info("Skipping default conf since the file exists")
return
_LOGGER.info("Build default conf for %s", package_name)
conf = {_SECTION: _CONFIG.copy()}
conf[_SECTION]["package_name"] = package_name
conf[_SECTION]["package_nspkg"] = package_name[:package_name.rindex('-')]+"-nspkg"
with open(conf_path, "w") as fd:
toml.dump(conf, fd)
|