# -*- coding: utf-8 -*-
from setuphelpers import *
from setupdevhelpers import *
from datetime import datetime
import os


def update_package():
    install_apt('python3-pip')
    install_apt('git')
    mkdirs("build")
    
    for u in ["branch-2.6","master"]:
        print(u)
        if isdir("/tmp/doc-wapt"):
            remove_tree('/tmp/doc-wapt')

        run(fr'git clone --branch %s https://gitea.ad.tranquil.it/doc/doc-wapt.git /tmp/doc-wapt' % u)

        olddir = os.getcwd()
        os.chdir('/tmp/doc-wapt')

        run("make clean")
        run("rm -Rf ./build/")
        run("pip3 install -U setuptools --break-system-packages")
        run("pip3 install -r requirements.txt --upgrade --break-system-packages")
        run("make gettext")
        run("sphinx-intl update -p build/locale/ -l fr")
        run("make clean")
        run("make htmlen")
        run('make -e SPHINXOPTS="-D language=\'fr\'" htmlfr')

        os.chdir(olddir)
        copytree2('/tmp/doc-wapt/build',makepath('build', u))

    version = int(datetime.now().strftime("%Y%m%d%H%M%S"))
    control.version = "%s-%s" % (version, control.version.split("-", 1)[-1])
    control.save_control_to_wapt()
