author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 08 Dec 2009 09:41:06 +0100 | |
changeset 4017 | a5b4d4f2a1c7 |
parent 4011 | 394f853bb653 |
child 4021 | 280c910c8710 |
permissions | -rw-r--r-- |
0 | 1 |
"""a class implementing basic actions used in migration scripts. |
2 |
||
3 |
The following schema actions are supported for now: |
|
4 |
* add/drop/rename attribute |
|
5 |
* add/drop entity/relation type |
|
6 |
* rename entity type |
|
7 |
||
8 |
The following data actions are supported for now: |
|
9 |
* add an entity |
|
10 |
* execute raw RQL queries |
|
11 |
||
12 |
||
13 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1790
diff
changeset
|
14 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 15 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1790
diff
changeset
|
16 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 17 |
""" |
18 |
__docformat__ = "restructuredtext en" |
|
19 |
||
20 |
import sys |
|
21 |
import os |
|
2759
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
22 |
import tarfile |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
23 |
import tempfile |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
24 |
import shutil |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
25 |
import os.path as osp |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
26 |
from datetime import datetime |
3903
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
27 |
from glob import glob |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
28 |
from warnings import warn |
0 | 29 |
|
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2493
diff
changeset
|
30 |
from logilab.common.deprecation import deprecated |
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
31 |
from logilab.common.decorators import cached, clear_cache |
0 | 32 |
from logilab.common.adbh import get_adv_func_helper |
33 |
||
34 |
from yams.constraints import SizeConstraint |
|
35 |
from yams.schema2sql import eschema2sql, rschema2sql |
|
36 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
37 |
from cubicweb import AuthenticationError, ETYPE_NAME_MAP |
2926
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
38 |
from cubicweb.schema import (META_RTYPES, VIRTUAL_RTYPES, |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
39 |
CubicWebRelationSchema, order_eschemas) |
0 | 40 |
from cubicweb.dbapi import get_repository, repo_connect |
41 |
from cubicweb.common.migration import MigrationHelper, yes |
|
42 |
||
43 |
try: |
|
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
44 |
from cubicweb.server import SOURCE_TYPES, schemaserial as ss |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
45 |
from cubicweb.server.utils import manager_userpasswd, ask_source_config |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1240
diff
changeset
|
46 |
from cubicweb.server.sqlutils import sqlexec, SQL_PREFIX |
0 | 47 |
except ImportError: # LAX |
48 |
pass |
|
49 |
||
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1240
diff
changeset
|
50 |
|
0 | 51 |
class ServerMigrationHelper(MigrationHelper): |
52 |
"""specific migration helper for server side migration scripts, |
|
53 |
providind actions related to schema/data migration |
|
54 |
""" |
|
55 |
||
56 |
def __init__(self, config, schema, interactive=True, |
|
57 |
repo=None, cnx=None, verbosity=1, connect=True): |
|
58 |
MigrationHelper.__init__(self, config, interactive, verbosity) |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
59 |
# no config on shell to a remote instance |
0 | 60 |
if not interactive: |
61 |
assert cnx |
|
62 |
assert repo |
|
63 |
if cnx is not None: |
|
64 |
assert repo |
|
65 |
self._cnx = cnx |
|
66 |
self.repo = repo |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
67 |
if config is not None: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
68 |
self.session.data['rebuild-infered'] = False |
0 | 69 |
elif connect: |
70 |
self.repo_connect() |
|
71 |
if not schema: |
|
72 |
schema = config.load_schema(expand_cubes=True) |
|
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
73 |
self.fs_schema = schema |
0 | 74 |
self._synchronized = set() |
75 |
||
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
76 |
# overriden from base MigrationHelper ###################################### |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
77 |
|
0 | 78 |
@cached |
79 |
def repo_connect(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
80 |
self.repo = get_repository(method='inmemory', config=self.config) |
0 | 81 |
return self.repo |
1477 | 82 |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
83 |
def cube_upgraded(self, cube, version): |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
84 |
self.cmd_set_property('system.version.%s' % cube.lower(), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
85 |
unicode(version)) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
86 |
self.commit() |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
87 |
|
0 | 88 |
def shutdown(self): |
89 |
if self.repo is not None: |
|
90 |
self.repo.shutdown() |
|
1477 | 91 |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
92 |
def migrate(self, vcconf, toupgrade, options): |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
93 |
if not options.fs_only: |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
94 |
if options.backup_db is None: |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
95 |
self.backup_database() |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
96 |
elif options.backup_db: |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
97 |
self.backup_database(askconfirm=False) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
98 |
super(ServerMigrationHelper, self).migrate(vcconf, toupgrade, options) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
99 |
|
3715
e3ccadb126d7
[shell] make process_script available throuhg c-c shell / migration script context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3708
diff
changeset
|
100 |
def cmd_process_script(self, migrscript, funcname=None, *args, **kwargs): |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
101 |
"""execute a migration script |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
102 |
in interactive mode, display the migration script path, ask for |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
103 |
confirmation and execute it if confirmed |
0 | 104 |
""" |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
105 |
try: |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
106 |
if migrscript.endswith('.sql'): |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
107 |
if self.execscript_confirm(migrscript): |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
108 |
sqlexec(open(migrscript).read(), self.session.system_sql) |
3935
2fbb79054a1a
imported patch cwctl-shell-textfile
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3903
diff
changeset
|
109 |
elif migrscript.endswith('.py') or migrscript.endswith('.txt'): |
3715
e3ccadb126d7
[shell] make process_script available throuhg c-c shell / migration script context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3708
diff
changeset
|
110 |
return super(ServerMigrationHelper, self).cmd_process_script( |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
111 |
migrscript, funcname, *args, **kwargs) |
3872
8b1b9179f100
[migration] avoid AssertionError / crashes if migration script is neither a py nor a sql file
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3836
diff
changeset
|
112 |
else: |
8b1b9179f100
[migration] avoid AssertionError / crashes if migration script is neither a py nor a sql file
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3836
diff
changeset
|
113 |
print |
3935
2fbb79054a1a
imported patch cwctl-shell-textfile
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3903
diff
changeset
|
114 |
print ('-> ignoring %s, only .py .sql and .txt scripts are considered' % |
3872
8b1b9179f100
[migration] avoid AssertionError / crashes if migration script is neither a py nor a sql file
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3836
diff
changeset
|
115 |
migrscript) |
8b1b9179f100
[migration] avoid AssertionError / crashes if migration script is neither a py nor a sql file
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3836
diff
changeset
|
116 |
print |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
117 |
self.commit() |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
118 |
except: |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
119 |
self.rollback() |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
120 |
raise |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
121 |
|
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
122 |
# server specific migration methods ######################################## |
1477 | 123 |
|
0 | 124 |
def backup_database(self, backupfile=None, askconfirm=True): |
125 |
config = self.config |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2489
diff
changeset
|
126 |
repo = self.repo_connect() |
2759
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
127 |
# paths |
3192 | 128 |
timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S') |
2759
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
129 |
instbkdir = osp.join(config.appdatahome, 'backup') |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
130 |
if not osp.exists(instbkdir): |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
131 |
os.makedirs(instbkdir) |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
132 |
backupfile = backupfile or osp.join(instbkdir, '%s-%s.tar.gz' |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
133 |
% (config.appid, timestamp)) |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
134 |
# check backup has to be done |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
135 |
if osp.exists(backupfile) and not \ |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
136 |
self.confirm('Backup file %s exists, overwrite it?' % backupfile): |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
137 |
print '-> no backup done.' |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
138 |
return |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
139 |
elif askconfirm and not self.confirm('Backup %s database?' % config.appid): |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
140 |
print '-> no backup done.' |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
141 |
return |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
142 |
open(backupfile,'w').close() # kinda lock |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
143 |
os.chmod(backupfile, 0600) |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
144 |
# backup |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
145 |
tmpdir = tempfile.mkdtemp(dir=instbkdir) |
2960
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
146 |
try: |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
147 |
for source in repo.sources: |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
148 |
try: |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
149 |
source.backup(osp.join(tmpdir, source.uri)) |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
150 |
except Exception, exc: |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
151 |
print '-> error trying to backup [%s]' % exc |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
152 |
if not self.confirm('Continue anyway?', default='n'): |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
153 |
raise SystemExit(1) |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
154 |
else: |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
155 |
break |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
156 |
else: |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
157 |
bkup = tarfile.open(backupfile, 'w|gz') |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
158 |
for filename in os.listdir(tmpdir): |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
159 |
bkup.add(osp.join(tmpdir,filename), filename) |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
160 |
bkup.close() |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
161 |
# call hooks |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
162 |
repo.hm.call_hooks('server_backup', repo=repo, timestamp=timestamp) |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
163 |
# done |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
164 |
print '-> backup file', backupfile |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
165 |
finally: |
1c6eafc68586
[db-dump] don't create tarball on failed dump, properly remove temporary directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
166 |
shutil.rmtree(tmpdir) |
1477 | 167 |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2489
diff
changeset
|
168 |
def restore_database(self, backupfile, drop=True, systemonly=True, |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2489
diff
changeset
|
169 |
askconfirm=True): |
2759
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
170 |
# check |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
171 |
if not osp.exists(backupfile): |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
172 |
raise Exception("Backup file %s doesn't exist" % backupfile) |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
173 |
return |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
174 |
if askconfirm and not self.confirm('Restore %s database from %s ?' |
2959
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2926
diff
changeset
|
175 |
% (self.config.appid, backupfile)): |
2759
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
176 |
return |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
177 |
# unpack backup |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
178 |
tmpdir = tempfile.mkdtemp() |
3105
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
179 |
try: |
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
180 |
bkup = tarfile.open(backupfile, 'r|gz') |
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
181 |
except tarfile.ReadError: |
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
182 |
# assume restoring old backup |
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
183 |
shutil.copy(backupfile, osp.join(tmpdir, 'system')) |
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
184 |
else: |
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
185 |
for name in bkup.getnames(): |
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
186 |
if name[0] in '/.': |
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
187 |
raise Exception('Security check failed, path starts with "/" or "."') |
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
188 |
bkup.close() # XXX seek error if not close+open !?! |
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
189 |
bkup = tarfile.open(backupfile, 'r|gz') |
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
190 |
bkup.extractall(path=tmpdir) |
b788903e77d5
be able to restore pre cw 3.4 database dumps #370595
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2963
diff
changeset
|
191 |
bkup.close() |
2959
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2926
diff
changeset
|
192 |
|
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2926
diff
changeset
|
193 |
self.config.open_connections_pools = False |
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2926
diff
changeset
|
194 |
repo = self.repo_connect() |
2861
9cb3027407aa
B offer to continue even when failed to restore systemonly
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2759
diff
changeset
|
195 |
for source in repo.sources: |
9cb3027407aa
B offer to continue even when failed to restore systemonly
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2759
diff
changeset
|
196 |
if systemonly and source.uri != 'system': |
9cb3027407aa
B offer to continue even when failed to restore systemonly
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2759
diff
changeset
|
197 |
continue |
9cb3027407aa
B offer to continue even when failed to restore systemonly
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2759
diff
changeset
|
198 |
try: |
9cb3027407aa
B offer to continue even when failed to restore systemonly
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2759
diff
changeset
|
199 |
source.restore(osp.join(tmpdir, source.uri), drop=drop) |
9cb3027407aa
B offer to continue even when failed to restore systemonly
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2759
diff
changeset
|
200 |
except Exception, exc: |
9cb3027407aa
B offer to continue even when failed to restore systemonly
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2759
diff
changeset
|
201 |
print '-> error trying to restore [%s]' % exc |
9cb3027407aa
B offer to continue even when failed to restore systemonly
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2759
diff
changeset
|
202 |
if not self.confirm('Continue anyway?', default='n'): |
9cb3027407aa
B offer to continue even when failed to restore systemonly
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2759
diff
changeset
|
203 |
raise SystemExit(1) |
2759
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
204 |
shutil.rmtree(tmpdir) |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
205 |
# call hooks |
2959
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2926
diff
changeset
|
206 |
repo.open_connections_pools() |
2759
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
207 |
repo.hm.call_hooks('server_restore', repo=repo, timestamp=backupfile) |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
208 |
print '-> database restored.' |
1477 | 209 |
|
0 | 210 |
@property |
211 |
def cnx(self): |
|
212 |
"""lazy connection""" |
|
213 |
try: |
|
214 |
return self._cnx |
|
215 |
except AttributeError: |
|
216 |
sourcescfg = self.repo.config.sources() |
|
217 |
try: |
|
218 |
login = sourcescfg['admin']['login'] |
|
219 |
pwd = sourcescfg['admin']['password'] |
|
220 |
except KeyError: |
|
221 |
login, pwd = manager_userpasswd() |
|
222 |
while True: |
|
223 |
try: |
|
3659 | 224 |
self._cnx = repo_connect(self.repo, login, password=pwd) |
0 | 225 |
if not 'managers' in self._cnx.user(self.session).groups: |
226 |
print 'migration need an account in the managers group' |
|
227 |
else: |
|
228 |
break |
|
229 |
except AuthenticationError: |
|
230 |
print 'wrong user/password' |
|
231 |
except (KeyboardInterrupt, EOFError): |
|
232 |
print 'aborting...' |
|
233 |
sys.exit(0) |
|
234 |
try: |
|
235 |
login, pwd = manager_userpasswd() |
|
236 |
except (KeyboardInterrupt, EOFError): |
|
237 |
print 'aborting...' |
|
238 |
sys.exit(0) |
|
2571
5c837feca73a
oops, this is a method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2570
diff
changeset
|
239 |
self.session.keep_pool_mode('transaction') |
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
240 |
self.session.data['rebuild-infered'] = False |
0 | 241 |
return self._cnx |
242 |
||
243 |
@property |
|
244 |
def session(self): |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
245 |
if self.config is not None: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
246 |
return self.repo._get_session(self.cnx.sessionid) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
247 |
# no access to session on remote instance |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
248 |
return None |
1477 | 249 |
|
0 | 250 |
def commit(self): |
251 |
if hasattr(self, '_cnx'): |
|
252 |
self._cnx.commit() |
|
1477 | 253 |
|
0 | 254 |
def rollback(self): |
255 |
if hasattr(self, '_cnx'): |
|
256 |
self._cnx.rollback() |
|
1477 | 257 |
|
0 | 258 |
def rqlexecall(self, rqliter, cachekey=None, ask_confirm=True): |
259 |
for rql, kwargs in rqliter: |
|
260 |
self.rqlexec(rql, kwargs, cachekey, ask_confirm) |
|
261 |
||
262 |
@cached |
|
263 |
def _create_context(self): |
|
264 |
"""return a dictionary to use as migration script execution context""" |
|
265 |
context = super(ServerMigrationHelper, self)._create_context() |
|
4017
a5b4d4f2a1c7
use commit in migration script instead of checkpoint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4011
diff
changeset
|
266 |
context.update({'commit': self.checkpoint, |
a5b4d4f2a1c7
use commit in migration script instead of checkpoint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4011
diff
changeset
|
267 |
'checkpoint': deprecated('[3.6] use commit')(self.checkpoint), |
0 | 268 |
'sql': self.sqlexec, |
269 |
'rql': self.rqlexec, |
|
270 |
'rqliter': self.rqliter, |
|
3707
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
271 |
'schema': self.repo.get_schema(), |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
272 |
'cnx': self.cnx, |
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
273 |
'fsschema': self.fs_schema, |
0 | 274 |
'session' : self.session, |
275 |
'repo' : self.repo, |
|
2788
8d3dbe577d3a
R put version info in deprecation warnings
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2759
diff
changeset
|
276 |
'synchronize_schema': deprecated()(self.cmd_sync_schema_props_perms), # 3.4 |
8d3dbe577d3a
R put version info in deprecation warnings
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2759
diff
changeset
|
277 |
'synchronize_eschema': deprecated()(self.cmd_sync_schema_props_perms), # 3.4 |
8d3dbe577d3a
R put version info in deprecation warnings
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2759
diff
changeset
|
278 |
'synchronize_rschema': deprecated()(self.cmd_sync_schema_props_perms), # 3.4 |
0 | 279 |
}) |
280 |
return context |
|
281 |
||
282 |
@cached |
|
283 |
def group_mapping(self): |
|
284 |
"""cached group mapping""" |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
285 |
return ss.group_mapping(self._cw) |
1477 | 286 |
|
0 | 287 |
def exec_event_script(self, event, cubepath=None, funcname=None, |
1477 | 288 |
*args, **kwargs): |
0 | 289 |
if cubepath: |
2759
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
290 |
apc = osp.join(cubepath, 'migration', '%s.py' % event) |
0 | 291 |
else: |
2759
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
292 |
apc = osp.join(self.config.migration_scripts_dir(), '%s.py' % event) |
23d7a75693f8
R refactor backup and use tar.gz to store all sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2700
diff
changeset
|
293 |
if osp.exists(apc): |
0 | 294 |
if self.config.free_wheel: |
295 |
from cubicweb.server.hooks import setowner_after_add_entity |
|
296 |
self.repo.hm.unregister_hook(setowner_after_add_entity, |
|
297 |
'after_add_entity', '') |
|
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2788
diff
changeset
|
298 |
self.cmd_deactivate_verification_hooks() |
0 | 299 |
self.info('executing %s', apc) |
300 |
confirm = self.confirm |
|
301 |
execscript_confirm = self.execscript_confirm |
|
302 |
self.confirm = yes |
|
303 |
self.execscript_confirm = yes |
|
304 |
try: |
|
3715
e3ccadb126d7
[shell] make process_script available throuhg c-c shell / migration script context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3708
diff
changeset
|
305 |
return self.cmd_process_script(apc, funcname, *args, **kwargs) |
0 | 306 |
finally: |
307 |
self.confirm = confirm |
|
308 |
self.execscript_confirm = execscript_confirm |
|
309 |
if self.config.free_wheel: |
|
310 |
self.repo.hm.register_hook(setowner_after_add_entity, |
|
311 |
'after_add_entity', '') |
|
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2788
diff
changeset
|
312 |
self.cmd_reactivate_verification_hooks() |
0 | 313 |
|
3903
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
314 |
def install_custom_sql_scripts(self, directory, driver): |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
315 |
self.session.set_pool() # ensure pool is set |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
316 |
for fpath in glob(osp.join(directory, '*.sql.%s' % driver)): |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
317 |
newname = osp.basename(fpath).replace('.sql.%s' % driver, |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
318 |
'.%s.sql' % driver) |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
319 |
warn('[3.5.6] rename %s into %s' % (fpath, newname), |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
320 |
DeprecationWarning) |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
321 |
print '-> installing', fpath |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
322 |
sqlexec(open(fpath).read(), self.session.system_sql, False, |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
323 |
delimiter=';;') |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
324 |
for fpath in glob(osp.join(directory, '*.%s.sql' % driver)): |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
325 |
print '-> installing', fpath |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
326 |
sqlexec(open(fpath).read(), self.session.system_sql, False, |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
327 |
delimiter=';;') |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
328 |
|
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
329 |
# schema synchronization internals ######################################## |
0 | 330 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
331 |
def _synchronize_permissions(self, erschema, teid): |
0 | 332 |
"""permission synchronization for an entity or relation type""" |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
333 |
if erschema in VIRTUAL_RTYPES: |
0 | 334 |
return |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
335 |
assert teid, erschema |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
336 |
if 'update' in erschema.ACTIONS or erschema.final: |
0 | 337 |
# entity type |
338 |
exprtype = u'ERQLExpression' |
|
339 |
else: |
|
340 |
# relation type |
|
341 |
exprtype = u'RRQLExpression' |
|
342 |
gm = self.group_mapping() |
|
343 |
confirm = self.verbosity >= 2 |
|
344 |
# * remove possibly deprecated permission (eg in the persistent schema |
|
345 |
# but not in the new schema) |
|
346 |
# * synchronize existing expressions |
|
347 |
# * add new groups/expressions |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
348 |
for action in erschema.ACTIONS: |
0 | 349 |
perm = '%s_permission' % action |
350 |
# handle groups |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
351 |
newgroups = list(erschema.get_groups(action)) |
0 | 352 |
for geid, gname in self.rqlexec('Any G, GN WHERE T %s G, G name GN, ' |
353 |
'T eid %%(x)s' % perm, {'x': teid}, 'x', |
|
354 |
ask_confirm=False): |
|
355 |
if not gname in newgroups: |
|
356 |
if not confirm or self.confirm('remove %s permission of %s to %s?' |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
357 |
% (action, erschema, gname)): |
0 | 358 |
self.rqlexec('DELETE T %s G WHERE G eid %%(x)s, T eid %s' |
359 |
% (perm, teid), |
|
360 |
{'x': geid}, 'x', ask_confirm=False) |
|
361 |
else: |
|
362 |
newgroups.remove(gname) |
|
363 |
for gname in newgroups: |
|
364 |
if not confirm or self.confirm('grant %s permission of %s to %s?' |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
365 |
% (action, erschema, gname)): |
0 | 366 |
self.rqlexec('SET T %s G WHERE G eid %%(x)s, T eid %s' |
367 |
% (perm, teid), |
|
368 |
{'x': gm[gname]}, 'x', ask_confirm=False) |
|
369 |
# handle rql expressions |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
370 |
newexprs = dict((expr.expression, expr) for expr in erschema.get_rqlexprs(action)) |
0 | 371 |
for expreid, expression in self.rqlexec('Any E, EX WHERE T %s E, E expression EX, ' |
372 |
'T eid %s' % (perm, teid), |
|
373 |
ask_confirm=False): |
|
374 |
if not expression in newexprs: |
|
375 |
if not confirm or self.confirm('remove %s expression for %s permission of %s?' |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
376 |
% (expression, action, erschema)): |
0 | 377 |
# deleting the relation will delete the expression entity |
378 |
self.rqlexec('DELETE T %s E WHERE E eid %%(x)s, T eid %s' |
|
379 |
% (perm, teid), |
|
380 |
{'x': expreid}, 'x', ask_confirm=False) |
|
381 |
else: |
|
382 |
newexprs.pop(expression) |
|
383 |
for expression in newexprs.values(): |
|
384 |
expr = expression.expression |
|
385 |
if not confirm or self.confirm('add %s expression for %s permission of %s?' |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
386 |
% (expr, action, erschema)): |
0 | 387 |
self.rqlexec('INSERT RQLExpression X: X exprtype %%(exprtype)s, ' |
388 |
'X expression %%(expr)s, X mainvars %%(vars)s, T %s X ' |
|
389 |
'WHERE T eid %%(x)s' % perm, |
|
390 |
{'expr': expr, 'exprtype': exprtype, |
|
391 |
'vars': expression.mainvars, 'x': teid}, 'x', |
|
392 |
ask_confirm=False) |
|
1477 | 393 |
|
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
394 |
def _synchronize_rschema(self, rtype, syncrdefs=True, syncperms=True): |
0 | 395 |
"""synchronize properties of the persistent relation schema against its |
396 |
current definition: |
|
1477 | 397 |
|
0 | 398 |
* description |
399 |
* symetric, meta |
|
400 |
* inlined |
|
401 |
* relation definitions if `syncrdefs` |
|
402 |
* permissions if `syncperms` |
|
1477 | 403 |
|
0 | 404 |
physical schema changes should be handled by repository's schema hooks |
405 |
""" |
|
406 |
rtype = str(rtype) |
|
407 |
if rtype in self._synchronized: |
|
408 |
return |
|
409 |
self._synchronized.add(rtype) |
|
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
410 |
rschema = self.fs_schema.rschema(rtype) |
0 | 411 |
self.rqlexecall(ss.updaterschema2rql(rschema), |
412 |
ask_confirm=self.verbosity>=2) |
|
413 |
reporschema = self.repo.schema.rschema(rtype) |
|
414 |
if syncrdefs: |
|
415 |
for subj, obj in rschema.iter_rdefs(): |
|
416 |
if not reporschema.has_rdef(subj, obj): |
|
417 |
continue |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
418 |
self._synchronize_rdef_schema(subj, rschema, obj, syncperms=syncperms) |
1477 | 419 |
|
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
420 |
def _synchronize_eschema(self, etype, syncperms=True): |
0 | 421 |
"""synchronize properties of the persistent entity schema against |
422 |
its current definition: |
|
1477 | 423 |
|
0 | 424 |
* description |
425 |
* internationalizable, fulltextindexed, indexed, meta |
|
426 |
* relations from/to this entity |
|
427 |
* permissions if `syncperms` |
|
428 |
""" |
|
429 |
etype = str(etype) |
|
430 |
if etype in self._synchronized: |
|
431 |
return |
|
432 |
self._synchronized.add(etype) |
|
433 |
repoeschema = self.repo.schema.eschema(etype) |
|
434 |
try: |
|
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
435 |
eschema = self.fs_schema.eschema(etype) |
0 | 436 |
except KeyError: |
437 |
return |
|
438 |
repospschema = repoeschema.specializes() |
|
439 |
espschema = eschema.specializes() |
|
440 |
if repospschema and not espschema: |
|
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
441 |
self.rqlexec('DELETE X specializes Y WHERE X is CWEType, X name %(x)s', |
3213
36a2357ccbc4
[migration] don't ask confirm here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3192
diff
changeset
|
442 |
{'x': str(repoeschema)}, ask_confirm=False) |
0 | 443 |
elif not repospschema and espschema: |
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
444 |
self.rqlexec('SET X specializes Y WHERE X is CWEType, X name %(x)s, ' |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
445 |
'Y is CWEType, Y name %(y)s', |
3213
36a2357ccbc4
[migration] don't ask confirm here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3192
diff
changeset
|
446 |
{'x': str(repoeschema), 'y': str(espschema)}, |
36a2357ccbc4
[migration] don't ask confirm here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3192
diff
changeset
|
447 |
ask_confirm=False) |
0 | 448 |
self.rqlexecall(ss.updateeschema2rql(eschema), |
449 |
ask_confirm=self.verbosity >= 2) |
|
2962
5e2239672e16
[migraction] use role instead of x
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2960
diff
changeset
|
450 |
for rschema, targettypes, role in eschema.relation_definitions(True): |
5e2239672e16
[migraction] use role instead of x
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2960
diff
changeset
|
451 |
if role == 'subject': |
0 | 452 |
if not rschema in repoeschema.subject_relations(): |
453 |
continue |
|
454 |
subjtypes, objtypes = [etype], targettypes |
|
2962
5e2239672e16
[migraction] use role instead of x
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2960
diff
changeset
|
455 |
else: # role == 'object' |
0 | 456 |
if not rschema in repoeschema.object_relations(): |
457 |
continue |
|
458 |
subjtypes, objtypes = targettypes, [etype] |
|
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
459 |
self._synchronize_rschema(rschema, syncperms=syncperms, |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
460 |
syncrdefs=False) |
0 | 461 |
reporschema = self.repo.schema.rschema(rschema) |
462 |
for subj in subjtypes: |
|
463 |
for obj in objtypes: |
|
464 |
if not reporschema.has_rdef(subj, obj): |
|
465 |
continue |
|
1414
448c9802d7df
does not apply any more
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1409
diff
changeset
|
466 |
self._synchronize_rdef_schema(subj, rschema, obj) |
0 | 467 |
if syncperms: |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
468 |
self._synchronize_permissions(eschema, repoeschema.eid) |
0 | 469 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
470 |
def _synchronize_rdef_schema(self, subjtype, rtype, objtype, syncperms=True): |
0 | 471 |
"""synchronize properties of the persistent relation definition schema |
472 |
against its current definition: |
|
473 |
* order and other properties |
|
474 |
* constraints |
|
475 |
""" |
|
476 |
subjtype, objtype = str(subjtype), str(objtype) |
|
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
477 |
rschema = self.fs_schema.rschema(rtype) |
0 | 478 |
reporschema = self.repo.schema.rschema(rschema) |
479 |
if (subjtype, rschema, objtype) in self._synchronized: |
|
480 |
return |
|
481 |
self._synchronized.add((subjtype, rschema, objtype)) |
|
482 |
if rschema.symetric: |
|
483 |
self._synchronized.add((objtype, rschema, subjtype)) |
|
484 |
confirm = self.verbosity >= 2 |
|
485 |
# properties |
|
486 |
self.rqlexecall(ss.updaterdef2rql(rschema, subjtype, objtype), |
|
487 |
ask_confirm=confirm) |
|
488 |
# constraints |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
489 |
rdef = rschema.rdef(subjtype, objtype) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
490 |
repordef = reporschema.rdef(subjtype, objtype) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
491 |
newconstraints = list(rdef.constraints) |
0 | 492 |
# 1. remove old constraints and update constraints of the same type |
493 |
# NOTE: don't use rschema.constraint_by_type because it may be |
|
494 |
# out of sync with newconstraints when multiple |
|
495 |
# constraints of the same type are used |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
496 |
for cstr in repordef.constraints: |
0 | 497 |
for newcstr in newconstraints: |
498 |
if newcstr.type() == cstr.type(): |
|
499 |
break |
|
500 |
else: |
|
501 |
newcstr = None |
|
502 |
if newcstr is None: |
|
503 |
self.rqlexec('DELETE X constrained_by C WHERE C eid %(x)s', |
|
504 |
{'x': cstr.eid}, 'x', |
|
505 |
ask_confirm=confirm) |
|
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
506 |
self.rqlexec('DELETE CWConstraint C WHERE C eid %(x)s', |
0 | 507 |
{'x': cstr.eid}, 'x', |
508 |
ask_confirm=confirm) |
|
509 |
else: |
|
510 |
newconstraints.remove(newcstr) |
|
511 |
values = {'x': cstr.eid, |
|
512 |
'v': unicode(newcstr.serialize())} |
|
513 |
self.rqlexec('SET X value %(v)s WHERE X eid %(x)s', |
|
514 |
values, 'x', ask_confirm=confirm) |
|
515 |
# 2. add new constraints |
|
516 |
for newcstr in newconstraints: |
|
517 |
self.rqlexecall(ss.constraint2rql(rschema, subjtype, objtype, |
|
518 |
newcstr), |
|
519 |
ask_confirm=confirm) |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
520 |
if syncperms: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
521 |
self._synchronize_permissions(rdef, repordef.eid) |
1477 | 522 |
|
0 | 523 |
# base actions ############################################################ |
524 |
||
4011
394f853bb653
[migration] write migration instructions for permissions handling on relation definition
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3998
diff
changeset
|
525 |
def checkpoint(self, ask_confirm=True): |
0 | 526 |
"""checkpoint action""" |
4011
394f853bb653
[migration] write migration instructions for permissions handling on relation definition
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3998
diff
changeset
|
527 |
if not ask_confirm or self.confirm('commit now ?', shell=False): |
0 | 528 |
self.commit() |
529 |
||
530 |
def cmd_add_cube(self, cube, update_database=True): |
|
676
270eb87a768a
provide a new add_cubes() migration function for cases where the new cubes are linked together by new relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
447
diff
changeset
|
531 |
self.cmd_add_cubes( (cube,), update_database) |
1477 | 532 |
|
676
270eb87a768a
provide a new add_cubes() migration function for cases where the new cubes are linked together by new relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
447
diff
changeset
|
533 |
def cmd_add_cubes(self, cubes, update_database=True): |
0 | 534 |
"""update_database is telling if the database schema should be updated |
535 |
or if only the relevant eproperty should be inserted (for the case where |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2275
diff
changeset
|
536 |
a cube has been extracted from an existing instance, so the |
0 | 537 |
cube schema is already in there) |
538 |
""" |
|
676
270eb87a768a
provide a new add_cubes() migration function for cases where the new cubes are linked together by new relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
447
diff
changeset
|
539 |
newcubes = super(ServerMigrationHelper, self).cmd_add_cubes(cubes) |
0 | 540 |
if not newcubes: |
541 |
return |
|
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
542 |
for cube in newcubes: |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
543 |
self.cmd_set_property('system.version.'+cube, |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
544 |
self.config.cube_version(cube)) |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
545 |
if cube in SOURCE_TYPES: |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
546 |
# don't use config.sources() in case some sources have been |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
547 |
# disabled for migration |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
548 |
sourcescfg = self.config.read_sources_file() |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
549 |
sourcescfg[cube] = ask_source_config(cube) |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
550 |
self.config.write_sources_file(sourcescfg) |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
551 |
clear_cache(self.config, 'read_sources_file') |
3836
58c09f21f503
fix necessary when adding a cube which isn't listed in fs dependencies of the instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3715
diff
changeset
|
552 |
# ensure added cube is in config cubes |
58c09f21f503
fix necessary when adding a cube which isn't listed in fs dependencies of the instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3715
diff
changeset
|
553 |
# XXX worth restoring on error? |
58c09f21f503
fix necessary when adding a cube which isn't listed in fs dependencies of the instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3715
diff
changeset
|
554 |
if not cube in self.config._cubes: |
58c09f21f503
fix necessary when adding a cube which isn't listed in fs dependencies of the instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3715
diff
changeset
|
555 |
self.config._cubes += (cube,) |
0 | 556 |
if not update_database: |
557 |
self.commit() |
|
558 |
return |
|
1036
593df4919845
when reading the schema while adding/removing cubes, read schema in non-strict mode
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
559 |
newcubes_schema = self.config.load_schema(construction_mode='non-strict') |
3836
58c09f21f503
fix necessary when adding a cube which isn't listed in fs dependencies of the instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3715
diff
changeset
|
560 |
# XXX we have to replace fs_schema, used in cmd_add_relation_type |
58c09f21f503
fix necessary when adding a cube which isn't listed in fs dependencies of the instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3715
diff
changeset
|
561 |
# etc. and fsschema of migration script contexts |
58c09f21f503
fix necessary when adding a cube which isn't listed in fs dependencies of the instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3715
diff
changeset
|
562 |
self.fs_schema = self._create_context()['fsschema'] = newcubes_schema |
0 | 563 |
new = set() |
564 |
# execute pre-create files |
|
3903
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
565 |
driver = self.repo.system_source.dbdriver |
0 | 566 |
for pack in reversed(newcubes): |
3903
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
567 |
cubedir = self.config.cube_dir(pack) |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
568 |
self.install_custom_sql_scripts(osp.join(cubedir, 'schema'), driver) |
7967d3766ecf
fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3872
diff
changeset
|
569 |
self.exec_event_script('precreate', cubedir) |
0 | 570 |
# add new entity and relation types |
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
571 |
for rschema in newcubes_schema.relations(): |
0 | 572 |
if not rschema in self.repo.schema: |
573 |
self.cmd_add_relation_type(rschema.type) |
|
574 |
new.add(rschema.type) |
|
2926
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
575 |
toadd = [eschema for eschema in newcubes_schema.entities() |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
576 |
if not eschema in self.repo.schema] |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
577 |
for eschema in order_eschemas(toadd): |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
578 |
self.cmd_add_entity_type(eschema.type) |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
579 |
new.add(eschema.type) |
0 | 580 |
# check if attributes has been added to existing entities |
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
581 |
for rschema in newcubes_schema.relations(): |
0 | 582 |
existingschema = self.repo.schema.rschema(rschema.type) |
583 |
for (fromtype, totype) in rschema.iter_rdefs(): |
|
584 |
if existingschema.has_rdef(fromtype, totype): |
|
585 |
continue |
|
586 |
# check we should actually add the relation definition |
|
587 |
if not (fromtype in new or totype in new or rschema in new): |
|
588 |
continue |
|
1477 | 589 |
self.cmd_add_relation_definition(str(fromtype), rschema.type, |
0 | 590 |
str(totype)) |
591 |
# execute post-create files |
|
592 |
for pack in reversed(newcubes): |
|
593 |
self.exec_event_script('postcreate', self.config.cube_dir(pack)) |
|
1477 | 594 |
self.commit() |
595 |
||
2124
5a0b02f37b23
set removedeps to False by default, raise an exception instead of a simple assertion for error, more remove_cube tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2122
diff
changeset
|
596 |
def cmd_remove_cube(self, cube, removedeps=False): |
2122
4ea13a828513
add removedeps option to remove_cube to control wether a cube's dependencies should be removed as well or not
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2107
diff
changeset
|
597 |
removedcubes = super(ServerMigrationHelper, self).cmd_remove_cube( |
4ea13a828513
add removedeps option to remove_cube to control wether a cube's dependencies should be removed as well or not
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2107
diff
changeset
|
598 |
cube, removedeps) |
0 | 599 |
if not removedcubes: |
600 |
return |
|
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
601 |
fsschema = self.fs_schema |
1036
593df4919845
when reading the schema while adding/removing cubes, read schema in non-strict mode
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
602 |
removedcubes_schema = self.config.load_schema(construction_mode='non-strict') |
0 | 603 |
reposchema = self.repo.schema |
604 |
# execute pre-remove files |
|
605 |
for pack in reversed(removedcubes): |
|
606 |
self.exec_event_script('preremove', self.config.cube_dir(pack)) |
|
607 |
# remove cubes'entity and relation types |
|
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
608 |
for rschema in fsschema.relations(): |
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
609 |
if not rschema in removedcubes_schema and rschema in reposchema: |
0 | 610 |
self.cmd_drop_relation_type(rschema.type) |
2926
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
611 |
toremove = [eschema for eschema in fsschema.entities() |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
612 |
if not eschema in removedcubes_schema |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
613 |
and eschema in reposchema] |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
614 |
for eschema in reversed(order_eschemas(toremove)): |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
615 |
self.cmd_drop_entity_type(eschema.type) |
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
616 |
for rschema in fsschema.relations(): |
1477 | 617 |
if rschema in removedcubes_schema and rschema in reposchema: |
618 |
# check if attributes/relations has been added to entities from |
|
0 | 619 |
# other cubes |
620 |
for fromtype, totype in rschema.iter_rdefs(): |
|
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
621 |
if not removedcubes_schema[rschema.type].has_rdef(fromtype, totype) and \ |
0 | 622 |
reposchema[rschema.type].has_rdef(fromtype, totype): |
623 |
self.cmd_drop_relation_definition( |
|
624 |
str(fromtype), rschema.type, str(totype)) |
|
625 |
# execute post-remove files |
|
626 |
for pack in reversed(removedcubes): |
|
627 |
self.exec_event_script('postremove', self.config.cube_dir(pack)) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
628 |
self.rqlexec('DELETE CWProperty X WHERE X pkey %(pk)s', |
0 | 629 |
{'pk': u'system.version.'+pack}, ask_confirm=False) |
630 |
self.commit() |
|
1477 | 631 |
|
0 | 632 |
# schema migration actions ################################################ |
1477 | 633 |
|
0 | 634 |
def cmd_add_attribute(self, etype, attrname, attrtype=None, commit=True): |
635 |
"""add a new attribute on the given entity type""" |
|
636 |
if attrtype is None: |
|
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
637 |
rschema = self.fs_schema.rschema(attrname) |
0 | 638 |
attrtype = rschema.objects(etype)[0] |
639 |
self.cmd_add_relation_definition(etype, attrname, attrtype, commit=commit) |
|
1477 | 640 |
|
0 | 641 |
def cmd_drop_attribute(self, etype, attrname, commit=True): |
642 |
"""drop an existing attribute from the given entity type |
|
1477 | 643 |
|
0 | 644 |
`attrname` is a string giving the name of the attribute to drop |
645 |
""" |
|
646 |
rschema = self.repo.schema.rschema(attrname) |
|
647 |
attrtype = rschema.objects(etype)[0] |
|
648 |
self.cmd_drop_relation_definition(etype, attrname, attrtype, commit=commit) |
|
649 |
||
650 |
def cmd_rename_attribute(self, etype, oldname, newname, commit=True): |
|
651 |
"""rename an existing attribute of the given entity type |
|
1477 | 652 |
|
0 | 653 |
`oldname` is a string giving the name of the existing attribute |
654 |
`newname` is a string giving the name of the renamed attribute |
|
655 |
""" |
|
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
656 |
eschema = self.fs_schema.eschema(etype) |
0 | 657 |
attrtype = eschema.destination(newname) |
658 |
# have to commit this first step anyway to get the definition |
|
659 |
# actually in the schema |
|
660 |
self.cmd_add_attribute(etype, newname, attrtype, commit=True) |
|
661 |
# skipp NULL values if the attribute is required |
|
662 |
rql = 'SET X %s VAL WHERE X is %s, X %s VAL' % (newname, etype, oldname) |
|
663 |
card = eschema.rproperty(newname, 'cardinality')[0] |
|
664 |
if card == '1': |
|
665 |
rql += ', NOT X %s NULL' % oldname |
|
666 |
self.rqlexec(rql, ask_confirm=self.verbosity>=2) |
|
3548
4cf5a360952e
add some notes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3213
diff
changeset
|
667 |
# XXX if both attributes fulltext indexed, should skip fti rebuild |
4cf5a360952e
add some notes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3213
diff
changeset
|
668 |
# XXX if old attribute was fti indexed but not the new one old value |
4cf5a360952e
add some notes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3213
diff
changeset
|
669 |
# won't be removed from the index (this occurs on other kind of |
4cf5a360952e
add some notes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3213
diff
changeset
|
670 |
# fulltextindexed change...) |
0 | 671 |
self.cmd_drop_attribute(etype, oldname, commit=commit) |
1477 | 672 |
|
0 | 673 |
def cmd_add_entity_type(self, etype, auto=True, commit=True): |
674 |
"""register a new entity type |
|
1477 | 675 |
|
0 | 676 |
in auto mode, automatically register entity's relation where the |
677 |
targeted type is known |
|
678 |
""" |
|
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
679 |
instschema = self.repo.schema |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
680 |
if etype in instschema: |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
681 |
# XXX (syt) plz explain: if we're adding an entity type, it should |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
682 |
# not be there... |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
683 |
eschema = instschema[etype] |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3582
diff
changeset
|
684 |
if eschema.final: |
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
685 |
instschema.del_entity_type(etype) |
0 | 686 |
else: |
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
687 |
eschema = self.fs_schema.eschema(etype) |
0 | 688 |
confirm = self.verbosity >= 2 |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
689 |
# register the entity into CWEType |
4011
394f853bb653
[migration] write migration instructions for permissions handling on relation definition
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3998
diff
changeset
|
690 |
self.rqlexecall(ss.eschema2rql(eschema, self.group_mapping()), ask_confirm=confirm) |
0 | 691 |
# add specializes relation if needed |
692 |
self.rqlexecall(ss.eschemaspecialize2rql(eschema), ask_confirm=confirm) |
|
693 |
# register entity's attributes |
|
694 |
for rschema, attrschema in eschema.attribute_definitions(): |
|
695 |
# ignore those meta relations, they will be automatically added |
|
2617
89c62b855f2e
[R schema hooks] rename META_RELATIONS_TYPES into META_RTYPES, use it and other schema consts to avoid errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2616
diff
changeset
|
696 |
if rschema.type in META_RTYPES: |
0 | 697 |
continue |
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
698 |
if not rschema.type in instschema: |
0 | 699 |
# need to add the relation type and to commit to get it |
700 |
# actually in the schema |
|
701 |
self.cmd_add_relation_type(rschema.type, False, commit=True) |
|
702 |
# register relation definition |
|
703 |
self.rqlexecall(ss.rdef2rql(rschema, etype, attrschema.type), |
|
704 |
ask_confirm=confirm) |
|
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
705 |
# take care to newly introduced base class |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
706 |
# XXX some part of this should probably be under the "if auto" block |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
707 |
for spschema in eschema.specialized_by(recursive=False): |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
708 |
try: |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
709 |
instspschema = instschema[spschema] |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
710 |
except KeyError: |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
711 |
# specialized entity type not in schema, ignore |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
712 |
continue |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
713 |
if instspschema.specializes() != eschema: |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
714 |
self.rqlexec('SET D specializes P WHERE D eid %(d)s, P name %(pn)s', |
3412 | 715 |
{'d': instspschema.eid, |
716 |
'pn': eschema.type}, ask_confirm=confirm) |
|
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
717 |
for rschema, tschemas, role in spschema.relation_definitions(True): |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
718 |
for tschema in tschemas: |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
719 |
if not tschema in instschema: |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
720 |
continue |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
721 |
if role == 'subject': |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
722 |
subjschema = spschema |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
723 |
objschema = tschema |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3582
diff
changeset
|
724 |
if rschema.final and rschema in instspschema.subjrels: |
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
725 |
# attribute already set, has_rdef would check if |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
726 |
# it's of the same type, we don't want this so |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
727 |
# simply skip here |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
728 |
continue |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
729 |
elif role == 'object': |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
730 |
subjschema = tschema |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
731 |
objschema = spschema |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
732 |
if (rschema.rproperty(subjschema, objschema, 'infered') |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
733 |
or (instschema.has_relation(rschema) and |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
734 |
instschema[rschema].has_rdef(subjschema, objschema))): |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
735 |
continue |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
736 |
self.cmd_add_relation_definition( |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
737 |
subjschema.type, rschema.type, objschema.type) |
0 | 738 |
if auto: |
739 |
# we have commit here to get relation types actually in the schema |
|
740 |
self.commit() |
|
741 |
added = [] |
|
742 |
for rschema in eschema.subject_relations(): |
|
743 |
# attribute relation have already been processed and |
|
744 |
# 'owned_by'/'created_by' will be automatically added |
|
2617
89c62b855f2e
[R schema hooks] rename META_RELATIONS_TYPES into META_RTYPES, use it and other schema consts to avoid errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2616
diff
changeset
|
745 |
if rschema.final or rschema.type in META_RTYPES: |
0 | 746 |
continue |
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
747 |
rtypeadded = rschema.type in instschema |
0 | 748 |
for targetschema in rschema.objects(etype): |
749 |
# ignore relations where the targeted type is not in the |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2275
diff
changeset
|
750 |
# current instance schema |
0 | 751 |
targettype = targetschema.type |
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
752 |
if not targettype in instschema and targettype != etype: |
0 | 753 |
continue |
754 |
if not rtypeadded: |
|
755 |
# need to add the relation type and to commit to get it |
|
756 |
# actually in the schema |
|
757 |
added.append(rschema.type) |
|
758 |
self.cmd_add_relation_type(rschema.type, False, commit=True) |
|
759 |
rtypeadded = True |
|
760 |
# register relation definition |
|
761 |
# remember this two avoid adding twice non symetric relation |
|
762 |
# such as "Emailthread forked_from Emailthread" |
|
763 |
added.append((etype, rschema.type, targettype)) |
|
764 |
self.rqlexecall(ss.rdef2rql(rschema, etype, targettype), |
|
765 |
ask_confirm=confirm) |
|
766 |
for rschema in eschema.object_relations(): |
|
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
767 |
rtypeadded = rschema.type in instschema or rschema.type in added |
0 | 768 |
for targetschema in rschema.subjects(etype): |
769 |
# ignore relations where the targeted type is not in the |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2275
diff
changeset
|
770 |
# current instance schema |
0 | 771 |
targettype = targetschema.type |
772 |
# don't check targettype != etype since in this case the |
|
773 |
# relation has already been added as a subject relation |
|
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2962
diff
changeset
|
774 |
if not targettype in instschema: |
0 | 775 |
continue |
776 |
if not rtypeadded: |
|
777 |
# need to add the relation type and to commit to get it |
|
778 |
# actually in the schema |
|
779 |
self.cmd_add_relation_type(rschema.type, False, commit=True) |
|
780 |
rtypeadded = True |
|
781 |
elif (targettype, rschema.type, etype) in added: |
|
782 |
continue |
|
783 |
# register relation definition |
|
784 |
self.rqlexecall(ss.rdef2rql(rschema, targettype, etype), |
|
785 |
ask_confirm=confirm) |
|
786 |
if commit: |
|
787 |
self.commit() |
|
1477 | 788 |
|
0 | 789 |
def cmd_drop_entity_type(self, etype, commit=True): |
790 |
"""unregister an existing entity type |
|
1477 | 791 |
|
0 | 792 |
This will trigger deletion of necessary relation types and definitions |
793 |
""" |
|
794 |
# XXX what if we delete an entity type which is specialized by other types |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
795 |
# unregister the entity from CWEType |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
796 |
self.rqlexec('DELETE CWEType X WHERE X name %(etype)s', {'etype': etype}, |
0 | 797 |
ask_confirm=self.verbosity>=2) |
798 |
if commit: |
|
799 |
self.commit() |
|
800 |
||
801 |
def cmd_rename_entity_type(self, oldname, newname, commit=True): |
|
802 |
"""rename an existing entity type in the persistent schema |
|
1477 | 803 |
|
0 | 804 |
`oldname` is a string giving the name of the existing entity type |
805 |
`newname` is a string giving the name of the renamed entity type |
|
806 |
""" |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
807 |
self.rqlexec('SET ET name %(newname)s WHERE ET is CWEType, ET name %(oldname)s', |
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
808 |
{'newname' : unicode(newname), 'oldname' : oldname}, |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
809 |
ask_confirm=False) |
0 | 810 |
if commit: |
811 |
self.commit() |
|
1477 | 812 |
|
0 | 813 |
def cmd_add_relation_type(self, rtype, addrdef=True, commit=True): |
814 |
"""register a new relation type named `rtype`, as described in the |
|
815 |
schema description file. |
|
816 |
||
817 |
`addrdef` is a boolean value; when True, it will also add all relations |
|
818 |
of the type just added found in the schema definition file. Note that it |
|
819 |
implies an intermediate "commit" which commits the relation type |
|
820 |
creation (but not the relation definitions themselves, for which |
|
821 |
committing depends on the `commit` argument value). |
|
1477 | 822 |
|
0 | 823 |
""" |
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
824 |
rschema = self.fs_schema.rschema(rtype) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
825 |
# register the relation into CWRType and insert necessary relation |
0 | 826 |
# definitions |
827 |
self.rqlexecall(ss.rschema2rql(rschema, addrdef=False), |
|
828 |
ask_confirm=self.verbosity>=2) |
|
829 |
if addrdef: |
|
830 |
self.commit() |
|
4011
394f853bb653
[migration] write migration instructions for permissions handling on relation definition
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3998
diff
changeset
|
831 |
self.rqlexecall(ss.rdef2rql(rschema, groupmap=self.group_mapping()), |
0 | 832 |
ask_confirm=self.verbosity>=2) |
2700
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
833 |
if rtype in META_RTYPES: |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
834 |
# if the relation is in META_RTYPES, ensure we're adding it for |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
835 |
# all entity types *in the persistent schema*, not only those in |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
836 |
# the fs schema |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
837 |
for etype in self.repo.schema.entities(): |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
838 |
if not etype in self.fs_schema: |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
839 |
# get sample object type and rproperties |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
840 |
objtypes = rschema.objects() |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
841 |
assert len(objtypes) == 1 |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
842 |
objtype = objtypes[0] |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
843 |
props = rschema.rproperties( |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
844 |
rschema.subjects(objtype)[0], objtype) |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
845 |
assert props |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
846 |
self.rqlexecall(ss.rdef2rql(rschema, etype, objtype, props), |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
847 |
ask_confirm=self.verbosity>=2) |
ecf888c8a250
[migration] when adding a core meta-relation, it should be added to all entities *in the persistent schema*, not only those in the fs schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
848 |
|
0 | 849 |
if commit: |
850 |
self.commit() |
|
1477 | 851 |
|
0 | 852 |
def cmd_drop_relation_type(self, rtype, commit=True): |
853 |
"""unregister an existing relation type""" |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
854 |
# unregister the relation from CWRType |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
855 |
self.rqlexec('DELETE CWRType X WHERE X name %r' % rtype, |
0 | 856 |
ask_confirm=self.verbosity>=2) |
857 |
if commit: |
|
858 |
self.commit() |
|
1477 | 859 |
|
0 | 860 |
def cmd_rename_relation(self, oldname, newname, commit=True): |
861 |
"""rename an existing relation |
|
1477 | 862 |
|
0 | 863 |
`oldname` is a string giving the name of the existing relation |
864 |
`newname` is a string giving the name of the renamed relation |
|
865 |
""" |
|
866 |
self.cmd_add_relation_type(newname, commit=True) |
|
867 |
self.rqlexec('SET X %s Y WHERE X %s Y' % (newname, oldname), |
|
868 |
ask_confirm=self.verbosity>=2) |
|
869 |
self.cmd_drop_relation_type(oldname, commit=commit) |
|
870 |
||
871 |
def cmd_add_relation_definition(self, subjtype, rtype, objtype, commit=True): |
|
872 |
"""register a new relation definition, from its definition found in the |
|
873 |
schema definition file |
|
874 |
""" |
|
934
f94e34795586
better variable/attribute names; fix remove_cube, it should not alter the .fs_schema attribute (former .new_schema)
sylvain.thenault@logilab.fr
parents:
676
diff
changeset
|
875 |
rschema = self.fs_schema.rschema(rtype) |
0 | 876 |
if not rtype in self.repo.schema: |
877 |
self.cmd_add_relation_type(rtype, addrdef=False, commit=True) |
|
4011
394f853bb653
[migration] write migration instructions for permissions handling on relation definition
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3998
diff
changeset
|
878 |
self.rqlexecall(ss.rdef2rql(rschema, subjtype, objtype, groupmap=self.group_mapping()), |
0 | 879 |
ask_confirm=self.verbosity>=2) |
880 |
if commit: |
|
881 |
self.commit() |
|
1477 | 882 |
|
0 | 883 |
def cmd_drop_relation_definition(self, subjtype, rtype, objtype, commit=True): |
884 |
"""unregister an existing relation definition""" |
|
885 |
rschema = self.repo.schema.rschema(rtype) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
886 |
# unregister the definition from CWAttribute or CWRelation |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3582
diff
changeset
|
887 |
if rschema.final: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
888 |
etype = 'CWAttribute' |
0 | 889 |
else: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
890 |
etype = 'CWRelation' |
0 | 891 |
rql = ('DELETE %s X WHERE X from_entity FE, FE name "%s",' |
892 |
'X relation_type RT, RT name "%s", X to_entity TE, TE name "%s"') |
|
893 |
self.rqlexec(rql % (etype, subjtype, rtype, objtype), |
|
894 |
ask_confirm=self.verbosity>=2) |
|
895 |
if commit: |
|
896 |
self.commit() |
|
1477 | 897 |
|
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
898 |
def cmd_sync_schema_props_perms(self, ertype=None, syncperms=True, |
1409
f4dee84a618f
sql attributes bugfix
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1399
diff
changeset
|
899 |
syncprops=True, syncrdefs=True, commit=True): |
0 | 900 |
"""synchronize the persistent schema against the current definition |
901 |
schema. |
|
1477 | 902 |
|
0 | 903 |
It will synch common stuff between the definition schema and the |
904 |
actual persistent schema, it won't add/remove any entity or relation. |
|
905 |
""" |
|
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
906 |
assert syncperms or syncprops, 'nothing to do' |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
907 |
if ertype is not None: |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
908 |
if isinstance(ertype, (tuple, list)): |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
909 |
assert len(ertype) == 3, 'not a relation definition' |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
910 |
assert syncprops, 'can\'t update permission for a relation definition' |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
911 |
self._synchronize_rdef_schema(ertype[0], ertype[1], ertype[2], |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
912 |
syncperms=syncperms) |
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
913 |
elif syncprops: |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
914 |
erschema = self.repo.schema[ertype] |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
915 |
if isinstance(erschema, CubicWebRelationSchema): |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
916 |
self._synchronize_rschema(erschema, syncperms=syncperms, |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
917 |
syncrdefs=syncrdefs) |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
918 |
else: |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
919 |
self._synchronize_eschema(erschema, syncperms=syncperms) |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
920 |
else: |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
921 |
erschema = self.repo.schema[ertype] |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
922 |
self._synchronize_permissions(self.fs_schema[ertype], erschema.eid) |
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
923 |
else: |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
924 |
for etype in self.repo.schema.entities(): |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
925 |
if syncprops: |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
926 |
self._synchronize_eschema(etype, syncperms=syncperms) |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
927 |
else: |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3836
diff
changeset
|
928 |
self._synchronize_permissions(self.fs_schema[etype], erschema.eid) |
0 | 929 |
if commit: |
930 |
self.commit() |
|
1477 | 931 |
|
0 | 932 |
def cmd_change_relation_props(self, subjtype, rtype, objtype, |
933 |
commit=True, **kwargs): |
|
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
934 |
"""change some properties of a relation definition |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
935 |
|
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
936 |
you usually want to use sync_schema_props_perms instead. |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
937 |
""" |
0 | 938 |
assert kwargs |
939 |
restriction = [] |
|
940 |
if subjtype and subjtype != 'Any': |
|
941 |
restriction.append('X from_entity FE, FE name "%s"' % subjtype) |
|
942 |
if objtype and objtype != 'Any': |
|
943 |
restriction.append('X to_entity TE, TE name "%s"' % objtype) |
|
944 |
if rtype and rtype != 'Any': |
|
945 |
restriction.append('X relation_type RT, RT name "%s"' % rtype) |
|
946 |
assert restriction |
|
947 |
values = [] |
|
948 |
for k, v in kwargs.items(): |
|
949 |
values.append('X %s %%(%s)s' % (k, k)) |
|
950 |
if isinstance(v, str): |
|
951 |
kwargs[k] = unicode(v) |
|
952 |
rql = 'SET %s WHERE %s' % (','.join(values), ','.join(restriction)) |
|
953 |
self.rqlexec(rql, kwargs, ask_confirm=self.verbosity>=2) |
|
954 |
if commit: |
|
955 |
self.commit() |
|
956 |
||
957 |
def cmd_set_size_constraint(self, etype, rtype, size, commit=True): |
|
958 |
"""set change size constraint of a string attribute |
|
959 |
||
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
960 |
if size is None any size constraint will be removed. |
1477 | 961 |
|
962 |
you usually want to use sync_schema_props_perms instead. |
|
0 | 963 |
""" |
964 |
oldvalue = None |
|
965 |
for constr in self.repo.schema.eschema(etype).constraints(rtype): |
|
966 |
if isinstance(constr, SizeConstraint): |
|
967 |
oldvalue = constr.max |
|
968 |
if oldvalue == size: |
|
969 |
return |
|
970 |
if oldvalue is None and not size is None: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
971 |
ceid = self.rqlexec('INSERT CWConstraint C: C value %(v)s, C cstrtype CT ' |
0 | 972 |
'WHERE CT name "SizeConstraint"', |
973 |
{'v': SizeConstraint(size).serialize()}, |
|
974 |
ask_confirm=self.verbosity>=2)[0][0] |
|
975 |
self.rqlexec('SET X constrained_by C WHERE X from_entity S, X relation_type R, ' |
|
976 |
'S name "%s", R name "%s", C eid %s' % (etype, rtype, ceid), |
|
977 |
ask_confirm=self.verbosity>=2) |
|
978 |
elif not oldvalue is None: |
|
979 |
if not size is None: |
|
980 |
self.rqlexec('SET C value %%(v)s WHERE X from_entity S, X relation_type R,' |
|
981 |
'X constrained_by C, C cstrtype CT, CT name "SizeConstraint",' |
|
982 |
'S name "%s", R name "%s"' % (etype, rtype), |
|
983 |
{'v': unicode(SizeConstraint(size).serialize())}, |
|
984 |
ask_confirm=self.verbosity>=2) |
|
985 |
else: |
|
986 |
self.rqlexec('DELETE X constrained_by C WHERE X from_entity S, X relation_type R,' |
|
987 |
'X constrained_by C, C cstrtype CT, CT name "SizeConstraint",' |
|
988 |
'S name "%s", R name "%s"' % (etype, rtype), |
|
989 |
ask_confirm=self.verbosity>=2) |
|
990 |
# cleanup unused constraints |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
991 |
self.rqlexec('DELETE CWConstraint C WHERE NOT X constrained_by C') |
0 | 992 |
if commit: |
993 |
self.commit() |
|
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
994 |
|
3577
067610a0e12f
add version number to deprecation messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3548
diff
changeset
|
995 |
@deprecated('[3.2] use sync_schema_props_perms(ertype, syncprops=False)') |
1399
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
996 |
def cmd_synchronize_permissions(self, ertype, commit=True): |
3f408c7a164e
unify schema sync migration commands with (hopefuly) a clearer name
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
997 |
self.cmd_sync_schema_props_perms(ertype, syncprops=False, commit=commit) |
1477 | 998 |
|
0 | 999 |
# Workflows handling ###################################################### |
1477 | 1000 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1001 |
def cmd_add_workflow(self, name, wfof, default=True, commit=False, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1002 |
**kwargs): |
3582
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1003 |
""" |
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1004 |
create a new workflow and links it to entity types |
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1005 |
:type name: unicode |
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1006 |
:param name: name of the workflow |
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1007 |
|
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1008 |
:type wfof: string or list/tuple of strings |
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1009 |
:param wfof: entity type(s) having this workflow |
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1010 |
|
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1011 |
:type default: bool |
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1012 |
:param default: tells wether this is the default workflow |
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1013 |
for the specified entity type(s); set it to false in |
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1014 |
the case of a subworkflow |
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1015 |
|
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1016 |
:rtype: `Workflow` |
28547f21308e
two bits of docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3577
diff
changeset
|
1017 |
""" |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1018 |
wf = self.cmd_create_entity('Workflow', name=unicode(name), |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1019 |
**kwargs) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1020 |
if not isinstance(wfof, (list, tuple)): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1021 |
wfof = (wfof,) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1022 |
for etype in wfof: |
2956
6a57c0be0e58
[migration] don't ask confirm here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
1023 |
rset = self.rqlexec( |
6a57c0be0e58
[migration] don't ask confirm here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
1024 |
'SET X workflow_of ET WHERE X eid %(x)s, ET name %(et)s', |
6a57c0be0e58
[migration] don't ask confirm here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
1025 |
{'x': wf.eid, 'et': etype}, 'x', ask_confirm=False) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1026 |
assert rset, 'unexistant entity type %s' % etype |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1027 |
if default: |
2956
6a57c0be0e58
[migration] don't ask confirm here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
1028 |
self.rqlexec( |
6a57c0be0e58
[migration] don't ask confirm here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
1029 |
'SET ET default_workflow X WHERE X eid %(x)s, ET name %(et)s', |
6a57c0be0e58
[migration] don't ask confirm here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
1030 |
{'x': wf.eid, 'et': etype}, 'x', ask_confirm=False) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1031 |
if commit: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1032 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1033 |
return wf |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1034 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1035 |
# XXX remove once cmd_add_[state|transition] are removed |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1036 |
def _get_or_create_wf(self, etypes): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1037 |
if not isinstance(etypes, (list, tuple)): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1038 |
etypes = (etypes,) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1039 |
rset = self.rqlexec('Workflow X WHERE X workflow_of ET, ET name %(et)s', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1040 |
{'et': etypes[0]}) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1041 |
if rset: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1042 |
return rset.get_entity(0, 0) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1043 |
return self.cmd_add_workflow('%s workflow' % ';'.join(etypes), etypes) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1044 |
|
3577
067610a0e12f
add version number to deprecation messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3548
diff
changeset
|
1045 |
@deprecated('[3.5] use add_workflow and Workflow.add_state method') |
0 | 1046 |
def cmd_add_state(self, name, stateof, initial=False, commit=False, **kwargs): |
1047 |
"""method to ease workflow definition: add a state for one or more |
|
1048 |
entity type(s) |
|
1049 |
""" |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1050 |
wf = self._get_or_create_wf(stateof) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1051 |
state = wf.add_state(name, initial, **kwargs) |
0 | 1052 |
if commit: |
1053 |
self.commit() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1054 |
return state.eid |
1477 | 1055 |
|
3577
067610a0e12f
add version number to deprecation messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3548
diff
changeset
|
1056 |
@deprecated('[3.5] use add_workflow and Workflow.add_transition method') |
0 | 1057 |
def cmd_add_transition(self, name, transitionof, fromstates, tostate, |
1058 |
requiredgroups=(), conditions=(), commit=False, **kwargs): |
|
1059 |
"""method to ease workflow definition: add a transition for one or more |
|
1060 |
entity type(s), from one or more state and to a single state |
|
1061 |
""" |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1062 |
wf = self._get_or_create_wf(transitionof) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1063 |
tr = wf.add_transition(name, fromstates, tostate, requiredgroups, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1064 |
conditions, **kwargs) |
0 | 1065 |
if commit: |
1066 |
self.commit() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1067 |
return tr.eid |
0 | 1068 |
|
3577
067610a0e12f
add version number to deprecation messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3548
diff
changeset
|
1069 |
@deprecated('[3.5] use Transition.set_transition_permissions method') |
0 | 1070 |
def cmd_set_transition_permissions(self, treid, |
1071 |
requiredgroups=(), conditions=(), |
|
1072 |
reset=True, commit=False): |
|
1073 |
"""set or add (if `reset` is False) groups and conditions for a |
|
1074 |
transition |
|
1075 |
""" |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1076 |
tr = self._cw.entity_from_eid(treid) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1077 |
tr.set_transition_permissions(requiredgroups, conditions, reset) |
0 | 1078 |
if commit: |
1079 |
self.commit() |
|
1080 |
||
3577
067610a0e12f
add version number to deprecation messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3548
diff
changeset
|
1081 |
@deprecated('[3.5] use entity.fire_transition("transition") or entity.change_state("state")') |
972 | 1082 |
def cmd_set_state(self, eid, statename, commit=False): |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1083 |
self._cw.entity_from_eid(eid).change_state(statename) |
972 | 1084 |
if commit: |
1085 |
self.commit() |
|
1477 | 1086 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1087 |
# CWProperty handling ###################################################### |
0 | 1088 |
|
1089 |
def cmd_property_value(self, pkey): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1090 |
rql = 'Any V WHERE X is CWProperty, X pkey %(k)s, X value V' |
0 | 1091 |
rset = self.rqlexec(rql, {'k': pkey}, ask_confirm=False) |
1092 |
return rset[0][0] |
|
1093 |
||
1094 |
def cmd_set_property(self, pkey, value): |
|
1095 |
value = unicode(value) |
|
1096 |
try: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1097 |
prop = self.rqlexec('CWProperty X WHERE X pkey %(k)s', {'k': pkey}, |
0 | 1098 |
ask_confirm=False).get_entity(0, 0) |
1099 |
except: |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1100 |
self.cmd_create_entity('CWProperty', pkey=unicode(pkey), value=value) |
0 | 1101 |
else: |
1102 |
self.rqlexec('SET X value %(v)s WHERE X pkey %(k)s', |
|
1103 |
{'k': pkey, 'v': value}, ask_confirm=False) |
|
1104 |
||
1105 |
# other data migration commands ########################################### |
|
1477 | 1106 |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1107 |
@property |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1108 |
def _cw(self): |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1109 |
session = self.session |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1110 |
if session is not None: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1111 |
session.set_pool() |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1112 |
return session |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1113 |
return self.cnx.request() |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1114 |
|
3708
95e8c3a9698a
update prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
1115 |
def cmd_create_entity(self, etype, **kwargs): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1116 |
"""add a new entity of the given type""" |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1117 |
commit = kwargs.pop('commit', False) |
3708
95e8c3a9698a
update prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
1118 |
entity = self._cw.create_entity(etype, **kwargs) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1119 |
if commit: |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1120 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1121 |
return entity |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1122 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1123 |
@deprecated('use create_entity') |
0 | 1124 |
def cmd_add_entity(self, etype, *args, **kwargs): |
1125 |
"""add a new entity of the given type""" |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
1126 |
return self.cmd_create_entity(etype, *args, **kwargs).eid |
1477 | 1127 |
|
0 | 1128 |
def sqlexec(self, sql, args=None, ask_confirm=True): |
1129 |
"""execute the given sql if confirmed |
|
1477 | 1130 |
|
0 | 1131 |
should only be used for low level stuff undoable with existing higher |
1132 |
level actions |
|
1133 |
""" |
|
1134 |
if not ask_confirm or self.confirm('execute sql: %s ?' % sql): |
|
1135 |
self.session.set_pool() # ensure pool is set |
|
1136 |
try: |
|
1137 |
cu = self.session.system_sql(sql, args) |
|
1138 |
except: |
|
1139 |
ex = sys.exc_info()[1] |
|
1140 |
if self.confirm('error: %s\nabort?' % ex): |
|
1141 |
raise |
|
1142 |
return |
|
1143 |
try: |
|
1144 |
return cu.fetchall() |
|
1145 |
except: |
|
1146 |
# no result to fetch |
|
1147 |
return |
|
1477 | 1148 |
|
0 | 1149 |
def rqlexec(self, rql, kwargs=None, cachekey=None, ask_confirm=True): |
1150 |
"""rql action""" |
|
1151 |
if not isinstance(rql, (tuple, list)): |
|
1152 |
rql = ( (rql, kwargs), ) |
|
1153 |
res = None |
|
1154 |
for rql, kwargs in rql: |
|
1155 |
if kwargs: |
|
1156 |
msg = '%s (%s)' % (rql, kwargs) |
|
1157 |
else: |
|
1158 |
msg = rql |
|
1159 |
if not ask_confirm or self.confirm('execute rql: %s ?' % msg): |
|
1160 |
try: |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1161 |
res = self._cw.execute(rql, kwargs, cachekey) |
0 | 1162 |
except Exception, ex: |
1163 |
if self.confirm('error: %s\nabort?' % ex): |
|
1164 |
raise |
|
1165 |
return res |
|
1166 |
||
1167 |
def rqliter(self, rql, kwargs=None, ask_confirm=True): |
|
1168 |
return ForRqlIterator(self, rql, None, ask_confirm) |
|
1169 |
||
1170 |
def cmd_deactivate_verification_hooks(self): |
|
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2788
diff
changeset
|
1171 |
self.config.disabled_hooks_categories.add('integrity') |
0 | 1172 |
|
1173 |
def cmd_reactivate_verification_hooks(self): |
|
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2788
diff
changeset
|
1174 |
self.config.disabled_hooks_categories.remove('integrity') |
1477 | 1175 |
|
0 | 1176 |
# broken db commands ###################################################### |
1177 |
||
1178 |
def cmd_change_attribute_type(self, etype, attr, newtype, commit=True): |
|
1179 |
"""low level method to change the type of an entity attribute. This is |
|
1180 |
a quick hack which has some drawback: |
|
1181 |
* only works when the old type can be changed to the new type by the |
|
1182 |
underlying rdbms (eg using ALTER TABLE) |
|
1183 |
* the actual schema won't be updated until next startup |
|
1184 |
""" |
|
1185 |
rschema = self.repo.schema.rschema(attr) |
|
1186 |
oldtype = rschema.objects(etype)[0] |
|
1187 |
rdefeid = rschema.rproperty(etype, oldtype, 'eid') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1188 |
sql = ("UPDATE CWAttribute " |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1189 |
"SET to_entity=(SELECT eid FROM CWEType WHERE name='%s')" |
0 | 1190 |
"WHERE eid=%s") % (newtype, rdefeid) |
1191 |
self.sqlexec(sql, ask_confirm=False) |
|
1192 |
dbhelper = self.repo.system_source.dbhelper |
|
1193 |
sqltype = dbhelper.TYPE_MAPPING[newtype] |
|
1194 |
sql = 'ALTER TABLE %s ALTER COLUMN %s TYPE %s' % (etype, attr, sqltype) |
|
1195 |
self.sqlexec(sql, ask_confirm=False) |
|
1196 |
if commit: |
|
1197 |
self.commit() |
|
1477 | 1198 |
|
0 | 1199 |
def cmd_add_entity_type_table(self, etype, commit=True): |
1200 |
"""low level method to create the sql table for an existing entity. |
|
1201 |
This may be useful on accidental desync between the repository schema |
|
1202 |
and a sql database |
|
1203 |
""" |
|
1204 |
dbhelper = self.repo.system_source.dbhelper |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1240
diff
changeset
|
1205 |
tablesql = eschema2sql(dbhelper, self.repo.schema.eschema(etype), |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1240
diff
changeset
|
1206 |
prefix=SQL_PREFIX) |
0 | 1207 |
for sql in tablesql.split(';'): |
1208 |
if sql.strip(): |
|
1209 |
self.sqlexec(sql) |
|
1210 |
if commit: |
|
1211 |
self.commit() |
|
1477 | 1212 |
|
0 | 1213 |
def cmd_add_relation_type_table(self, rtype, commit=True): |
1214 |
"""low level method to create the sql table for an existing relation. |
|
1215 |
This may be useful on accidental desync between the repository schema |
|
1216 |
and a sql database |
|
1217 |
""" |
|
1218 |
dbhelper = self.repo.system_source.dbhelper |
|
1219 |
tablesql = rschema2sql(dbhelper, self.repo.schema.rschema(rtype)) |
|
1220 |
for sql in tablesql.split(';'): |
|
1221 |
if sql.strip(): |
|
1222 |
self.sqlexec(sql) |
|
1223 |
if commit: |
|
1224 |
self.commit() |
|
1477 | 1225 |
|
0 | 1226 |
|
1227 |
class ForRqlIterator: |
|
1228 |
"""specific rql iterator to make the loop skipable""" |
|
1229 |
def __init__(self, helper, rql, kwargs, ask_confirm): |
|
1230 |
self._h = helper |
|
1231 |
self.rql = rql |
|
1232 |
self.kwargs = kwargs |
|
1233 |
self.ask_confirm = ask_confirm |
|
1234 |
self._rsetit = None |
|
1477 | 1235 |
|
0 | 1236 |
def __iter__(self): |
1237 |
return self |
|
1477 | 1238 |
|
0 | 1239 |
def next(self): |
1240 |
if self._rsetit is not None: |
|
1241 |
return self._rsetit.next() |
|
1242 |
rql, kwargs = self.rql, self.kwargs |
|
1243 |
if kwargs: |
|
1244 |
msg = '%s (%s)' % (rql, kwargs) |
|
1245 |
else: |
|
1246 |
msg = rql |
|
1247 |
if self.ask_confirm: |
|
1248 |
if not self._h.confirm('execute rql: %s ?' % msg): |
|
1249 |
raise StopIteration |
|
1250 |
try: |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
1251 |
rset = self._h._cw.execute(rql, kwargs) |
0 | 1252 |
except Exception, ex: |
1253 |
if self._h.confirm('error: %s\nabort?' % ex): |
|
1254 |
raise |
|
1255 |
else: |
|
1256 |
raise StopIteration |
|
1257 |
self._rsetit = iter(rset) |
|
1258 |
return self._rsetit.next() |