misc-fred/grandlyon/scripts/copy-portal-agent.py

31 lines
1.3 KiB
Python

#! /usr/bin/env python3
# python3 copy-portal-agent.py Oullins Genay
import json
import os
import subprocess
import sys
from django.utils.text import slugify
orig_city= sys.argv[1]
slug_orig_city = slugify(orig_city)
orig_site = 'portail-agent-%s.guichet-recette.grandlyon.com' % slug_orig_city
dest_city = sys.argv[2]
slug_dest_city = slugify(dest_city)
dest_site = 'portail-agent-%s.guichet-recette.grandlyon.com' % slug_dest_city
site_export_orig = subprocess.check_output(['sudo', '-u', 'combo', 'combo-manage', 'tenant_command', 'export_site', '-d', orig_site])
site_export_orig = site_export_orig.decode('utf-8')
site_export = site_export_orig.replace(orig_city, dest_city)
site_export = site_export.replace(slug_orig_city, slug_dest_city)
open('/tmp/site-export.json', 'w').write(site_export)
subprocess.call(['sudo', '-u', 'combo', 'combo-manage', 'tenant_command', 'import_site', '-d', dest_site, '/tmp/site-export.json'])
subprocess.call(['sudo', '-u', 'combo', 'combo-manage', 'tenant_command', 'runscript', '-d', dest_site, 'fsck-combo.py'])
orig_media_dir = '/var/lib/combo/tenants/%s/media/*' % orig_site
if os.path.exists(orig_media_dir) and os.listdir(orig_media_dir):
subprocess.call(['sudo', '-u', 'combo', 'cp', '-ar', orig_media_dir, '/var/lib/combo/tenants/%s/' % dest_site])