import io, sys

p = "/homez.1005/fxdevsx/etic/.htaccess"
src = io.open(p, encoding="utf-8").read()

old = """  RewriteRule (?i)(^|/)\\.(git|svn|hg|bzr)(/|$) - [R=404,L]
  RewriteRule (?i)(^|/)\\.git[a-z]*$            - [R=404,L]
"""

new = """  # Regle GENERIQUE, alignee sur assets/htaccess.tpl du skill
  # wp-elementor-ovh-setup : une enumeration (.git|.svn|...) laisse passer ce
  # qu'on n'a pas prevu (.github/, .env). Ici et aujourd'hui : .git/ + .gitignore.
  # /!\\ L'exception .well-known est OBLIGATOIRE : sans elle, le renouvellement
  #     Let's Encrypt echoue EN SILENCE.
  RewriteCond %{REQUEST_URI} !(^|/)\\.well-known/
  RewriteRule (^|/)\\. - [F,L]
"""

if old not in src:
    sys.exit("ANCRE INTROUVABLE - rien modifie")

io.open(p, "w", encoding="utf-8").write(src.replace(old, new, 1))
print("OK patch 2 applique")
