ScoDoc/config/postupgrade.py

76 lines
2.2 KiB
Python
Executable File

#!/opt/zope213/bin/python
# -*- coding: utf-8 -*-
"""
ScoDoc post-upgrade script.
This script is launched by upgrade.sh after each SVN update.
Run as "root" with Zope shutted down and postgresql up,
_before_ upgrading the database.
E. Viennet, June 2008
Mar 2017: suppress upgrade of very old Apache configs
Aug 2020: move photos to .../var/scodoc/
Apr 2021: bug #70
"""
import os
import sys
import glob
import shutil
from scodocutils import log, SCODOC_DIR, SCODOC_VAR_DIR, SCODOC_LOGOS_DIR, SCO_TMPDIR
if os.getuid() != 0:
log("postupgrade.py: must be run as root")
sys.exit(1)
# ---
# Migrate photos (2020-08-16, svn 1908)
old_photo_dir = os.path.join(SCODOC_DIR, "static", "photos")
photo_dirs = glob.glob(old_photo_dir + "/F*")
if photo_dirs:
log("Moving photos to new <var> directory...")
shutil.move(old_photo_dir, SCODOC_VAR_DIR)
# Migrate depts (2020-08-17, svn 1909)
old_depts_dir = os.path.join(SCODOC_DIR, "config", "depts")
cfg_files = glob.glob(old_depts_dir + "/*.cfg")
depts_dir = os.path.join(SCODOC_VAR_DIR, "config/depts/")
for cfg in cfg_files:
log("Moving %s to new <var> directory..." % cfg)
shutil.move(cfg, depts_dir)
# Move logos
if not os.path.exists(SCODOC_LOGOS_DIR):
old_logos = os.path.join(SCODOC_DIR, "logos")
if os.path.exists(old_logos):
log("Moving logos to new <var> directory...")
dest = os.path.normpath(os.path.join(SCODOC_LOGOS_DIR, ".."))
shutil.move(old_logos, dest)
else:
log("Warning: logos directory is missing (%s)" % SCODOC_LOGOS_DIR)
# Move dept-specific logos
for d in glob.glob(SCODOC_DIR + "/logos_*"):
log("Moving %s to %s" % (d, SCODOC_LOGOS_DIR))
shutil.move(d, SCODOC_LOGOS_DIR)
# Fix bug #70
depts = [
os.path.splitext(os.path.basename(f))[0] for f in glob.glob(depts_dir + "/*.cfg")
]
for dept in depts:
fixed_filename = SCO_TMPDIR + "/.%s_bug70_fixed" % dept
if not os.path.exists(fixed_filename):
log("fixing #70 on %s" % dept)
os.system("../scotests/scointeractive.sh -x %s config/fix_bug70_db.py" % dept)
# n'essaie qu'une fois, même en cas d'échec
f = open(fixed_filename, "a")
f.close()
# Continue here...
# ---
sys.exit(0)