52 lines
1.8 KiB
Python
Executable File
52 lines
1.8 KiB
Python
Executable File
#! /usr/bin/env python
|
|
# usage: sudo -u wcs-au-quotidien ~tma/scripts/copy-wcs.py
|
|
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
from django.utils.text import slugify
|
|
|
|
communes_json = os.path.join(os.path.dirname(__file__), 'communes.json')
|
|
|
|
orig_city = json.load(open(communes_json))['orig']
|
|
slug_orig_city = slugify(orig_city)
|
|
orig_site = 'demarches-%s.guichet-recette.grandlyon.com' % slug_orig_city
|
|
|
|
roles_mapping = json.load(open('/tmp/roles.mapping.json'))
|
|
|
|
|
|
def copy(orig, dest, dest_city):
|
|
if os.path.exists(dest):
|
|
return # do not overwrite
|
|
src = open(orig).read()
|
|
for role_id in roles_mapping.keys():
|
|
src = src.replace(role_id, roles_mapping[role_id][dest_city])
|
|
fd = open(dest, 'w')
|
|
fd.write(src)
|
|
fd.close()
|
|
|
|
for dest in json.load(open(communes_json))['dests']:
|
|
dest_city = dest['name']
|
|
print dest_city
|
|
slug_dest_city = slugify(dest_city)
|
|
dest_site = 'demarches-%s.guichet-recette.grandlyon.com' % slug_dest_city
|
|
|
|
for object_type in ('formdefs', 'workflows', 'categories', 'datasources', 'models'):
|
|
orig_dir = os.path.join('/var/lib/wcs-au-quotidien/%s/%s/' % (orig_site, object_type))
|
|
dest_dir = os.path.join('/var/lib/wcs-au-quotidien/%s/%s/' % (dest_site, object_type))
|
|
if not os.path.exists(orig_dir):
|
|
continue
|
|
if not os.path.exists(dest_dir):
|
|
os.mkdir(dest_dir)
|
|
for object_id in os.listdir(orig_dir):
|
|
copy(os.path.join(orig_dir, object_id),
|
|
os.path.join(dest_dir, object_id),
|
|
dest_city)
|
|
|
|
subprocess.call(['/usr/bin/python', '/usr/sbin/wcsctl', '-f', '/etc/wcs/wcs-au-quotidien.cfg',
|
|
'runscript', '--extra', '/usr/lib/pymodules/python2.7/extra-wcs-au-quotidien/',
|
|
'--vhost', dest_site,
|
|
'/data/home/tma/scripts/fsck-wcs.py'])
|