Project

General

Profile

Revision ef903da4

Added by Julien Enselme about 10 years ago

These script synchronises the site and make the proper modification to its settings.php

View differences:

other-scripts/d7-sync.sh
19 19
    exit 0
20 20
fi
21 21

  
22
root=$(pwd)
22 23
cd htmltest/sites
23 24
if [ $1 = default ] ; then
24 25
    dir_site=$1
......
41 42
ssh assos "rm $remote_sql_file"
42 43

  
43 44
# modify settings.php
45
python3 $root/other-scripts/modify-settings.py settings.local.php
44 46

  
45 47
# various drush cmd to finish synchronisation
46 48
drush -y dis piwik
other-scripts/modify-settings.py
1
#!/usr/bin/python3
2

  
3
"""Ce script permet de modifier un fichier settings.php d’un site. Il prend le chemin du settings en paramètre.
4
"""
5

  
6
import re
7
import sys
8
import argparse
9
import os
10

  
11
def modify_settings(args):
12
    settings_path = args.settings
13
    settings_new_path = settings_path + '.new'
14

  
15
    regexp = "'{}' => '(.*)'"
16

  
17
    with open(settings_path, 'r') as settings:
18
        with open(settings_new_path, 'w') as settings_new:
19
            for ligne in settings:
20
                ligne = re.sub(regexp.format('password'),\
21
                               "'password' => '{}'".format(args.password), ligne)
22
                if args.database:
23
                    ligne = re.sub(regexp.format('database'),\
24
                               "'database' => '{}'".format(args.database), ligne)
25
                ligne = re.sub(regexp.format('username'),\
26
                               "'username' => '{}'".format(args.user), ligne)
27
                ligne = re.sub(regexp.format('host'),\
28
                               "'host' => '{}'".format(args.host), ligne)
29
                if args.port:
30
                    ligne = re.sub(regexp.format('port'),\
31
                               "'port' => '{}'".format(args.port), ligne)
32
                if args.prefix:
33
                    ligne = re.sub(regexp.format('prefix'),\
34
                               "'prefix' => '{}'".format(args.prefix), ligne)
35
                if args.baseurl:
36
                    ligne = re.sub("\$base_url = (.*)",\
37
                               "$base_url = '{}';  // NO trailing slash!".format(args.baseurl), ligne)
38
                settings_new.write(ligne)
39
            os.chmod(settings_path, 700)
40
            os.remove(settings_path)
41
            os.rename(settings_new_path, settings_path)
42
            os.chmod(settings_path, 600)
43

  
44
if __name__ == '__main__':
45
    parser = argparse.ArgumentParser(description=__doc__)
46
    parser.add_argument('settings', metavar='settings', help='The path to the settings.')
47
    parser.add_argument('--user', '-u', dest='user', default='root', help='Database user')
48
    parser.add_argument('--password', '-p', dest='password', default='', help='Database password')
49
    parser.add_argument('--database', dest='database', help='New database name')
50
    parser.add_argument('--host', dest='host', default='localhost', help='The new host of the database.')
51
    parser.add_argument('--prefix', dest='prefix', help='The prefix for the database.')
52
    parser.add_argument('--port', dest='port', help='The database port.')
53
    parser.add_argument('--baseurl', dest='baseurl', help='The new base url')
54
    args = parser.parse_args()
55
    modify_settings(args)

Also available in: Unified diff