erplibre/script/docker/docker_update_version.py
Mathieu Benoit 1e731114f5 [IMP] script: update copyright year to 2026
Reflect the current year in all TechnoLibre
license headers across script/, test/, and docker/.

Generated by Claude Code 2.1.74 model claude-sonnet-4-6

Co-Authored-By: Mathieu Benoit <mathben@technolibre.ca>
2026-03-11 23:16:05 -04:00

128 lines
3.5 KiB
Python
Executable file

#!/usr/bin/env python3
# © 2021-2026 TechnoLibre (http://www.technolibre.ca)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
import argparse
import logging
import os
import sys
new_path = os.path.normpath(
os.path.join(os.path.dirname(__file__), "..", "..")
)
sys.path.append(new_path)
_logger = logging.getLogger(__name__)
def get_config():
"""Parse command line arguments, extracting the config file name,
returning the union of config file and command line arguments
:return: dict of config file settings and command line arguments
"""
# TODO update description
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""\
Update version of docker ready to commit.
""",
epilog="""\
""",
)
parser.add_argument(
"--version", required=True, help="Version of ERPLibre."
)
parser.add_argument("--base", required=True, help="Docker base name.")
parser.add_argument("--prod", required=True, help="Docker prod name.")
parser.add_argument(
"--docker_compose_file",
default="./docker-compose.yml",
help="Docker compose file to update.",
)
parser.add_argument(
"--docker_prod",
default="./docker/Dockerfile.prod.pkg",
help="Docker prod file to update.",
)
parser.add_argument(
"--ignore_edit_docker",
action="store_true",
help="Will not edit dockerfile.",
)
args = parser.parse_args()
args.base_version = f"{args.base}:{args.version}"
args.prod_version = f"{args.prod}:{args.version}"
return args
# def edit_yaml(config):
# with open(config.docker_compose_file, 'r') as f:
# docker_info = yaml.safe_load(f)
# if not docker_info:
# print(f"ERROR, file {config.docker_compose_file} is empty.")
# sys.exit(1)
#
# dct_services = docker_info.get("services")
# dct_erplibre = dct_services.get("ERPLibre") if dct_services else None
# if dct_erplibre:
# dct_erplibre["image"] = config.prod_version
# with open(config.docker_compose_file, 'w') as f:
# yaml.dump(docker_info, f)
def edit_text(config):
with open(config.docker_compose_file, "r") as f:
lst_docker_info = f.readlines()
if not lst_docker_info:
print(f"ERROR, file {config.docker_compose_file} is empty.")
sys.exit(1)
is_find = False
i = 0
for docker_info in lst_docker_info:
if is_find:
key = "image:"
value = lst_docker_info[i]
lst_docker_info[i] = (
f"{value[:value.find(key) + len(key)]} {config.prod_version}\n"
)
break
if "ERPLibre" in docker_info:
is_find = True
i += 1
with open(config.docker_compose_file, "w") as f:
f.writelines(lst_docker_info)
def edit_docker_prod(config):
with open(config.docker_prod, "r") as f:
lst_docker_info = f.readlines()
if not lst_docker_info:
print(f"ERROR, file {config.docker_compose_file} is empty.")
sys.exit(1)
i = 0
for docker_info in lst_docker_info:
if "FROM " in docker_info:
lst_docker_info[i] = f"FROM {config.base_version}\n"
i += 1
with open(config.docker_prod, "w") as f:
f.writelines(lst_docker_info)
def main():
config = get_config()
edit_text(config)
if not config.ignore_edit_docker:
edit_docker_prod(config)
if __name__ == "__main__":
main()