def update_sonar_properties(version: Tuple[str, str, str], dry_run: bool = False) -> Optional[str]: """ Updates the sonar-project.properties file with the new release number :param version: Release number tuple (major, minor, release) :param dry_run: If `True`, no operation performed :return: changed string """ assert RELEASE_CONFIG is not None if not RELEASE_CONFIG.has_section("sonar"): raise helpers.NothingToDoException("No `sonar` section in release.ini file") try: _path = RELEASE_CONFIG["sonar"].get("path") path = Path(_path) pattern = RELEASE_CONFIG["sonar"].get("pattern", "").strip('"') or helpers.SONAR_PATTERN template = RELEASE_CONFIG["sonar"].get("template", "").strip('"') or helpers.SONAR_TEMPLATE except configparser.Error as e: raise helpers.NothingToDoException("No action to perform for sonar file", e) return helpers.update_file(path=path, pattern=pattern, template=template, version=version, dry_run=dry_run)
def update_docs_conf(version: Tuple[str, str, str], dry_run: bool = False) -> Optional[str]: """ Updates the Sphinx conf.py file with the new release number :param version: Release number tuple (major, minor, release) :param dry_run: If `True`, no operation performed :return: changed string """ assert RELEASE_CONFIG is not None if not RELEASE_CONFIG.has_section("docs"): raise helpers.NothingToDoException("No `docs` section in release.ini file") try: _path = RELEASE_CONFIG["docs"].get("path") path = Path(_path) pattern_release = RELEASE_CONFIG["docs"].get("pattern_release", "").strip('"') or helpers.DOCS_RELEASE_PATTERN template_release = RELEASE_CONFIG["docs"].get("template_release", "").strip('"') or helpers.DOCS_RELEASE_FORMAT pattern_version = RELEASE_CONFIG["docs"].get("pattern_version", "").strip('"') or helpers.DOCS_VERSION_PATTERN template_version = RELEASE_CONFIG["docs"].get("template_version", "").strip('"') or helpers.DOCS_VERSION_FORMAT except configparser.Error as e: raise helpers.NothingToDoException("No action to perform for docs file", e) update_release = helpers.update_file( path=path, pattern=pattern_release, template=template_release, version=version, dry_run=dry_run, ) update_version = helpers.update_file( path=path, pattern=pattern_version, template=template_version, version=version, dry_run=dry_run, ) return str(update_release) + str(update_version)
def update_main_file(version: Tuple[str, str, str], dry_run: bool = True) -> Optional[str]: """ Updates the main django settings file, or a python script with a __init__.py file. :param version: Release number tuple (major, minor, release) :param dry_run: If `True`, no operation performed :return: changed string """ assert RELEASE_CONFIG is not None if not RELEASE_CONFIG.has_section("main_project"): raise helpers.NothingToDoException("No `main_project` section in release.ini file") try: _path = RELEASE_CONFIG["main_project"].get("path") if _path is None: raise helpers.NothingToDoException("No action to perform for main project: No path provided.") path = Path(_path) pattern = RELEASE_CONFIG["main_project"].get("pattern", "").strip('"') or helpers.MAIN_PROJECT_PATTERN template = RELEASE_CONFIG["main_project"].get("template", "").strip('"') or helpers.MAIN_PROJECT_TEMPLATE except configparser.Error as e: raise helpers.NothingToDoException("Unable to update main project file", e) return helpers.update_file(path=path, pattern=pattern, template=template, version=version, dry_run=dry_run)
def update_ansible_vars(version: Tuple[str, str, str], dry_run: bool = False) -> Optional[str]: """ Updates the ansible project variables file with the new release number :param version: Release number tuple (major, minor, release) :param dry_run: If `True`, no operation performed :return: changed string """ assert RELEASE_CONFIG is not None try: path = Path(RELEASE_CONFIG.get("ansible", "path")) key = RELEASE_CONFIG.get("ansible", "key", fallback=helpers.ANSIBLE_KEY) # noqa except configparser.Error as e: raise helpers.NothingToDoException("No action to perform for ansible file", e) return helpers.updates_yaml_file(path=path, version=version, key=key, dry_run=dry_run)