author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 25 Aug 2010 18:55:58 +0200 | |
changeset 6149 | 57e956441ca4 |
parent 6138 | 65f5e488f983 |
child 6184 | da580218a5b3 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5410
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5967 | 18 |
"""cubicweb-ctl commands and command handlers specific to the repository""" |
0 | 19 |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
20 |
__docformat__ = 'restructuredtext en' |
0 | 21 |
|
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4670
diff
changeset
|
22 |
# *ctl module should limit the number of import to be imported as quickly as |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4670
diff
changeset
|
23 |
# possible (for cubicweb-ctl reactivity, necessary for instance for usable bash |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4670
diff
changeset
|
24 |
# completion). So import locally in command helpers. |
1912
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
25 |
import sys |
0 | 26 |
import os |
27 |
||
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2106
diff
changeset
|
28 |
from logilab.common.configuration import Configuration |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2507
diff
changeset
|
29 |
from logilab.common.shellutils import ASK |
0 | 30 |
|
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2711
diff
changeset
|
31 |
from cubicweb import AuthenticationError, ExecutionError, ConfigurationError |
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2711
diff
changeset
|
32 |
from cubicweb.toolsutils import Command, CommandHandler, underline_title |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
33 |
from cubicweb.cwctl import CWCTL |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
34 |
from cubicweb.server import SOURCE_TYPES |
3904
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3893
diff
changeset
|
35 |
from cubicweb.server.serverconfig import (USER_OPTIONS, ServerConfiguration, |
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3893
diff
changeset
|
36 |
SourceConfiguration) |
0 | 37 |
|
38 |
# utility functions ########################################################### |
|
39 |
||
136
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
40 |
def source_cnx(source, dbname=None, special_privs=False, verbose=True): |
0 | 41 |
"""open and return a connection to the system database defined in the |
42 |
given server.serverconfig |
|
43 |
""" |
|
44 |
from getpass import getpass |
|
6060
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
45 |
from logilab.database import get_connection, get_db_helper |
4218
deb2dcffb301
[cwctl] reset-admin-pwd was failing when db-host was not set
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4212
diff
changeset
|
46 |
dbhost = source.get('db-host') |
0 | 47 |
if dbname is None: |
48 |
dbname = source['db-name'] |
|
49 |
driver = source['db-driver'] |
|
6060
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
50 |
dbhelper = get_db_helper(driver) |
5754
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
51 |
if verbose: |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
52 |
print '-> connecting to %s database' % driver, |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
53 |
if dbhost: |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
54 |
print '%s@%s' % (dbname, dbhost), |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
55 |
else: |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
56 |
print dbname, |
6060
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
57 |
if dbhelper.users_support: |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
58 |
if not verbose or (not special_privs and source.get('db-user')): |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
59 |
user = source['db-user'] |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
60 |
if verbose: |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
61 |
print 'as', user |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
62 |
if source.get('db-password'): |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
63 |
password = source['db-password'] |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
64 |
else: |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
65 |
password = getpass('password: ') |
0 | 66 |
else: |
67 |
print |
|
6060
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
68 |
if special_privs: |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
69 |
print 'WARNING' |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
70 |
print ('the user will need the following special access rights ' |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
71 |
'on the database:') |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
72 |
print special_privs |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
73 |
print |
6072
9d83b214066a
[db-create] fix bug introduced by 6060:353bec342e2a (we ask for user while in non verbose mode)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6060
diff
changeset
|
74 |
default_user = source.get('db-user', os.environ.get('USER', '')) |
9d83b214066a
[db-create] fix bug introduced by 6060:353bec342e2a (we ask for user while in non verbose mode)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6060
diff
changeset
|
75 |
user = raw_input('Connect as user ? [%r]: ' % default_user) |
9d83b214066a
[db-create] fix bug introduced by 6060:353bec342e2a (we ask for user while in non verbose mode)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6060
diff
changeset
|
76 |
user = user or default_user |
9d83b214066a
[db-create] fix bug introduced by 6060:353bec342e2a (we ask for user while in non verbose mode)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6060
diff
changeset
|
77 |
if user == source.get('db-user') and source.get('db-password'): |
9d83b214066a
[db-create] fix bug introduced by 6060:353bec342e2a (we ask for user while in non verbose mode)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6060
diff
changeset
|
78 |
password = source['db-password'] |
9d83b214066a
[db-create] fix bug introduced by 6060:353bec342e2a (we ask for user while in non verbose mode)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6060
diff
changeset
|
79 |
else: |
9d83b214066a
[db-create] fix bug introduced by 6060:353bec342e2a (we ask for user while in non verbose mode)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6060
diff
changeset
|
80 |
password = getpass('password: ') |
6060
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
81 |
else: |
353bec342e2a
[db create] don't ask user/password if the underlying db doesn't support it (eg sqlite)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5990
diff
changeset
|
82 |
user = password = None |
4180
9fb0d06926cc
more extra_args cleanup
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4177
diff
changeset
|
83 |
extra_args = source.get('db-extra-arguments') |
9fb0d06926cc
more extra_args cleanup
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4177
diff
changeset
|
84 |
extra = extra_args and {'extra_args': extra_args} or {} |
4837
54969eec48eb
misc fixes to ensure logilab.db compatibility
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
85 |
cnx = get_connection(driver, dbhost, dbname, user, password=password, |
54969eec48eb
misc fixes to ensure logilab.db compatibility
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
86 |
port=source.get('db-port'), |
54969eec48eb
misc fixes to ensure logilab.db compatibility
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
87 |
**extra) |
4845 | 88 |
try: |
89 |
cnx.logged_user = user |
|
90 |
except AttributeError: |
|
91 |
# C object, __slots__ |
|
4848
41f84eea63c9
rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4845
diff
changeset
|
92 |
from logilab.database import _SimpleConnectionWrapper |
4845 | 93 |
cnx = _SimpleConnectionWrapper(cnx) |
94 |
cnx.logged_user = user |
|
4837
54969eec48eb
misc fixes to ensure logilab.db compatibility
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
95 |
return cnx |
0 | 96 |
|
136
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
97 |
def system_source_cnx(source, dbms_system_base=False, |
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
98 |
special_privs='CREATE/DROP DATABASE', verbose=True): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
99 |
"""shortcut to get a connextion to the instance system database |
0 | 100 |
defined in the given config. If <dbms_system_base> is True, |
101 |
connect to the dbms system database instead (for task such as |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
102 |
create/drop the instance database) |
0 | 103 |
""" |
104 |
if dbms_system_base: |
|
4848
41f84eea63c9
rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4845
diff
changeset
|
105 |
from logilab.database import get_db_helper |
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
106 |
system_db = get_db_helper(source['db-driver']).system_database() |
136
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
107 |
return source_cnx(source, system_db, special_privs=special_privs, verbose=verbose) |
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
108 |
return source_cnx(source, special_privs=special_privs, verbose=verbose) |
0 | 109 |
|
136
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
110 |
def _db_sys_cnx(source, what, db=None, user=None, verbose=True): |
0 | 111 |
"""return a connection on the RDMS system table (to create/drop a user |
112 |
or a database |
|
113 |
""" |
|
2417
18a14c23413c
should ensure lgc is configured to not use mx to avoid error if backend module is missing mx support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2107
diff
changeset
|
114 |
import logilab.common as lgp |
4848
41f84eea63c9
rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4845
diff
changeset
|
115 |
from logilab.database import get_db_helper |
2417
18a14c23413c
should ensure lgc is configured to not use mx to avoid error if backend module is missing mx support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2107
diff
changeset
|
116 |
lgp.USE_MX_DATETIME = False |
0 | 117 |
special_privs = '' |
118 |
driver = source['db-driver'] |
|
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
119 |
helper = get_db_helper(driver) |
0 | 120 |
if user is not None and helper.users_support: |
121 |
special_privs += '%s USER' % what |
|
122 |
if db is not None: |
|
123 |
special_privs += ' %s DATABASE' % what |
|
124 |
# connect on the dbms system base to create our base |
|
136
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
125 |
cnx = system_source_cnx(source, True, special_privs=special_privs, verbose=verbose) |
0 | 126 |
# disable autocommit (isolation_level(1)) because DROP and |
127 |
# CREATE DATABASE can't be executed in a transaction |
|
128 |
try: |
|
129 |
cnx.set_isolation_level(0) |
|
130 |
except AttributeError: |
|
131 |
# set_isolation_level() is psycopg specific |
|
132 |
pass |
|
133 |
return cnx |
|
1469 | 134 |
|
0 | 135 |
def repo_cnx(config): |
136 |
"""return a in-memory repository and a db api connection it""" |
|
137 |
from cubicweb.dbapi import in_memory_cnx |
|
138 |
from cubicweb.server.utils import manager_userpasswd |
|
139 |
try: |
|
140 |
login = config.sources()['admin']['login'] |
|
141 |
pwd = config.sources()['admin']['password'] |
|
142 |
except KeyError: |
|
143 |
login, pwd = manager_userpasswd() |
|
144 |
while True: |
|
145 |
try: |
|
3647
2941f4a0aab9
refactor repo authentication to allow pluggable authentifier to login with something else than a password
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3589
diff
changeset
|
146 |
return in_memory_cnx(config, login, password=pwd) |
0 | 147 |
except AuthenticationError: |
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2107
diff
changeset
|
148 |
print '-> Error: wrong user/password.' |
1682
36bd5cba09de
must reset cubes before next authentication
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1469
diff
changeset
|
149 |
# reset cubes else we'll have an assertion error on next retry |
36bd5cba09de
must reset cubes before next authentication
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1469
diff
changeset
|
150 |
config._cubes = None |
0 | 151 |
login, pwd = manager_userpasswd() |
1469 | 152 |
|
3904
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3893
diff
changeset
|
153 |
|
0 | 154 |
# repository specific command handlers ######################################## |
155 |
||
156 |
class RepositoryCreateHandler(CommandHandler): |
|
157 |
cmdname = 'create' |
|
158 |
cfgname = 'repository' |
|
159 |
||
160 |
def bootstrap(self, cubes, inputlevel=0): |
|
5967 | 161 |
"""create an instance by copying files from the given cube and by asking |
162 |
information necessary to build required configuration files |
|
0 | 163 |
""" |
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4670
diff
changeset
|
164 |
from cubicweb.server.utils import ask_source_config |
0 | 165 |
config = self.config |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2394
diff
changeset
|
166 |
print underline_title('Configuring the repository') |
0 | 167 |
config.input_config('email', inputlevel) |
3539
f3b14d052798
[pyro] merge pyro-id / pyro-instance-id options, put all pyro options in the same section of the configuration file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
168 |
# ask for pyro configuration if pyro is activated and we're not using a |
f3b14d052798
[pyro] merge pyro-id / pyro-instance-id options, put all pyro options in the same section of the configuration file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
169 |
# all-in-one config, in which case this is done by the web side command |
f3b14d052798
[pyro] merge pyro-id / pyro-instance-id options, put all pyro options in the same section of the configuration file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
170 |
# handler |
f3b14d052798
[pyro] merge pyro-id / pyro-instance-id options, put all pyro options in the same section of the configuration file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
171 |
if config.pyro_enabled() and config.name != 'all-in-one': |
f3b14d052798
[pyro] merge pyro-id / pyro-instance-id options, put all pyro options in the same section of the configuration file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
172 |
config.input_config('pyro', inputlevel) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2394
diff
changeset
|
173 |
print '\n'+underline_title('Configuring the sources') |
0 | 174 |
sourcesfile = config.sources_file() |
3835
a191b3b9e455
more sensible default values to c-c "create" inputs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3786
diff
changeset
|
175 |
# XXX hack to make Method('default_instance_id') usable in db option |
a191b3b9e455
more sensible default values to c-c "create" inputs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3786
diff
changeset
|
176 |
# defs (in native.py) |
3904
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3893
diff
changeset
|
177 |
sconfig = SourceConfiguration(config.appid, |
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3893
diff
changeset
|
178 |
options=SOURCE_TYPES['native'].options) |
0 | 179 |
sconfig.adapter = 'native' |
180 |
sconfig.input_config(inputlevel=inputlevel) |
|
181 |
sourcescfg = {'system': sconfig} |
|
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
182 |
for cube in cubes: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
183 |
# if a source is named as the cube containing it, we need the |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
184 |
# source to use the cube, so add it. |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
185 |
if cube in SOURCE_TYPES: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
186 |
sourcescfg[cube] = ask_source_config(cube, inputlevel) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2394
diff
changeset
|
187 |
print |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2507
diff
changeset
|
188 |
while ASK.confirm('Enter another source ?', default_is_yes=False): |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
189 |
available = sorted(stype for stype in SOURCE_TYPES |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
190 |
if not stype in cubes) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
191 |
while True: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
192 |
sourcetype = raw_input('source type (%s): ' % ', '.join(available)) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
193 |
if sourcetype in available: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
194 |
break |
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2107
diff
changeset
|
195 |
print '-> unknown source type, use one of the available types.' |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
196 |
while True: |
5410
3cccd5e9dd7d
cubicweb-ctl create improvements
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5043
diff
changeset
|
197 |
sourceuri = raw_input('source identifier (a unique name used to tell sources apart): ').strip() |
2106
2295f2aba61d
check not using "admin" as uri (reserved)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
198 |
if sourceuri != 'admin' and sourceuri not in sourcescfg: |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
199 |
break |
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2107
diff
changeset
|
200 |
print '-> uri already used, choose another one.' |
5410
3cccd5e9dd7d
cubicweb-ctl create improvements
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5043
diff
changeset
|
201 |
sourcescfg[sourceuri] = ask_source_config(sourcetype, inputlevel) |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
202 |
sourcemodule = SOURCE_TYPES[sourcetype].module |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
203 |
if not sourcemodule.startswith('cubicweb.'): |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
204 |
# module names look like cubes.mycube.themodule |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
205 |
sourcecube = SOURCE_TYPES[sourcetype].module.split('.', 2)[1] |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
206 |
# if the source adapter is coming from an external component, |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
207 |
# ensure it's specified in used cubes |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
208 |
if not sourcecube in cubes: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
209 |
cubes.append(sourcecube) |
0 | 210 |
sconfig = Configuration(options=USER_OPTIONS) |
211 |
sconfig.input_config(inputlevel=inputlevel) |
|
212 |
sourcescfg['admin'] = sconfig |
|
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
213 |
config.write_sources_file(sourcescfg) |
0 | 214 |
# remember selected cubes for later initialization of the database |
215 |
config.write_bootstrap_cubes_file(cubes) |
|
1469 | 216 |
|
0 | 217 |
def postcreate(self): |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2507
diff
changeset
|
218 |
if ASK.confirm('Run db-create to create the system database ?'): |
136
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
219 |
verbosity = (self.config.mode == 'installed') and 'y' or 'n' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
220 |
CWCTL.run(['db-create', self.config.appid, '--verbose=%s' % verbosity]) |
0 | 221 |
else: |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2394
diff
changeset
|
222 |
print ('-> nevermind, you can do it later with ' |
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2394
diff
changeset
|
223 |
'"cubicweb-ctl db-create %s".' % self.config.appid) |
1469 | 224 |
|
0 | 225 |
|
226 |
class RepositoryDeleteHandler(CommandHandler): |
|
227 |
cmdname = 'delete' |
|
228 |
cfgname = 'repository' |
|
229 |
||
230 |
def cleanup(self): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
231 |
"""remove instance's configuration and database""" |
4848
41f84eea63c9
rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4845
diff
changeset
|
232 |
from logilab.database import get_db_helper |
0 | 233 |
source = self.config.sources()['system'] |
234 |
dbname = source['db-name'] |
|
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
235 |
helper = get_db_helper(source['db-driver']) |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2507
diff
changeset
|
236 |
if ASK.confirm('Delete database %s ?' % dbname): |
0 | 237 |
user = source['db-user'] or None |
238 |
cnx = _db_sys_cnx(source, 'DROP DATABASE', user=user) |
|
239 |
cursor = cnx.cursor() |
|
240 |
try: |
|
241 |
cursor.execute('DROP DATABASE %s' % dbname) |
|
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2107
diff
changeset
|
242 |
print '-> database %s dropped.' % dbname |
0 | 243 |
# XXX should check we are not connected as user |
244 |
if user and helper.users_support and \ |
|
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2507
diff
changeset
|
245 |
ASK.confirm('Delete user %s ?' % user, default_is_yes=False): |
0 | 246 |
cursor.execute('DROP USER %s' % user) |
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2107
diff
changeset
|
247 |
print '-> user %s dropped.' % user |
0 | 248 |
cnx.commit() |
249 |
except: |
|
250 |
cnx.rollback() |
|
251 |
raise |
|
252 |
||
1469 | 253 |
|
0 | 254 |
class RepositoryStartHandler(CommandHandler): |
255 |
cmdname = 'start' |
|
256 |
cfgname = 'repository' |
|
257 |
||
5814
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
258 |
def start_server(self, config): |
0 | 259 |
command = ['cubicweb-ctl start-repository '] |
5814
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
260 |
if config.debugmode: |
0 | 261 |
command.append('--debug') |
5990
6f3c77c79a88
[c-c start repo] config log's threshold is upper case while option accepts lower case. This break c-c start of repository instances.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5967
diff
changeset
|
262 |
command.append('--loglevel %s' % config['log-threshold'].lower()) |
5814
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
263 |
command.append(config.appid) |
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2969
diff
changeset
|
264 |
os.system(' '.join(command)) |
1469 | 265 |
|
0 | 266 |
|
267 |
class RepositoryStopHandler(CommandHandler): |
|
268 |
cmdname = 'stop' |
|
269 |
cfgname = 'repository' |
|
270 |
||
271 |
def poststop(self): |
|
5814
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
272 |
"""if pyro is enabled, ensure the repository is correctly unregistered |
0 | 273 |
""" |
274 |
if self.config.pyro_enabled(): |
|
275 |
from cubicweb.server.repository import pyro_unregister |
|
276 |
pyro_unregister(self.config) |
|
1469 | 277 |
|
0 | 278 |
|
279 |
# repository specific commands ################################################ |
|
3954
56a8b14d68aa
properly fail if user has entered wrong connection information for the system database, closes #549136
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3904
diff
changeset
|
280 |
|
5754
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
281 |
def createdb(helper, source, dbcnx, cursor, **kwargs): |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
282 |
if dbcnx.logged_user != source['db-user']: |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
283 |
helper.create_database(cursor, source['db-name'], source['db-user'], |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
284 |
source['db-encoding'], **kwargs) |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
285 |
else: |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
286 |
helper.create_database(cursor, source['db-name'], |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
287 |
dbencoding=source['db-encoding'], **kwargs) |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
288 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
289 |
class CreateInstanceDBCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
290 |
"""Create the system database of an instance (run after 'create'). |
1469 | 291 |
|
0 | 292 |
You will be prompted for a login / password to use to connect to |
293 |
the system database. The given user should have almost all rights |
|
294 |
on the database (ie a super user on the dbms allowed to create |
|
295 |
database, users, languages...). |
|
296 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
297 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
298 |
the identifier of the instance to initialize. |
0 | 299 |
""" |
300 |
name = 'db-create' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
301 |
arguments = '<instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
302 |
min_args = max_args = 1 |
0 | 303 |
options = ( |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
304 |
('create-db', |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
305 |
{'short': 'c', 'type': 'yn', 'metavar': '<y or n>', |
0 | 306 |
'default': True, |
307 |
'help': 'create the database (yes by default)'}), |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
308 |
('verbose', |
136
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
309 |
{'short': 'v', 'type' : 'yn', 'metavar': '<verbose>', |
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
310 |
'default': 'n', |
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
311 |
'help': 'verbose mode: will ask all possible configuration questions', |
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
312 |
} |
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
313 |
), |
2969
d95f23a0fc3b
F add --automatic/-a option to run db-create without user input
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2851
diff
changeset
|
314 |
('automatic', |
d95f23a0fc3b
F add --automatic/-a option to run db-create without user input
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2851
diff
changeset
|
315 |
{'short': 'a', 'type' : 'yn', 'metavar': '<auto>', |
d95f23a0fc3b
F add --automatic/-a option to run db-create without user input
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2851
diff
changeset
|
316 |
'default': 'n', |
d95f23a0fc3b
F add --automatic/-a option to run db-create without user input
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2851
diff
changeset
|
317 |
'help': 'automatic mode: never ask and use default answer to every question', |
d95f23a0fc3b
F add --automatic/-a option to run db-create without user input
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2851
diff
changeset
|
318 |
} |
d95f23a0fc3b
F add --automatic/-a option to run db-create without user input
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2851
diff
changeset
|
319 |
), |
0 | 320 |
) |
321 |
def run(self, args): |
|
322 |
"""run the command with its specific arguments""" |
|
4848
41f84eea63c9
rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4845
diff
changeset
|
323 |
from logilab.database import get_db_helper |
136
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
324 |
verbose = self.get('verbose') |
2969
d95f23a0fc3b
F add --automatic/-a option to run db-create without user input
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2851
diff
changeset
|
325 |
automatic = self.get('automatic') |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
326 |
appid = args.pop() |
0 | 327 |
config = ServerConfiguration.config_for(appid) |
328 |
source = config.sources()['system'] |
|
4197
5446c74189b6
quick and dirty fix to avoid crash when running db-create command with an sqlite source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4180
diff
changeset
|
329 |
dbname = source['db-name'] |
0 | 330 |
driver = source['db-driver'] |
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
331 |
helper = get_db_helper(driver) |
4197
5446c74189b6
quick and dirty fix to avoid crash when running db-create command with an sqlite source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4180
diff
changeset
|
332 |
if driver == 'sqlite': |
5585
e1cbf6b304ea
[sqlite] fix crash on db-create with sqlite abd unexistent database due to missing paren in logical expression (closes #909604)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5553
diff
changeset
|
333 |
if os.path.exists(dbname) and ( |
e1cbf6b304ea
[sqlite] fix crash on db-create with sqlite abd unexistent database due to missing paren in logical expression (closes #909604)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5553
diff
changeset
|
334 |
automatic or |
e1cbf6b304ea
[sqlite] fix crash on db-create with sqlite abd unexistent database due to missing paren in logical expression (closes #909604)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5553
diff
changeset
|
335 |
ASK.confirm('Database %s already exists. Drop it?' % dbname)): |
4197
5446c74189b6
quick and dirty fix to avoid crash when running db-create command with an sqlite source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4180
diff
changeset
|
336 |
os.unlink(dbname) |
5754
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
337 |
elif self.config.create_db: |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
338 |
print '\n'+underline_title('Creating the system database') |
0 | 339 |
# connect on the dbms system base to create our base |
136
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
340 |
dbcnx = _db_sys_cnx(source, 'CREATE DATABASE and / or USER', verbose=verbose) |
0 | 341 |
cursor = dbcnx.cursor() |
342 |
try: |
|
343 |
if helper.users_support: |
|
344 |
user = source['db-user'] |
|
2969
d95f23a0fc3b
F add --automatic/-a option to run db-create without user input
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2851
diff
changeset
|
345 |
if not helper.user_exists(cursor, user) and (automatic or \ |
d95f23a0fc3b
F add --automatic/-a option to run db-create without user input
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2851
diff
changeset
|
346 |
ASK.confirm('Create db user %s ?' % user, default_is_yes=False)): |
0 | 347 |
helper.create_user(source['db-user'], source['db-password']) |
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2107
diff
changeset
|
348 |
print '-> user %s created.' % user |
0 | 349 |
if dbname in helper.list_databases(cursor): |
2969
d95f23a0fc3b
F add --automatic/-a option to run db-create without user input
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2851
diff
changeset
|
350 |
if automatic or ASK.confirm('Database %s already exists -- do you want to drop it ?' % dbname): |
0 | 351 |
cursor.execute('DROP DATABASE %s' % dbname) |
352 |
else: |
|
353 |
return |
|
5754
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
354 |
createdb(helper, source, dbcnx, cursor) |
0 | 355 |
dbcnx.commit() |
4197
5446c74189b6
quick and dirty fix to avoid crash when running db-create command with an sqlite source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4180
diff
changeset
|
356 |
print '-> database %s created.' % dbname |
0 | 357 |
except: |
358 |
dbcnx.rollback() |
|
359 |
raise |
|
1469 | 360 |
cnx = system_source_cnx(source, special_privs='LANGUAGE C', verbose=verbose) |
0 | 361 |
cursor = cnx.cursor() |
4886
18a1735c283c
[db creation] fix some bugs introduced by the migration to logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4848
diff
changeset
|
362 |
helper.init_fti_extensions(cursor) |
1469 | 363 |
# postgres specific stuff |
0 | 364 |
if driver == 'postgres': |
365 |
# install plpythonu/plpgsql language if not installed by the cube |
|
3303 | 366 |
langs = sys.platform == 'win32' and ('plpgsql',) or ('plpythonu', 'plpgsql') |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2969
diff
changeset
|
367 |
for extlang in langs: |
0 | 368 |
helper.create_language(cursor, extlang) |
369 |
cursor.close() |
|
370 |
cnx.commit() |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
371 |
print '-> database for instance %s created and necessary extensions installed.' % appid |
0 | 372 |
print |
2969
d95f23a0fc3b
F add --automatic/-a option to run db-create without user input
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2851
diff
changeset
|
373 |
if automatic or ASK.confirm('Run db-init to initialize the system database ?'): |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
374 |
CWCTL.run(['db-init', config.appid]) |
0 | 375 |
else: |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2394
diff
changeset
|
376 |
print ('-> nevermind, you can do it later with ' |
3893 | 377 |
'"cubicweb-ctl db-init %s".' % config.appid) |
0 | 378 |
|
1469 | 379 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
380 |
class InitInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
381 |
"""Initialize the system database of an instance (run after 'db-create'). |
1469 | 382 |
|
0 | 383 |
You will be prompted for a login / password to use to connect to |
384 |
the system database. The given user should have the create tables, |
|
385 |
and grant permissions. |
|
386 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
387 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
388 |
the identifier of the instance to initialize. |
0 | 389 |
""" |
390 |
name = 'db-init' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
391 |
arguments = '<instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
392 |
min_args = max_args = 1 |
0 | 393 |
options = ( |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
394 |
('drop', |
0 | 395 |
{'short': 'd', 'action': 'store_true', |
396 |
'default': False, |
|
397 |
'help': 'insert drop statements to remove previously existant \ |
|
398 |
tables, indexes... (no by default)'}), |
|
399 |
) |
|
400 |
||
401 |
def run(self, args): |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
402 |
print '\n'+underline_title('Initializing the system database') |
0 | 403 |
from cubicweb.server import init_repository |
5586
aabe082fee02
[c-c] use logilab.database, not lgc.db
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5585
diff
changeset
|
404 |
from logilab.database import get_connection |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
405 |
appid = args[0] |
0 | 406 |
config = ServerConfiguration.config_for(appid) |
3954
56a8b14d68aa
properly fail if user has entered wrong connection information for the system database, closes #549136
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3904
diff
changeset
|
407 |
try: |
56a8b14d68aa
properly fail if user has entered wrong connection information for the system database, closes #549136
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3904
diff
changeset
|
408 |
system = config.sources()['system'] |
4180
9fb0d06926cc
more extra_args cleanup
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4177
diff
changeset
|
409 |
extra_args=system.get('db-extra-arguments') |
9fb0d06926cc
more extra_args cleanup
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4177
diff
changeset
|
410 |
extra = extra_args and {'extra_args': extra_args} or {} |
3954
56a8b14d68aa
properly fail if user has entered wrong connection information for the system database, closes #549136
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3904
diff
changeset
|
411 |
get_connection( |
56a8b14d68aa
properly fail if user has entered wrong connection information for the system database, closes #549136
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3904
diff
changeset
|
412 |
system['db-driver'], database=system['db-name'], |
56a8b14d68aa
properly fail if user has entered wrong connection information for the system database, closes #549136
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3904
diff
changeset
|
413 |
host=system.get('db-host'), port=system.get('db-port'), |
5043
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5033
diff
changeset
|
414 |
user=system.get('db-user'), password=system.get('db-password'), |
4180
9fb0d06926cc
more extra_args cleanup
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4177
diff
changeset
|
415 |
**extra) |
3954
56a8b14d68aa
properly fail if user has entered wrong connection information for the system database, closes #549136
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3904
diff
changeset
|
416 |
except Exception, ex: |
56a8b14d68aa
properly fail if user has entered wrong connection information for the system database, closes #549136
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3904
diff
changeset
|
417 |
raise ConfigurationError( |
56a8b14d68aa
properly fail if user has entered wrong connection information for the system database, closes #549136
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3904
diff
changeset
|
418 |
'You seem to have provided wrong connection information in '\ |
56a8b14d68aa
properly fail if user has entered wrong connection information for the system database, closes #549136
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3904
diff
changeset
|
419 |
'the %s file. Resolve this first (error: %s).' |
56a8b14d68aa
properly fail if user has entered wrong connection information for the system database, closes #549136
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3904
diff
changeset
|
420 |
% (config.sources_file(), str(ex).strip())) |
0 | 421 |
init_repository(config, drop=self.config.drop) |
422 |
||
423 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
424 |
class GrantUserOnInstanceCommand(Command): |
0 | 425 |
"""Grant a database user on a repository system database. |
1469 | 426 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
427 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
428 |
the identifier of the instance |
0 | 429 |
<user> |
430 |
the database's user requiring grant access |
|
431 |
""" |
|
432 |
name = 'db-grant-user' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
433 |
arguments = '<instance> <user>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
434 |
min_args = max_args = 2 |
0 | 435 |
options = ( |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
436 |
('set-owner', |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
437 |
{'short': 'o', 'type' : 'yn', 'metavar' : '<yes or no>', |
0 | 438 |
'default' : False, |
439 |
'help': 'Set the user as tables owner if yes (no by default).'} |
|
440 |
), |
|
441 |
) |
|
442 |
def run(self, args): |
|
443 |
"""run the command with its specific arguments""" |
|
444 |
from cubicweb.server.sqlutils import sqlexec, sqlgrants |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
445 |
appid, user = args |
0 | 446 |
config = ServerConfiguration.config_for(appid) |
447 |
source = config.sources()['system'] |
|
448 |
set_owner = self.config.set_owner |
|
449 |
cnx = system_source_cnx(source, special_privs='GRANT') |
|
450 |
cursor = cnx.cursor() |
|
451 |
schema = config.load_schema() |
|
452 |
try: |
|
453 |
sqlexec(sqlgrants(schema, source['db-driver'], user, |
|
454 |
set_owner=set_owner), cursor) |
|
455 |
except Exception, ex: |
|
456 |
cnx.rollback() |
|
457 |
import traceback |
|
458 |
traceback.print_exc() |
|
6109
47d9c0e0f7b7
integrate Celso's work on translation file: proper/complete spanish translation, fixed some typos in french translation, occured -> occurred fix in various places
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6072
diff
changeset
|
459 |
print '-> an error occurred:', ex |
0 | 460 |
else: |
461 |
cnx.commit() |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
462 |
print '-> rights granted to %s on instance %s.' % (appid, user) |
0 | 463 |
|
3954
56a8b14d68aa
properly fail if user has entered wrong connection information for the system database, closes #549136
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3904
diff
changeset
|
464 |
|
1912
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
465 |
class ResetAdminPasswordCommand(Command): |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
466 |
"""Reset the administrator password. |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
467 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
468 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
469 |
the identifier of the instance |
1912
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
470 |
""" |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
471 |
name = 'reset-admin-pwd' |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
472 |
arguments = '<instance>' |
1912
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
473 |
|
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
474 |
def run(self, args): |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
475 |
"""run the command with its specific arguments""" |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
476 |
from cubicweb.server.utils import crypt_password, manager_userpasswd |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
477 |
appid = args[0] |
1912
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
478 |
config = ServerConfiguration.config_for(appid) |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
479 |
sourcescfg = config.read_sources_file() |
1912
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
480 |
try: |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
481 |
adminlogin = sourcescfg['admin']['login'] |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
482 |
except KeyError: |
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2107
diff
changeset
|
483 |
print '-> Error: could not get cubicweb administrator login.' |
1912
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
484 |
sys.exit(1) |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
485 |
cnx = source_cnx(sourcescfg['system']) |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
486 |
cursor = cnx.cursor() |
4670
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
487 |
# check admin exists |
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
488 |
cursor.execute("SELECT * FROM cw_CWUser WHERE cw_login=%(l)s", |
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
489 |
{'l': adminlogin}) |
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
490 |
if not cursor.fetchall(): |
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
491 |
print ("-> error: admin user %r specified in sources doesn't exist " |
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
492 |
"in the database" % adminlogin) |
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
493 |
print " fix your sources file before running this command" |
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
494 |
cnx.close() |
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
495 |
sys.exit(1) |
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
496 |
# ask for a new password |
1912
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
497 |
_, passwd = manager_userpasswd(adminlogin, confirm=True, |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
498 |
passwdmsg='new password for %s' % adminlogin) |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
499 |
try: |
4670
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
500 |
cursor.execute("UPDATE cw_CWUser SET cw_upassword=%(p)s WHERE cw_login=%(l)s", |
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
501 |
{'p': crypt_password(passwd), 'l': adminlogin}) |
1912
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
502 |
sconfig = Configuration(options=USER_OPTIONS) |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
503 |
sconfig['login'] = adminlogin |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
504 |
sconfig['password'] = passwd |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
505 |
sourcescfg['admin'] = sconfig |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1980
diff
changeset
|
506 |
config.write_sources_file(sourcescfg) |
1912
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
507 |
except Exception, ex: |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
508 |
cnx.rollback() |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
509 |
import traceback |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
510 |
traceback.print_exc() |
6109
47d9c0e0f7b7
integrate Celso's work on translation file: proper/complete spanish translation, fixed some typos in french translation, occured -> occurred fix in various places
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6072
diff
changeset
|
511 |
print '-> an error occurred:', ex |
1912
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
512 |
else: |
2b9432262240
[server] provide a new reset-admin-pwd command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1682
diff
changeset
|
513 |
cnx.commit() |
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2107
diff
changeset
|
514 |
print '-> password reset, sources file regenerated.' |
4670
48ba6f820fae
fix #615379 by checking admin user exists instead of making think everything is fine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
515 |
cnx.close() |
0 | 516 |
|
1469 | 517 |
|
0 | 518 |
class StartRepositoryCommand(Command): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
519 |
"""Start an CubicWeb RQL server for a given instance. |
1469 | 520 |
|
0 | 521 |
The server will be accessible through pyro |
522 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
523 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
524 |
the identifier of the instance to initialize. |
0 | 525 |
""" |
526 |
name = 'start-repository' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
527 |
arguments = '<instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
528 |
min_args = max_args = 1 |
0 | 529 |
options = ( |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
530 |
('debug', |
0 | 531 |
{'short': 'D', 'action' : 'store_true', |
532 |
'help': 'start server in debug mode.'}), |
|
5814
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
533 |
('loglevel', |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
534 |
{'short': 'l', 'type' : 'choice', 'metavar': '<log level>', |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
535 |
'default': None, 'choices': ('debug', 'info', 'warning', 'error'), |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
536 |
'help': 'debug if -D is set, error otherwise', |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
537 |
}), |
0 | 538 |
) |
539 |
||
540 |
def run(self, args): |
|
5553 | 541 |
from logilab.common.daemon import daemonize |
5814
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
542 |
from cubicweb.cwctl import init_cmdline_log_threshold |
0 | 543 |
from cubicweb.server.server import RepositoryServer |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
544 |
appid = args[0] |
5814
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
545 |
debug = self['debug'] |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
546 |
if sys.platform == 'win32' and not debug: |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
547 |
from logging import getLogger |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
548 |
logger = getLogger('cubicweb.ctl') |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
549 |
logger.info('Forcing debug mode on win32 platform') |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
550 |
debug = True |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
551 |
config = ServerConfiguration.config_for(appid, debugmode=debug) |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
552 |
init_cmdline_log_threshold(config, self['loglevel']) |
0 | 553 |
# create the server |
5814
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5754
diff
changeset
|
554 |
server = RepositoryServer(config) |
2711
7aee3bd7a704
ensure runtime dir exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2682
diff
changeset
|
555 |
# ensure the directory where the pid-file should be set exists (for |
7aee3bd7a704
ensure runtime dir exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2682
diff
changeset
|
556 |
# instance /var/run/cubicweb may be deleted on computer restart) |
5692
59ceed788bdb
[repo server] fix startup bug, lgc.daemon.daemonize return 1 for the parent process, not -1
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5586
diff
changeset
|
557 |
pidfile = config['pid-file'] |
2711
7aee3bd7a704
ensure runtime dir exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2682
diff
changeset
|
558 |
piddir = os.path.dirname(pidfile) |
5692
59ceed788bdb
[repo server] fix startup bug, lgc.daemon.daemonize return 1 for the parent process, not -1
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5586
diff
changeset
|
559 |
# go ! (don't daemonize in debug mode) |
2711
7aee3bd7a704
ensure runtime dir exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2682
diff
changeset
|
560 |
if not os.path.exists(piddir): |
7aee3bd7a704
ensure runtime dir exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2682
diff
changeset
|
561 |
os.makedirs(piddir) |
5692
59ceed788bdb
[repo server] fix startup bug, lgc.daemon.daemonize return 1 for the parent process, not -1
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5586
diff
changeset
|
562 |
if not debug and daemonize(pidfile): |
0 | 563 |
return |
564 |
uid = config['uid'] |
|
565 |
if uid is not None: |
|
566 |
try: |
|
567 |
uid = int(uid) |
|
568 |
except ValueError: |
|
569 |
from pwd import getpwnam |
|
570 |
uid = getpwnam(uid).pw_uid |
|
571 |
os.setuid(uid) |
|
572 |
server.install_sig_handlers() |
|
573 |
server.connect(config['host'], 0) |
|
574 |
server.run() |
|
575 |
||
576 |
||
577 |
def _remote_dump(host, appid, output, sudo=False): |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
578 |
# XXX generate unique/portable file name |
2837
65df5df190a5
B [cwctl] fix db-{dump,copy,restore} commands
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2711
diff
changeset
|
579 |
from datetime import date |
65df5df190a5
B [cwctl] fix db-{dump,copy,restore} commands
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2711
diff
changeset
|
580 |
filename = '%s-%s.tgz' % (appid, date.today().strftime('%Y-%m-%d')) |
65df5df190a5
B [cwctl] fix db-{dump,copy,restore} commands
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2711
diff
changeset
|
581 |
dmpcmd = 'cubicweb-ctl db-dump -o /tmp/%s %s' % (filename, appid) |
0 | 582 |
if sudo: |
583 |
dmpcmd = 'sudo %s' % (dmpcmd) |
|
584 |
dmpcmd = 'ssh -t %s "%s"' % (host, dmpcmd) |
|
585 |
print dmpcmd |
|
586 |
if os.system(dmpcmd): |
|
587 |
raise ExecutionError('Error while dumping the database') |
|
588 |
if output is None: |
|
2837
65df5df190a5
B [cwctl] fix db-{dump,copy,restore} commands
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2711
diff
changeset
|
589 |
output = filename |
65df5df190a5
B [cwctl] fix db-{dump,copy,restore} commands
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2711
diff
changeset
|
590 |
cmd = 'scp %s:/tmp/%s %s' % (host, filename, output) |
0 | 591 |
print cmd |
592 |
if os.system(cmd): |
|
2837
65df5df190a5
B [cwctl] fix db-{dump,copy,restore} commands
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2711
diff
changeset
|
593 |
raise ExecutionError('Error while retrieving the dump at /tmp/%s' % filename) |
65df5df190a5
B [cwctl] fix db-{dump,copy,restore} commands
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2711
diff
changeset
|
594 |
rmcmd = 'ssh -t %s "rm -f /tmp/%s"' % (host, filename) |
0 | 595 |
print rmcmd |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2507
diff
changeset
|
596 |
if os.system(rmcmd) and not ASK.confirm( |
6109
47d9c0e0f7b7
integrate Celso's work on translation file: proper/complete spanish translation, fixed some typos in french translation, occured -> occurred fix in various places
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6072
diff
changeset
|
597 |
'An error occurred while deleting remote dump at /tmp/%s. ' |
2837
65df5df190a5
B [cwctl] fix db-{dump,copy,restore} commands
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2711
diff
changeset
|
598 |
'Continue anyway?' % filename): |
65df5df190a5
B [cwctl] fix db-{dump,copy,restore} commands
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2711
diff
changeset
|
599 |
raise ExecutionError('Error while deleting remote dump at /tmp/%s' % filename) |
0 | 600 |
|
601 |
def _local_dump(appid, output): |
|
602 |
config = ServerConfiguration.config_for(appid) |
|
5043
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5033
diff
changeset
|
603 |
config.quick_start = True |
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5033
diff
changeset
|
604 |
mih = config.migration_handler(connect=False, verbosity=1) |
0 | 605 |
mih.backup_database(output, askconfirm=False) |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
606 |
mih.shutdown() |
0 | 607 |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
608 |
def _local_restore(appid, backupfile, drop, systemonly=True): |
0 | 609 |
config = ServerConfiguration.config_for(appid) |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
610 |
config.verbosity = 1 # else we won't be asked for confirmation on problems |
5043
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5033
diff
changeset
|
611 |
config.quick_start = True |
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5033
diff
changeset
|
612 |
mih = config.migration_handler(connect=False, verbosity=1) |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
613 |
mih.restore_database(backupfile, drop, systemonly, askconfirm=False) |
0 | 614 |
repo = mih.repo_connect() |
615 |
# version of the database |
|
616 |
dbversions = repo.get_versions() |
|
617 |
mih.shutdown() |
|
618 |
if not dbversions: |
|
619 |
print "bad or missing version information in the database, don't upgrade file system" |
|
620 |
return |
|
621 |
# version of installed software |
|
622 |
eversion = dbversions['cubicweb'] |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
623 |
status = instance_status(config, eversion, dbversions) |
0 | 624 |
# * database version > installed software |
625 |
if status == 'needsoftupgrade': |
|
2851
d3b80a4faf3f
F [cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2837
diff
changeset
|
626 |
print "** The database of %s is more recent than the installed software!" % config.appid |
d3b80a4faf3f
F [cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2837
diff
changeset
|
627 |
print "** Upgrade your software, then migrate the database by running the command" |
d3b80a4faf3f
F [cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2837
diff
changeset
|
628 |
print "** 'cubicweb-ctl upgrade %s'" % config.appid |
0 | 629 |
return |
630 |
# * database version < installed software, an upgrade will be necessary |
|
631 |
# anyway, just rewrite vc.conf and warn user he has to upgrade |
|
2851
d3b80a4faf3f
F [cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2837
diff
changeset
|
632 |
elif status == 'needapplupgrade': |
d3b80a4faf3f
F [cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2837
diff
changeset
|
633 |
print "** The database of %s is older than the installed software." % config.appid |
d3b80a4faf3f
F [cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2837
diff
changeset
|
634 |
print "** Migrate the database by running the command" |
d3b80a4faf3f
F [cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2837
diff
changeset
|
635 |
print "** 'cubicweb-ctl upgrade %s'" % config.appid |
0 | 636 |
return |
637 |
# * database version = installed software, database version = instance fs version |
|
638 |
# ok! |
|
639 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
640 |
def instance_status(config, cubicwebapplversion, vcconf): |
0 | 641 |
cubicwebversion = config.cubicweb_version() |
642 |
if cubicwebapplversion > cubicwebversion: |
|
643 |
return 'needsoftupgrade' |
|
644 |
if cubicwebapplversion < cubicwebversion: |
|
645 |
return 'needapplupgrade' |
|
646 |
for cube in config.cubes(): |
|
647 |
try: |
|
648 |
softversion = config.cube_version(cube) |
|
649 |
except ConfigurationError: |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
650 |
print '-> Error: no cube version information for %s, please check that the cube is installed.' % cube |
0 | 651 |
continue |
652 |
try: |
|
653 |
applversion = vcconf[cube] |
|
654 |
except KeyError: |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
655 |
print '-> Error: no cube version information for %s in version configuration.' % cube |
1469 | 656 |
continue |
0 | 657 |
if softversion == applversion: |
658 |
continue |
|
659 |
if softversion > applversion: |
|
660 |
return 'needsoftupgrade' |
|
661 |
elif softversion < applversion: |
|
662 |
return 'needapplupgrade' |
|
663 |
return None |
|
1469 | 664 |
|
0 | 665 |
|
666 |
class DBDumpCommand(Command): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
667 |
"""Backup the system database of an instance. |
1469 | 668 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
669 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
670 |
the identifier of the instance to backup |
0 | 671 |
format [[user@]host:]appname |
672 |
""" |
|
673 |
name = 'db-dump' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
674 |
arguments = '<instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
675 |
min_args = max_args = 1 |
0 | 676 |
options = ( |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
677 |
('output', |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
678 |
{'short': 'o', 'type' : 'string', 'metavar' : '<file>', |
0 | 679 |
'default' : None, |
680 |
'help': 'Specify the backup file where the backup will be stored.'} |
|
681 |
), |
|
682 |
('sudo', |
|
683 |
{'short': 's', 'action' : 'store_true', |
|
684 |
'default' : False, |
|
685 |
'help': 'Use sudo on the remote host.'} |
|
686 |
), |
|
687 |
) |
|
688 |
||
689 |
def run(self, args): |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
690 |
appid = args[0] |
0 | 691 |
if ':' in appid: |
692 |
host, appid = appid.split(':') |
|
693 |
_remote_dump(host, appid, self.config.output, self.config.sudo) |
|
694 |
else: |
|
695 |
_local_dump(appid, self.config.output) |
|
696 |
||
697 |
||
698 |
class DBRestoreCommand(Command): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
699 |
"""Restore the system database of an instance. |
1469 | 700 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
701 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
702 |
the identifier of the instance to restore |
0 | 703 |
""" |
704 |
name = 'db-restore' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
705 |
arguments = '<instance> <backupfile>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
706 |
min_args = max_args = 2 |
0 | 707 |
|
708 |
options = ( |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
709 |
('no-drop', |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
710 |
{'short': 'n', 'action' : 'store_true', 'default' : False, |
0 | 711 |
'help': 'for some reason the database doesn\'t exist and so ' |
712 |
'should not be dropped.'} |
|
713 |
), |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
714 |
('restore-all', |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
715 |
{'short': 'r', 'action' : 'store_true', 'default' : False, |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
716 |
'help': 'restore everything, eg not only the system source database ' |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
717 |
'but also data for all sources supporting backup/restore and custom ' |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
718 |
'instance data. In that case, <backupfile> is expected to be the ' |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
719 |
'timestamp of the backup to restore, not a file'} |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
720 |
), |
0 | 721 |
) |
722 |
||
723 |
def run(self, args): |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
724 |
appid, backupfile = args |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
725 |
_local_restore(appid, backupfile, |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
726 |
drop=not self.config.no_drop, |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
727 |
systemonly=not self.config.restore_all) |
0 | 728 |
|
729 |
||
730 |
class DBCopyCommand(Command): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
731 |
"""Copy the system database of an instance (backup and restore). |
1469 | 732 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
733 |
<src-instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
734 |
the identifier of the instance to backup |
0 | 735 |
format [[user@]host:]appname |
736 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
737 |
<dest-instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
738 |
the identifier of the instance to restore |
0 | 739 |
""" |
740 |
name = 'db-copy' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
741 |
arguments = '<src-instance> <dest-instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
742 |
min_args = max_args = 2 |
0 | 743 |
options = ( |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
744 |
('no-drop', |
1469 | 745 |
{'short': 'n', 'action' : 'store_true', |
0 | 746 |
'default' : False, |
747 |
'help': 'For some reason the database doesn\'t exist and so ' |
|
748 |
'should not be dropped.'} |
|
749 |
), |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
750 |
('keep-dump', |
0 | 751 |
{'short': 'k', 'action' : 'store_true', |
752 |
'default' : False, |
|
753 |
'help': 'Specify that the dump file should not be automatically removed.'} |
|
754 |
), |
|
755 |
('sudo', |
|
756 |
{'short': 's', 'action' : 'store_true', |
|
757 |
'default' : False, |
|
758 |
'help': 'Use sudo on the remote host.'} |
|
759 |
), |
|
760 |
) |
|
761 |
||
762 |
def run(self, args): |
|
763 |
import tempfile |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
764 |
srcappid, destappid = args |
3148 | 765 |
fd, output = tempfile.mkstemp() |
766 |
os.close(fd) |
|
0 | 767 |
if ':' in srcappid: |
768 |
host, srcappid = srcappid.split(':') |
|
769 |
_remote_dump(host, srcappid, output, self.config.sudo) |
|
770 |
else: |
|
771 |
_local_dump(srcappid, output) |
|
772 |
_local_restore(destappid, output, not self.config.no_drop) |
|
773 |
if self.config.keep_dump: |
|
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2107
diff
changeset
|
774 |
print '-> you can get the dump file at', output |
0 | 775 |
else: |
776 |
os.remove(output) |
|
777 |
||
1469 | 778 |
|
0 | 779 |
class CheckRepositoryCommand(Command): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
780 |
"""Check integrity of the system database of an instance. |
1469 | 781 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
782 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
783 |
the identifier of the instance to check |
0 | 784 |
""" |
785 |
name = 'db-check' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
786 |
arguments = '<instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
787 |
min_args = max_args = 1 |
0 | 788 |
options = ( |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
789 |
('checks', |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
790 |
{'short': 'c', 'type' : 'csv', 'metavar' : '<check list>', |
0 | 791 |
'default' : ('entities', 'relations', 'metadata', 'schema', 'text_index'), |
792 |
'help': 'Comma separated list of check to run. By default run all \ |
|
793 |
checks, i.e. entities, relations, text_index and metadata.'} |
|
794 |
), |
|
1469 | 795 |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
796 |
('autofix', |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
797 |
{'short': 'a', 'type' : 'yn', 'metavar' : '<yes or no>', |
0 | 798 |
'default' : False, |
799 |
'help': 'Automatically correct integrity problems if this option \ |
|
800 |
is set to "y" or "yes", else only display them'} |
|
801 |
), |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
802 |
('reindex', |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
803 |
{'short': 'r', 'type' : 'yn', 'metavar' : '<yes or no>', |
0 | 804 |
'default' : False, |
805 |
'help': 're-indexes the database for full text search if this \ |
|
806 |
option is set to "y" or "yes" (may be long for large database).'} |
|
807 |
), |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
808 |
('force', |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
809 |
{'short': 'f', 'action' : 'store_true', |
2473
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2461
diff
changeset
|
810 |
'default' : False, |
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2461
diff
changeset
|
811 |
'help': 'don\'t check instance is up to date.'} |
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2461
diff
changeset
|
812 |
), |
1469 | 813 |
|
0 | 814 |
) |
815 |
||
816 |
def run(self, args): |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
817 |
appid = args[0] |
0 | 818 |
config = ServerConfiguration.config_for(appid) |
2473
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2461
diff
changeset
|
819 |
config.repairing = self.config.force |
0 | 820 |
repo, cnx = repo_cnx(config) |
821 |
check(repo, cnx, |
|
822 |
self.config.checks, self.config.reindex, self.config.autofix) |
|
823 |
||
824 |
||
825 |
class RebuildFTICommand(Command): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
826 |
"""Rebuild the full-text index of the system database of an instance. |
1469 | 827 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
828 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
829 |
the identifier of the instance to rebuild |
0 | 830 |
""" |
831 |
name = 'db-rebuild-fti' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
832 |
arguments = '<instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
833 |
min_args = max_args = 1 |
0 | 834 |
|
835 |
def run(self, args): |
|
836 |
from cubicweb.server.checkintegrity import reindex_entities |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
837 |
appid = args[0] |
0 | 838 |
config = ServerConfiguration.config_for(appid) |
839 |
repo, cnx = repo_cnx(config) |
|
840 |
session = repo._get_session(cnx.sessionid, setpool=True) |
|
841 |
reindex_entities(repo.schema, session) |
|
842 |
cnx.commit() |
|
843 |
||
1469 | 844 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
845 |
class SynchronizeInstanceSchemaCommand(Command): |
0 | 846 |
"""Synchronize persistent schema with cube schema. |
1469 | 847 |
|
0 | 848 |
Will synchronize common stuff between the cube schema and the |
849 |
actual persistent schema, but will not add/remove any entity or relation. |
|
850 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
851 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
852 |
the identifier of the instance to synchronize. |
0 | 853 |
""" |
854 |
name = 'schema-sync' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
855 |
arguments = '<instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
856 |
min_args = max_args = 1 |
0 | 857 |
|
858 |
def run(self, args): |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
859 |
appid = args[0] |
0 | 860 |
config = ServerConfiguration.config_for(appid) |
861 |
mih = config.migration_handler() |
|
862 |
mih.cmd_synchronize_schema() |
|
863 |
||
864 |
||
6127
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
865 |
class CheckMappingCommand(Command): |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
866 |
"""Check content of the mapping file of an external source. |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
867 |
|
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
868 |
The mapping is checked against the instance's schema, searching for |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
869 |
inconsistencies or stuff you may have forgotten. It's higly recommanded to |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
870 |
run it when you setup a multi-sources instance. |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
871 |
|
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
872 |
<instance> |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
873 |
the identifier of the instance. |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
874 |
|
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
875 |
<mapping file> |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
876 |
the mapping file to check. |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
877 |
""" |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
878 |
name = 'check-mapping' |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
879 |
arguments = '<instance> <mapping file>' |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
880 |
min_args = max_args = 2 |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
881 |
|
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
882 |
def run(self, args): |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
883 |
from cubicweb.server.checkintegrity import check_mapping |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
884 |
from cubicweb.server.sources.pyrorql import load_mapping_file |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
885 |
appid, mappingfile = args |
6127
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
886 |
config = ServerConfiguration.config_for(appid) |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
887 |
config.quick_start = True |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
888 |
mih = config.migration_handler(connect=False, verbosity=1) |
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
889 |
repo = mih.repo_connect() # necessary to get cubes |
6132
440df442d705
[c-c check-mapping] fix dumb name error and add a warning about inlined crossed relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6127
diff
changeset
|
890 |
check_mapping(config.load_schema(), load_mapping_file(mappingfile)) |
6127
747e423093fc
[ms, c-c] new command checking for consistency / potentian flaws and enhancements of mapping file of a multi-sources instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
891 |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
892 |
for cmdclass in (CreateInstanceDBCommand, InitInstanceCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
893 |
GrantUserOnInstanceCommand, ResetAdminPasswordCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
894 |
StartRepositoryCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
895 |
DBDumpCommand, DBRestoreCommand, DBCopyCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
896 |
CheckRepositoryCommand, RebuildFTICommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
897 |
SynchronizeInstanceSchemaCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
898 |
CheckMappingCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
899 |
): |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6132
diff
changeset
|
900 |
CWCTL.register(cmdclass) |