summaryrefslogtreecommitdiffstats
path: root/grandlyon/scripts/copy-portal-agent.py
blob: 55514bc74e243266955caf4e95880a9c3d39fa29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /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)
dest_city = sys.argv[2]
slug_dest_city = slugify(dest_city)

if os.path.exists('/var/lib/combo/tenants/www.toodego.com'):
    orig_site = 'agents-%s.toodego.com' % slug_orig_city
    dest_site = 'agents-%s.toodego.com' % slug_dest_city
else:
    orig_site = 'portail-agent-%s.guichet-recette.grandlyon.com' % slug_orig_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, '--format-json'])
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])