grand lyon: update management scripts for one to one copy
This commit is contained in:
parent
6a090ded52
commit
122e8873eb
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"orig": "Bron",
|
||||
"dests": [
|
||||
{"name": "Corbas"},
|
||||
{"name": "Dardilly"},
|
||||
{"name": "Oullins"},
|
||||
{"name": "Vaulx-en-Velin"},
|
||||
{"name": "Villeurbanne"}
|
||||
],
|
||||
"dests-off": [
|
||||
]
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#! /usr/bin/env python
|
||||
#! /usr/bin/env python3
|
||||
# python3 copy-portal-agent.py Oullins Genay
|
||||
|
||||
import json
|
||||
import os
|
||||
|
@ -7,22 +8,22 @@ 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']
|
||||
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')
|
||||
|
||||
for dest in json.load(open(communes_json))['dests']:
|
||||
dest_city = dest['name']
|
||||
slug_dest_city = slugify(dest_city)
|
||||
dest_site = 'portail-agent-%s.guichet-recette.grandlyon.com' % slug_dest_city
|
||||
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'])
|
||||
|
||||
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, '/data/home/tma/scripts/fsck-combo.py'])
|
||||
if os.listdir('/var/lib/combo/tenants/%s/media/*' % orig_site):
|
||||
subprocess.call(['sudo', '-u', 'combo', 'cp', '-ar', '/var/lib/combo/tenants/%s/media' % orig_site, '/var/lib/combo/tenants/%s/' % dest_site])
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#! /usr/bin/env python
|
||||
# python3 copy-portal-users.py Oullins Genay
|
||||
|
||||
import json
|
||||
import os
|
||||
|
@ -7,22 +8,22 @@ 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']
|
||||
orig_city= sys.argv[1]
|
||||
slug_orig_city = slugify(orig_city)
|
||||
orig_site = 'portail-citoyen-%s.guichet-recette.grandlyon.com' % slug_orig_city
|
||||
|
||||
dest_city = sys.argv[2]
|
||||
slug_dest_city = slugify(dest_city)
|
||||
dest_site = 'portail-citoyen-%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')
|
||||
|
||||
for dest in json.load(open(communes_json))['dests']:
|
||||
dest_city = dest['name']
|
||||
slug_dest_city = slugify(dest_city)
|
||||
dest_site = 'portail-citoyen-%s.guichet-recette.grandlyon.com' % slug_dest_city
|
||||
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'])
|
||||
|
||||
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, '/data/home/tma/scripts/fsck-combo.py'])
|
||||
if os.listdir('/var/lib/combo/tenants/%s/media/' % orig_site):
|
||||
subprocess.call(['sudo', '-u', 'combo', 'cp', '-ar', '/var/lib/combo/tenants/%s/media' % orig_site, '/var/lib/combo/tenants/%s/' % dest_site])
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
import os
|
||||
import json
|
||||
import sys
|
||||
|
||||
from django_rbac.utils import get_role_model, get_ou_model
|
||||
|
||||
Ou = get_ou_model()
|
||||
Role = get_role_model()
|
||||
|
||||
mapping = {}
|
||||
|
||||
name_src = sys.argv[1]
|
||||
name_dst = sys.argv[2]
|
||||
|
||||
ou_src = Ou.objects.get(name=name_src)
|
||||
ou = Ou.objects.get(name=name_dst)
|
||||
|
||||
for role in Role.objects.filter(ou=ou_src):
|
||||
if not (role.name.startswith('Gestionnaire') or role.name.startswith('Administrateur')):
|
||||
continue
|
||||
if role.slug.startswith('_'):
|
||||
continue
|
||||
new_name = role.name.replace(name_src, name_dst).replace(name_src.lower(), name_dst.lower())
|
||||
new_role, created = Role.objects.get_or_create(ou=ou, name=new_name)
|
||||
mapping[role.uuid] = {name_dst: new_role.uuid}
|
||||
|
||||
json.dump(mapping, open('/tmp/roles.mapping.json', 'w'), indent=2)
|
|
@ -1,5 +1,8 @@
|
|||
#! /usr/bin/env python
|
||||
# usage: sudo -u wcs-au-quotidien ~tma/scripts/copy-wcs.py
|
||||
# usage: sudo -u wcs /usr/bin/wcsctl -f /etc/wcs/wcs-au-quotidien.cfg runscript --vhost=demarches-<...>.guichet-recette.grandlyon.com copy-wcs.py Oullins Genay
|
||||
|
||||
from quixote import get_publisher
|
||||
from wcs.formdef import FormDef
|
||||
|
||||
import json
|
||||
import os
|
||||
|
@ -8,44 +11,40 @@ 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']
|
||||
orig_city = sys.argv[1]
|
||||
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'))
|
||||
dest_city = sys.argv[2]
|
||||
slug_dest_city = slugify(dest_city)
|
||||
dest_site = 'demarches-%s.guichet-recette.grandlyon.com' % slug_dest_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()
|
||||
return # do not overwrite
|
||||
if not os.path.isfile(orig):
|
||||
return # ignore non files
|
||||
src = open(orig, 'rb').read()
|
||||
for role_id in roles_mapping.keys():
|
||||
src = src.replace(role_id, roles_mapping[role_id][dest_city])
|
||||
fd = open(dest, 'w')
|
||||
src = src.replace(role_id.encode('ascii'), roles_mapping[role_id][dest_city].encode('ascii'))
|
||||
fd = open(dest, 'wb')
|
||||
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', 'wcscalls'):
|
||||
orig_dir = os.path.join('/var/lib/wcs/%s/%s/' % (orig_site, object_type))
|
||||
dest_dir = os.path.join('/var/lib/wcs/%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)
|
||||
|
||||
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'])
|
||||
# iterate over all objects and store them again to make sure side-code is run.
|
||||
for formdef in FormDef.select():
|
||||
formdef.store()
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
# usage:
|
||||
# cmd ou-orig ou-dest
|
||||
# ex:
|
||||
# authentic2-multitenant-manage tenant_command runscript -d connexion.guichet-recette.grandlyon.com ~tma/scripts/duplicate-roles.py Bron Dardilly
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import sys
|
||||
|
||||
from authentic2.models import Attribute
|
||||
from authentic2.compat import get_user_model
|
||||
from authentic2.utils import datetime_to_utc
|
||||
from django_rbac.utils import get_role_model, get_ou_model
|
||||
from hobo.agent.authentic2.provisionning import Provisionning
|
||||
|
||||
ORIG = json.load(open('communes.json'))['orig']
|
||||
DESTS = [x['name'] for x in json.load(open('communes.json'))['dests']]
|
||||
|
||||
User = get_user_model()
|
||||
Role = get_role_model()
|
||||
Ou = get_ou_model()
|
||||
|
||||
ou_orig = Ou.objects.get(name=ORIG)
|
||||
|
||||
with Provisionning():
|
||||
mapping = {}
|
||||
for orig_role in Role.objects.filter(ou=ou_orig):
|
||||
if orig_role.slug.startswith('_a2'):
|
||||
continue
|
||||
mapping[orig_role.uuid] = {}
|
||||
for dest in DESTS:
|
||||
ou_dest = Ou.objects.get(name=dest)
|
||||
dest_role, created = Role.objects.get_or_create(ou=ou_dest, name=orig_role.name.replace(ORIG, dest))
|
||||
dest_role.save()
|
||||
mapping[orig_role.uuid][dest] = dest_role.uuid
|
||||
json.dump(mapping, open('/tmp/roles.mapping.json', 'w'), indent=2)
|
|
@ -1,6 +1,6 @@
|
|||
# add all collectivity technical admin roles to "Administrateur <commune>"
|
||||
|
||||
# authentic2-multitenant-manage tenant_command runscript -d connexion.guichet-recette.grandlyon.com ~tma/misc-fred/grandlyon/scripts/mark-admin-roles.py
|
||||
# authentic2-multitenant-manage tenant_command runscript -d connexion.guichet-recette.grandlyon.com ~tma/misc-fred/grandlyon/scripts/mark-admin-roles.py Genais
|
||||
|
||||
import os
|
||||
import json
|
||||
|
@ -13,12 +13,11 @@ from django_rbac.utils import get_role_model, get_ou_model
|
|||
Ou = get_ou_model()
|
||||
Role = get_role_model()
|
||||
|
||||
communes_json = os.path.join(os.path.dirname(__file__), 'communes.json')
|
||||
name_dst = sys.argv[1]
|
||||
ou = Ou.objects.get(name=name_dst)
|
||||
|
||||
for dest in json.load(open(communes_json))['dests']:
|
||||
ou = Ou.objects.get(name=dest['name'])
|
||||
role = Role.objects.get(name=u'Administrateur %s' % dest['name'])
|
||||
for subrole in Role.objects.filter(Q(slug='_a2-hobo-superuser', ou=ou) |
|
||||
Q(slug__startswith='administrateur-fonc', ou=ou) |
|
||||
Q(slug__startswith='_a2-administrateur', ou=ou)):
|
||||
role.add_parent(subrole)
|
||||
role = Role.objects.get(name=u'Administrateur %s' % name_dst, ou=ou)
|
||||
for subrole in Role.objects.filter(Q(slug='_a2-hobo-superuser', ou=ou) |
|
||||
Q(slug__startswith='administrateur-fonc', ou=ou) |
|
||||
Q(slug__startswith='_a2-administrateur', ou=ou)):
|
||||
role.add_parent(subrole)
|
||||
|
|
Loading…
Reference in New Issue