author | Laurent Peuch <cortex@worlddomination.be> |
Tue, 26 Nov 2019 20:26:58 +0100 | |
changeset 12777 | 7c4216ed7497 |
parent 12567 | 26744ad37953 |
permissions | -rw-r--r-- |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7301
diff
changeset
|
1 |
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5324
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
18 |
"""some utilities for cubicweb command line tools""" |
11767
432f87a63057
flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11693
diff
changeset
|
19 |
|
2397
cdedc2a32b06
[shell] move toolsutils.confirm() to logilab.common.shellutils
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
20 |
# XXX move most of this in logilab.common (shellutils ?) |
cdedc2a32b06
[shell] move toolsutils.confirm() to logilab.common.shellutils
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
21 |
|
10966
8909593f46d4
[toolsutils] Small fixes to fill_templated_file()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10688
diff
changeset
|
22 |
import io |
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
23 |
import os |
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
24 |
import sys |
4554
2279ba039494
use subprocess instead of os.popen to run diff
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4212
diff
changeset
|
25 |
import subprocess |
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
26 |
from os import listdir, makedirs, chmod, walk, remove |
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
27 |
from os.path import exists, join, normpath |
9740
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
28 |
import re |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
29 |
from rlcompleter import Completer |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
30 |
try: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
31 |
import readline |
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
32 |
except ImportError: # readline not available, no completion |
9740
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
33 |
pass |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2615
diff
changeset
|
34 |
try: |
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2615
diff
changeset
|
35 |
from os import symlink |
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2615
diff
changeset
|
36 |
except ImportError: |
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2615
diff
changeset
|
37 |
def symlink(*args): |
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2615
diff
changeset
|
38 |
raise NotImplementedError |
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2615
diff
changeset
|
39 |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
40 |
from logilab.common.clcommands import Command as BaseCommand |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
41 |
from logilab.common.shellutils import ASK |
0 | 42 |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
43 |
from cubicweb import warning # pylint: disable=E0611 |
0 | 44 |
from cubicweb import ConfigurationError, ExecutionError |
45 |
||
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
46 |
|
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2615
diff
changeset
|
47 |
def underline_title(title, car='-'): |
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
48 |
return title + '\n' + (car * len(title)) |
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
49 |
|
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2615
diff
changeset
|
50 |
|
0 | 51 |
def iter_dir(directory, condition_file=None, ignore=()): |
52 |
"""iterate on a directory""" |
|
53 |
for sub in listdir(directory): |
|
54 |
if sub in ('CVS', '.svn', '.hg'): |
|
55 |
continue |
|
56 |
if condition_file is not None and \ |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
57 |
not exists(join(directory, sub, condition_file)): |
0 | 58 |
continue |
59 |
if sub in ignore: |
|
60 |
continue |
|
61 |
yield sub |
|
62 |
||
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
63 |
|
0 | 64 |
def create_dir(directory): |
65 |
"""create a directory if it doesn't exist yet""" |
|
66 |
try: |
|
67 |
makedirs(directory) |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
68 |
print('-> created directory %s' % directory) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7896
diff
changeset
|
69 |
except OSError as ex: |
0 | 70 |
import errno |
71 |
if ex.errno != errno.EEXIST: |
|
72 |
raise |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
73 |
print('-> no need to create existing directory %s' % directory) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1138
diff
changeset
|
74 |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
75 |
|
0 | 76 |
def create_symlink(source, target): |
77 |
"""create a symbolic link""" |
|
78 |
if exists(target): |
|
79 |
remove(target) |
|
80 |
symlink(source, target) |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
81 |
print('[symlink] %s <-- %s' % (target, source)) |
0 | 82 |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
83 |
|
0 | 84 |
def create_copy(source, target): |
85 |
import shutil |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
86 |
print('[copy] %s <-- %s' % (target, source)) |
0 | 87 |
shutil.copy2(source, target) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1138
diff
changeset
|
88 |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
89 |
|
0 | 90 |
def rm(whatever): |
91 |
import shutil |
|
92 |
shutil.rmtree(whatever) |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
93 |
print('-> removed %s' % whatever) |
0 | 94 |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
95 |
|
0 | 96 |
def show_diffs(appl_file, ref_file, askconfirm=True): |
97 |
"""interactivly replace the old file with the new file according to |
|
98 |
user decision |
|
99 |
""" |
|
100 |
import shutil |
|
4554
2279ba039494
use subprocess instead of os.popen to run diff
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4212
diff
changeset
|
101 |
pipe = subprocess.Popen(['diff', '-u', appl_file, ref_file], stdout=subprocess.PIPE) |
12311
4d8268ef1fb7
[py3] Decode subprocess stdout in toolsutils.show_diffs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11767
diff
changeset
|
102 |
diffs = pipe.stdout.read().decode('utf-8') |
0 | 103 |
if diffs: |
104 |
if askconfirm: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
105 |
print() |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
106 |
print(diffs) |
5324
449cc4fa9c42
[migration] makes Yes the default answer to replace configuration file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
107 |
action = ASK.ask('Replace ?', ('Y', 'n', 'q'), 'Y').lower() |
0 | 108 |
else: |
109 |
action = 'y' |
|
110 |
if action == 'y': |
|
111 |
try: |
|
112 |
shutil.copyfile(ref_file, appl_file) |
|
113 |
except IOError: |
|
114 |
os.system('chmod a+w %s' % appl_file) |
|
115 |
shutil.copyfile(ref_file, appl_file) |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
116 |
print('replaced') |
0 | 117 |
elif action == 'q': |
118 |
sys.exit(0) |
|
119 |
else: |
|
120 |
copy_file = appl_file + '.default' |
|
10614
57dfde80df11
[py3k] file → open
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10591
diff
changeset
|
121 |
copy = open(copy_file, 'w') |
0 | 122 |
copy.write(open(ref_file).read()) |
123 |
copy.close() |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
124 |
print('keep current version, the new file has been written to', copy_file) |
0 | 125 |
else: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
126 |
print('no diff between %s and %s' % (appl_file, ref_file)) |
0 | 127 |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
128 |
|
5184
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
129 |
SKEL_EXCLUDE = ('*.py[co]', '*.orig', '*~', '*_flymake.py') |
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
130 |
|
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
131 |
|
0 | 132 |
def copy_skeleton(skeldir, targetdir, context, |
5184
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
133 |
exclude=SKEL_EXCLUDE, askconfirm=False): |
0 | 134 |
import shutil |
135 |
from fnmatch import fnmatch |
|
136 |
skeldir = normpath(skeldir) |
|
137 |
targetdir = normpath(targetdir) |
|
138 |
for dirpath, dirnames, filenames in walk(skeldir): |
|
139 |
tdirpath = dirpath.replace(skeldir, targetdir) |
|
11454
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11057
diff
changeset
|
140 |
if 'cubicweb_CUBENAME' in tdirpath: |
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11057
diff
changeset
|
141 |
tdirpath = tdirpath.replace('cubicweb_CUBENAME', |
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11057
diff
changeset
|
142 |
'cubicweb_' + context['cubename']) |
0 | 143 |
create_dir(tdirpath) |
144 |
for fname in filenames: |
|
145 |
if any(fnmatch(fname, pat) for pat in exclude): |
|
146 |
continue |
|
147 |
fpath = join(dirpath, fname) |
|
148 |
if 'CUBENAME' in fname: |
|
149 |
tfpath = join(tdirpath, fname.replace('CUBENAME', context['cubename'])) |
|
150 |
elif 'DISTNAME' in fname: |
|
151 |
tfpath = join(tdirpath, fname.replace('DISTNAME', context['distname'])) |
|
152 |
else: |
|
153 |
tfpath = join(tdirpath, fname) |
|
154 |
if fname.endswith('.tmpl'): |
|
155 |
tfpath = tfpath[:-5] |
|
156 |
if not askconfirm or not exists(tfpath) or \ |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
157 |
ASK.confirm('%s exists, overwrite?' % tfpath): |
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
158 |
fill_templated_file(fpath, tfpath, context) |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
159 |
print('[generate] %s <-- %s' % (tfpath, fpath)) |
0 | 160 |
elif exists(tfpath): |
161 |
show_diffs(tfpath, fpath, askconfirm) |
|
162 |
else: |
|
163 |
shutil.copyfile(fpath, tfpath) |
|
11693
b44c0d2462c9
[skeleton] Copy files mode bits (debian/rules in particular)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11476
diff
changeset
|
164 |
shutil.copymode(fpath, tfpath) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1138
diff
changeset
|
165 |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
166 |
|
0 | 167 |
def fill_templated_file(fpath, tfpath, context): |
10966
8909593f46d4
[toolsutils] Small fixes to fill_templated_file()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10688
diff
changeset
|
168 |
with io.open(fpath, encoding='ascii') as fobj: |
8909593f46d4
[toolsutils] Small fixes to fill_templated_file()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10688
diff
changeset
|
169 |
template = fobj.read() |
8909593f46d4
[toolsutils] Small fixes to fill_templated_file()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10688
diff
changeset
|
170 |
with io.open(tfpath, 'w', encoding='ascii') as fobj: |
8909593f46d4
[toolsutils] Small fixes to fill_templated_file()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10688
diff
changeset
|
171 |
fobj.write(template % context) |
0 | 172 |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
173 |
|
0 | 174 |
def restrict_perms_to_user(filepath, log=None): |
175 |
"""set -rw------- permission on the given file""" |
|
176 |
if log: |
|
7155
4bab50b02927
[cwctl] refactor ui messages aiming for consistency and simplicity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6495
diff
changeset
|
177 |
log('set permissions to 0600 for %s', filepath) |
0 | 178 |
else: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
179 |
print('-> set permissions to 0600 for %s' % filepath) |
10591
8e46ed1a0b8a
[py3k] octals and long
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10589
diff
changeset
|
180 |
chmod(filepath, 0o600) |
0 | 181 |
|
11476
a9f26de5ea6c
Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11454
diff
changeset
|
182 |
|
a9f26de5ea6c
Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11454
diff
changeset
|
183 |
def option_value_from_env(option, default=None): |
a9f26de5ea6c
Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11454
diff
changeset
|
184 |
"""Return the value of configuration `option` from cannonical environment |
a9f26de5ea6c
Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11454
diff
changeset
|
185 |
variable. |
a9f26de5ea6c
Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11454
diff
changeset
|
186 |
""" |
a9f26de5ea6c
Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11454
diff
changeset
|
187 |
envvar = ('CW_' + '_'.join(option.split('-'))).upper() |
a9f26de5ea6c
Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11454
diff
changeset
|
188 |
return os.environ.get(envvar, default) |
a9f26de5ea6c
Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11454
diff
changeset
|
189 |
|
a9f26de5ea6c
Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11454
diff
changeset
|
190 |
|
7301
93e96700e0c0
[configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7155
diff
changeset
|
191 |
def read_config(config_file, raise_if_unreadable=False): |
93e96700e0c0
[configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7155
diff
changeset
|
192 |
"""read some simple configuration from `config_file` and return it as a |
93e96700e0c0
[configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7155
diff
changeset
|
193 |
dictionary. If `raise_if_unreadable` is false (the default), an empty |
93e96700e0c0
[configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7155
diff
changeset
|
194 |
dictionary will be returned if the file is inexistant or unreadable, else |
93e96700e0c0
[configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7155
diff
changeset
|
195 |
:exc:`ExecutionError` will be raised. |
0 | 196 |
""" |
197 |
from logilab.common.fileutils import lines |
|
198 |
config = current = {} |
|
199 |
try: |
|
200 |
for line in lines(config_file, comments='#'): |
|
201 |
try: |
|
202 |
option, value = line.split('=', 1) |
|
203 |
except ValueError: |
|
204 |
option = line.strip().lower() |
|
205 |
if option[0] == '[': |
|
206 |
# start a section |
|
207 |
section = option[1:-1] |
|
8697
574bb05e40a4
[toward py3k] rewrite has_key() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
208 |
assert section not in config, \ |
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
209 |
'Section %s is defined more than once' % section |
0 | 210 |
config[section] = current = {} |
211 |
continue |
|
7896
4c954e1e73ef
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7879
diff
changeset
|
212 |
sys.stderr.write('ignoring malformed line\n%r\n' % line) |
0 | 213 |
continue |
214 |
option = option.strip().replace(' ', '_') |
|
11476
a9f26de5ea6c
Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11454
diff
changeset
|
215 |
value = option_value_from_env(option, value.strip()) |
0 | 216 |
current[option] = value or None |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7896
diff
changeset
|
217 |
except IOError as ex: |
7301
93e96700e0c0
[configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7155
diff
changeset
|
218 |
if raise_if_unreadable: |
93e96700e0c0
[configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7155
diff
changeset
|
219 |
raise ExecutionError('%s. Are you logged with the correct user ' |
93e96700e0c0
[configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7155
diff
changeset
|
220 |
'to use this instance?' % ex) |
93e96700e0c0
[configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7155
diff
changeset
|
221 |
else: |
93e96700e0c0
[configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7155
diff
changeset
|
222 |
warning('missing or non readable configuration file %s (%s)', |
93e96700e0c0
[configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7155
diff
changeset
|
223 |
config_file, ex) |
0 | 224 |
return config |
225 |
||
226 |
||
227 |
_HDLRS = {} |
|
228 |
||
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
229 |
|
0 | 230 |
class metacmdhandler(type): |
231 |
def __new__(mcs, name, bases, classdict): |
|
232 |
cls = super(metacmdhandler, mcs).__new__(mcs, name, bases, classdict) |
|
233 |
if getattr(cls, 'cfgname', None) and getattr(cls, 'cmdname', None): |
|
234 |
_HDLRS.setdefault(cls.cmdname, []).append(cls) |
|
235 |
return cls |
|
236 |
||
237 |
||
12567
26744ad37953
Drop python2 support
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12312
diff
changeset
|
238 |
class CommandHandler(object, metaclass=metacmdhandler): |
0 | 239 |
"""configuration specific helper for cubicweb-ctl commands""" |
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
240 |
|
0 | 241 |
def __init__(self, config): |
242 |
self.config = config |
|
243 |
||
10688
fa29f3628a1b
[py3k] use six.add_metaclass
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
244 |
|
0 | 245 |
class Command(BaseCommand): |
246 |
"""base class for cubicweb-ctl commands""" |
|
247 |
||
248 |
def config_helper(self, config, required=True, cmdname=None): |
|
249 |
if cmdname is None: |
|
250 |
cmdname = self.name |
|
251 |
for helpercls in _HDLRS.get(cmdname, ()): |
|
252 |
if helpercls.cfgname == config.name: |
|
253 |
return helpercls(config) |
|
254 |
if config.name == 'all-in-one': |
|
255 |
for helpercls in _HDLRS.get(cmdname, ()): |
|
256 |
if helpercls.cfgname == 'repository': |
|
257 |
return helpercls(config) |
|
258 |
if required: |
|
259 |
msg = 'No helper for command %s using %s configuration' % ( |
|
260 |
cmdname, config.name) |
|
261 |
raise ConfigurationError(msg) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1138
diff
changeset
|
262 |
|
0 | 263 |
def fail(self, reason): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10331
diff
changeset
|
264 |
print("command failed:", reason) |
0 | 265 |
sys.exit(1) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1138
diff
changeset
|
266 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1138
diff
changeset
|
267 |
|
0 | 268 |
CONNECT_OPTIONS = ( |
269 |
("user", |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
270 |
{'short': 'u', 'type': 'string', 'metavar': '<user>', |
0 | 271 |
'help': 'connect as <user> instead of being prompted to give it.', |
272 |
} |
|
273 |
), |
|
274 |
("password", |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
275 |
{'short': 'p', 'type': 'password', 'metavar': '<password>', |
0 | 276 |
'help': 'automatically give <password> for authentication instead of \ |
277 |
being prompted to give it.', |
|
278 |
}), |
|
279 |
("host", |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
280 |
{'short': 'H', 'type': 'string', 'metavar': '<hostname>', |
541
0d75cfe50f83
fix default value of pyro ns host
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
281 |
'default': None, |
0 | 282 |
'help': 'specify the name server\'s host name. Will be detected by \ |
283 |
broadcast if not provided.', |
|
284 |
}), |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
285 |
) |
0 | 286 |
|
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
287 |
# cwshell helpers ############################################################# |
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
288 |
|
9740
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
289 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
290 |
class AbstractMatcher(object): |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
291 |
"""Abstract class for CWShellCompleter's matchers. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
292 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
293 |
A matcher should implement a ``possible_matches`` method. This |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
294 |
method has to return the list of possible completions for user's input. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
295 |
Because of the python / readline interaction, each completion should |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
296 |
be a superset of the user's input. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
297 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
298 |
NOTE: readline tokenizes user's input and only passes last token to |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
299 |
completers. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
300 |
""" |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
301 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
302 |
def possible_matches(self, text): |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
303 |
"""return possible completions for user's input. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
304 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
305 |
Parameters: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
306 |
text: the user's input |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
307 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
308 |
Return: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
309 |
a list of completions. Each completion includes the original input. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
310 |
""" |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
311 |
raise NotImplementedError() |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
312 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
313 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
314 |
class RQLExecuteMatcher(AbstractMatcher): |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
315 |
"""Custom matcher for rql queries. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
316 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
317 |
If user's input starts with ``rql(`` or ``session.execute(`` and |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
318 |
the corresponding rql query is incomplete, suggest some valid completions. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
319 |
""" |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
320 |
query_match_rgx = re.compile( |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
321 |
r'(?P<func_prefix>\s*(?:rql)' # match rql, possibly indented |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
322 |
r'|' # or |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
323 |
r'\s*(?:\w+\.execute))' # match .execute, possibly indented |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
324 |
# end of <func_prefix> |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
325 |
r'\(' # followed by a parenthesis |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
326 |
r'(?P<quote_delim>["\'])' # a quote or double quote |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
327 |
r'(?P<parameters>.*)') # and some content |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
328 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
329 |
def __init__(self, local_ctx, req): |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
330 |
self.local_ctx = local_ctx |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
331 |
self.req = req |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
332 |
self.schema = req.vreg.schema |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
333 |
self.rsb = req.vreg['components'].select('rql.suggestions', req) |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
334 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
335 |
@staticmethod |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
336 |
def match(text): |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
337 |
"""check if ``text`` looks like a call to ``rql`` or ``session.execute`` |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
338 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
339 |
Parameters: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
340 |
text: the user's input |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
341 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
342 |
Returns: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
343 |
None if it doesn't match, the query structure otherwise. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
344 |
""" |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
345 |
query_match = RQLExecuteMatcher.query_match_rgx.match(text) |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
346 |
if query_match is None: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
347 |
return None |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
348 |
parameters_text = query_match.group('parameters') |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
349 |
quote_delim = query_match.group('quote_delim') |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
350 |
# first parameter is fully specified, no completion needed |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
351 |
if re.match(r"(.*?)%s" % quote_delim, parameters_text) is not None: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
352 |
return None |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
353 |
func_prefix = query_match.group('func_prefix') |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
354 |
return { |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
355 |
# user's input |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
356 |
'text': text, |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
357 |
# rql( or session.execute( |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
358 |
'func_prefix': func_prefix, |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
359 |
# offset of rql query |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
360 |
'rql_offset': len(func_prefix) + 2, |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
361 |
# incomplete rql query |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
362 |
'rql_query': parameters_text, |
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
363 |
} |
9740
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
364 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
365 |
def possible_matches(self, text): |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
366 |
"""call ``rql.suggestions`` component to complete user's input. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
367 |
""" |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
368 |
# readline will only send last token, but we need the entire user's input |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
369 |
user_input = readline.get_line_buffer() |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
370 |
query_struct = self.match(user_input) |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
371 |
if query_struct is None: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
372 |
return [] |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
373 |
else: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
374 |
# we must only send completions of the last token => compute where it |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
375 |
# starts relatively to the rql query itself. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
376 |
completion_offset = readline.get_begidx() - query_struct['rql_offset'] |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
377 |
rql_query = query_struct['rql_query'] |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
378 |
return [suggestion[completion_offset:] |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
379 |
for suggestion in self.rsb.build_suggestions(rql_query)] |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
380 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
381 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
382 |
class DefaultMatcher(AbstractMatcher): |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
383 |
"""Default matcher: delegate to standard's `rlcompleter.Completer`` class |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
384 |
""" |
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
385 |
|
9740
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
386 |
def __init__(self, local_ctx): |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
387 |
self.completer = Completer(local_ctx) |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
388 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
389 |
def possible_matches(self, text): |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
390 |
if "." in text: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
391 |
return self.completer.attr_matches(text) |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
392 |
else: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
393 |
return self.completer.global_matches(text) |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
394 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
395 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
396 |
class CWShellCompleter(object): |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
397 |
"""Custom auto-completion helper for cubicweb-ctl shell. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
398 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
399 |
``CWShellCompleter`` provides a ``complete`` method suitable for |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
400 |
``readline.set_completer``. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
401 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
402 |
Attributes: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
403 |
matchers: the list of ``AbstractMatcher`` instances that will suggest |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
404 |
possible completions |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
405 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
406 |
The completion process is the following: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
407 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
408 |
- readline calls the ``complete`` method with user's input, |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
409 |
- the ``complete`` method asks for each known matchers if |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
410 |
it can suggest completions for user's input. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
411 |
""" |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
412 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
413 |
def __init__(self, local_ctx): |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
414 |
# list of matchers to ask for possible matches on completion |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
415 |
self.matchers = [DefaultMatcher(local_ctx)] |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
416 |
self.matchers.insert(0, RQLExecuteMatcher(local_ctx, local_ctx['session'])) |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
417 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
418 |
def complete(self, text, state): |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
419 |
"""readline's completer method |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
420 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
421 |
cf http://docs.python.org/2/library/readline.html#readline.set_completer |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
422 |
for more details. |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
423 |
|
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
424 |
Implementation inspired by `rlcompleter.Completer` |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
425 |
""" |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
426 |
if state == 0: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
427 |
# reset self.matches |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
428 |
self.matches = [] |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
429 |
for matcher in self.matchers: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
430 |
matches = matcher.possible_matches(text) |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
431 |
if matches: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
432 |
self.matches = matches |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
433 |
break |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
434 |
else: |
12312
a7c4b13a2d60
[style] Make toolsutils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12311
diff
changeset
|
435 |
return None # no matcher able to handle `text` |
9740
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
436 |
try: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
437 |
return self.matches[state] |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
438 |
except IndexError: |
c0239d8ae742
[shell] provide autocompletion for rql queries in cubicweb-ctl shell (closes #3560541)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8697
diff
changeset
|
439 |
return None |