Modification du versionnage auto
This commit is contained in:
@@ -1,51 +1,135 @@
|
||||
import sys
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from datetime import date
|
||||
|
||||
# =========================================================
|
||||
# CONFIG
|
||||
# =========================================================
|
||||
|
||||
VBS_SCRIPT = Path(__file__).parent / "set_cell_silent.vbs"
|
||||
|
||||
# =========================================================
|
||||
# PREFIXE VERSION
|
||||
# =========================================================
|
||||
|
||||
def detecter_major(path: Path) -> int:
|
||||
|
||||
nom = path.name.lower()
|
||||
|
||||
if "restauration" in nom:
|
||||
return 2
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
# =========================================================
|
||||
# LECTURE VERSION
|
||||
# =========================================================
|
||||
|
||||
def lire_version(path: Path, major: int):
|
||||
|
||||
def lire_version(path: Path):
|
||||
if not path.exists():
|
||||
return [1, 0, 0]
|
||||
return [major, 0, 0]
|
||||
|
||||
contenu = path.read_text(encoding="utf-8").strip().splitlines()
|
||||
|
||||
if not contenu:
|
||||
return [1, 0, 0]
|
||||
return [major, 0, 0]
|
||||
|
||||
version_str = contenu[0].strip()
|
||||
try:
|
||||
parts = [int(x) for x in version_str.split(".")]
|
||||
while len(parts) < 3:
|
||||
parts.append(0)
|
||||
return parts[:3]
|
||||
except ValueError:
|
||||
return [1, 0, 0]
|
||||
version = [int(x) for x in contenu[0].split(".")]
|
||||
|
||||
while len(version) < 3:
|
||||
version.append(0)
|
||||
|
||||
version = version[:3]
|
||||
|
||||
# force le major correct
|
||||
version[0] = major
|
||||
|
||||
return version
|
||||
|
||||
except Exception:
|
||||
return [major, 0, 0]
|
||||
|
||||
|
||||
def ecrire_version(path: Path, version):
|
||||
version_str = ".".join(str(x) for x in version)
|
||||
today = date.today().isoformat()
|
||||
texte = f"{version_str}\n{today}\n"
|
||||
path.write_text(texte, encoding="utf-8")
|
||||
return version_str
|
||||
|
||||
# =========================================================
|
||||
# INCREMENT
|
||||
# =========================================================
|
||||
|
||||
def increment_patch(version):
|
||||
version[2] += 1
|
||||
return version
|
||||
|
||||
|
||||
# =========================================================
|
||||
# ECRITURE TXT
|
||||
# =========================================================
|
||||
|
||||
def ecrire_version_txt(path: Path, version):
|
||||
|
||||
version_str = ".".join(str(x) for x in version)
|
||||
|
||||
contenu = f"{version_str}\n{date.today().isoformat()}\n"
|
||||
|
||||
path.write_text(contenu, encoding="utf-8")
|
||||
|
||||
return version_str
|
||||
|
||||
|
||||
# =========================================================
|
||||
# ECRITURE EXCEL
|
||||
# =========================================================
|
||||
|
||||
def ecrire_version_excel(classeur: Path, version_str: str):
|
||||
|
||||
if not classeur.exists():
|
||||
print(f"Classeur introuvable : {classeur}")
|
||||
return
|
||||
|
||||
valeur = f"Version : {version_str}"
|
||||
|
||||
cmd = [
|
||||
"cscript",
|
||||
"//nologo",
|
||||
str(VBS_SCRIPT),
|
||||
str(classeur),
|
||||
"Tableau de bord",
|
||||
"C1",
|
||||
valeur
|
||||
]
|
||||
|
||||
subprocess.run(cmd, check=True)
|
||||
|
||||
|
||||
# =========================================================
|
||||
# MAIN
|
||||
# =========================================================
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage : python maj_version.py chemin_du_VERSION.txt")
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print("Usage :")
|
||||
print("python maj_version.py VERSION.txt classeur.xlsm")
|
||||
sys.exit(1)
|
||||
|
||||
version_file = Path(sys.argv[1])
|
||||
version = lire_version(version_file)
|
||||
classeur = Path(sys.argv[2])
|
||||
|
||||
major = detecter_major(version_file)
|
||||
|
||||
version = lire_version(version_file, major)
|
||||
|
||||
version = increment_patch(version)
|
||||
new_version_str = ecrire_version(version_file, version)
|
||||
print(f"Nouvelle version : {new_version_str}")
|
||||
|
||||
version_str = ecrire_version_txt(version_file, version)
|
||||
|
||||
ecrire_version_excel(classeur, version_str)
|
||||
|
||||
print(f"Nouvelle version : {version_str}")
|
||||
print(f"Classeur mis à jour : {classeur.name}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user