2020-09-26 16:19:37 +02:00
|
|
|
#!/opt/zope213/bin/python
|
2021-04-23 10:30:16 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
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/
|
2021-04-23 10:24:45 +02:00
|
|
|
Apr 2021: bug #70
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import glob
|
2021-04-23 10:24:45 +02:00
|
|
|
import shutil
|
|
|
|
from scodocutils import log, SCODOC_DIR, SCODOC_VAR_DIR, SCODOC_LOGOS_DIR, SCO_TMPDIR
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
if os.getuid() != 0:
|
2021-04-23 10:24:45 +02:00
|
|
|
log("postupgrade.py: must be run as root")
|
2020-09-26 16:19:37 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# ---
|
|
|
|
# Migrate photos (2020-08-16, svn 1908)
|
|
|
|
old_photo_dir = os.path.join(SCODOC_DIR, "static", "photos")
|
2021-04-23 10:24:45 +02:00
|
|
|
photo_dirs = glob.glob(old_photo_dir + "/F*")
|
2020-09-26 16:19:37 +02:00
|
|
|
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")
|
2021-04-23 10:24:45 +02:00
|
|
|
cfg_files = glob.glob(old_depts_dir + "/*.cfg")
|
2020-09-26 16:19:37 +02:00
|
|
|
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):
|
2021-04-23 10:24:45 +02:00
|
|
|
old_logos = os.path.join(SCODOC_DIR, "logos")
|
2020-09-26 16:19:37 +02:00
|
|
|
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
|
2021-04-23 10:24:45 +02:00
|
|
|
for d in glob.glob(SCODOC_DIR + "/logos_*"):
|
2020-09-26 16:19:37 +02:00
|
|
|
log("Moving %s to %s" % (d, SCODOC_LOGOS_DIR))
|
|
|
|
shutil.move(d, SCODOC_LOGOS_DIR)
|
|
|
|
|
2021-04-23 10:24:45 +02:00
|
|
|
# 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)
|
2021-04-23 10:30:16 +02:00
|
|
|
# n'essaie qu'une fois, même en cas d'échec
|
2021-04-23 10:24:45 +02:00
|
|
|
f = open(fixed_filename, "a")
|
|
|
|
f.close()
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
# Continue here...
|
|
|
|
|
|
|
|
# ---
|
|
|
|
sys.exit(0)
|