Révision ef98b98a
Ajouté par Julien Enselme il y a plus de 10 ans
scripts_divers/fix-cas.py | ||
---|---|---|
3 | 3 |
# This script is intended to fix the cas_user table. Just give the database name. |
4 | 4 |
|
5 | 5 |
import argparse |
6 |
from getpass import getpass |
|
6 | 7 |
|
7 | 8 |
def fix_cas(db, host, user, password, prefix, roles): |
8 | 9 |
import pymysql as mysql |
9 | 10 |
|
10 | 11 |
while not password: |
11 |
password = input('Please enter the password: ') |
|
12 |
password = getpass('Please enter the password: ') |
|
13 |
password = password.strip() |
|
12 | 14 |
|
13 | 15 |
conn = mysql.connect(host=host, user=user, passwd=password, db=db, charset='utf8') |
14 | 16 |
with conn: |
... | ... | |
21 | 23 |
tables[key] = elt.format(prefix) |
22 | 24 |
|
23 | 25 |
# We take into account the roles to modify |
26 |
for role in roles: |
|
27 |
i = roles.index(role) |
|
28 |
roles[i] = "'" + role + "'" |
|
24 | 29 |
format_dict = {'roles_to_modify': ', '.join(roles)} |
25 | 30 |
|
26 | 31 |
# We are ready to format queries |
... | ... | |
54 | 59 |
parser.add_argument('--host', dest='host', default='localhost') |
55 | 60 |
parser.add_argument('--user', '-u', dest='user', default='root') |
56 | 61 |
parser.add_argument('--password', '--passwd', '-p', dest='password') |
57 |
parser.add_argument('--prefix', dest='prefix') |
|
62 |
parser.add_argument('--prefix', dest='prefix', default='')
|
|
58 | 63 |
parser.add_argument('--roles', '-r', dest='roles', nargs='+', default=['authenticated user']) |
59 | 64 |
|
60 | 65 |
args = parser.parse_args() |
61 |
fix_cas(args.database, args.host, args.user, args.passwd, args.prefix, args.roles) |
|
66 |
fix_cas(args.database, args.host, args.user, args.password, args.prefix, args.roles) |
Formats disponibles : Unified diff
fix-cas.py: corrections diverses
problème sur les rôles et caractères de fin de ligne du mot de passe