author | Sandrine Ribeau <sandrine.ribeau@logilab.fr> |
Mon, 08 Dec 2008 17:33:58 -0800 | |
changeset 193 | cd9cc0153835 |
parent 155 | 9ed6db94a087 |
child 264 | 6eb0725d509d |
permissions | -rw-r--r-- |
0 | 1 |
"""additional cubicweb-ctl commands and command handlers for cubicweb and cubicweb's |
2 |
cubes development |
|
3 |
||
4 |
:organization: Logilab |
|
5 |
:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
7 |
""" |
|
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
import sys |
|
11 |
from os import walk, mkdir, chdir, listdir |
|
12 |
from os.path import join, exists, abspath, basename, normpath, split, isdir |
|
13 |
||
14 |
||
15 |
from logilab.common import STD_BLACKLIST |
|
16 |
from logilab.common.modutils import get_module_files |
|
17 |
from logilab.common.textutils import get_csv |
|
18 |
||
19 |
from cubicweb import CW_SOFTWARE_ROOT as BASEDIR |
|
20 |
from cubicweb.__pkginfo__ import version as cubicwebversion |
|
21 |
from cubicweb import BadCommandUsage |
|
22 |
from cubicweb.toolsutils import Command, register_commands, confirm, copy_skeleton |
|
23 |
from cubicweb.web.webconfig import WebConfiguration |
|
24 |
from cubicweb.server.serverconfig import ServerConfiguration |
|
25 |
||
26 |
||
27 |
class DevConfiguration(ServerConfiguration, WebConfiguration): |
|
28 |
"""dummy config to get full library schema and entities""" |
|
29 |
creating = True |
|
30 |
def __init__(self, appid=None, cube=None): |
|
31 |
self._cube = cube |
|
32 |
super(DevConfiguration, self).__init__(appid) |
|
33 |
if self._cube is None: |
|
34 |
self._cubes = () |
|
35 |
else: |
|
36 |
self._cubes = self.expand_cubes(self.cube_dependencies(self._cube)) |
|
37 |
||
38 |
# def adjust_sys_path(self): |
|
39 |
# # update python path if necessary |
|
40 |
# if not self.cubes_dir() in sys.path: |
|
41 |
# sys.path.insert(0, self.cubes_dir()) |
|
42 |
||
43 |
@property |
|
44 |
def apphome(self): |
|
45 |
return self.appid |
|
46 |
||
47 |
def init_log(self, debug=None): |
|
48 |
pass |
|
49 |
def load_configuration(self): |
|
50 |
pass |
|
51 |
||
52 |
cubicweb_vobject_path = ServerConfiguration.cubicweb_vobject_path | WebConfiguration.cubicweb_vobject_path |
|
53 |
cube_vobject_path = ServerConfiguration.cube_vobject_path | WebConfiguration.cube_vobject_path |
|
54 |
||
55 |
||
56 |
def generate_schema_pot(w, cubedir=None): |
|
57 |
"""generate a pot file with schema specific i18n messages |
|
58 |
||
59 |
notice that relation definitions description and static vocabulary |
|
60 |
should be marked using '_' and extracted using xgettext |
|
61 |
""" |
|
62 |
from cubicweb.cwvreg import CubicWebRegistry |
|
63 |
cube = cubedir and split(cubedir)[-1] |
|
64 |
config = DevConfiguration(join(BASEDIR, 'web'), cube) |
|
65 |
if cubedir: |
|
66 |
libschema = config.load_schema() |
|
67 |
config = DevConfiguration(cubedir, cube) |
|
68 |
schema = config.load_schema() |
|
69 |
else: |
|
70 |
schema = config.load_schema() |
|
71 |
libschema = None |
|
72 |
config.cleanup_interface_sobjects = False |
|
73 |
vreg = CubicWebRegistry(config) |
|
74 |
vreg.set_schema(schema) |
|
75 |
vreg.register_objects(config.vregistry_path()) |
|
76 |
w(DEFAULT_POT_HEAD) |
|
77 |
_generate_schema_pot(w, vreg, schema, libschema=libschema, |
|
78 |
cube=cube) |
|
79 |
# cleanup sys.modules, required when we're updating multiple cubes |
|
80 |
for name, mod in sys.modules.items(): |
|
81 |
if mod is None: |
|
82 |
# duh ? logilab.common.os for instance |
|
83 |
del sys.modules[name] |
|
84 |
continue |
|
85 |
if not hasattr(mod, '__file__'): |
|
86 |
continue |
|
87 |
for path in config.vregistry_path(): |
|
88 |
if mod.__file__.startswith(path): |
|
89 |
del sys.modules[name] |
|
90 |
break |
|
91 |
||
92 |
def _generate_schema_pot(w, vreg, schema, libschema=None, cube=None): |
|
93 |
from mx.DateTime import now |
|
94 |
from cubicweb.common.i18n import add_msg |
|
95 |
w('# schema pot file, generated on %s\n' % now().strftime('%Y-%m-%d %H:%M:%S')) |
|
96 |
w('# \n') |
|
97 |
w('# singular and plural forms for each entity type\n') |
|
98 |
w('\n') |
|
99 |
if libschema is not None: |
|
100 |
entities = [e for e in schema.entities() if not e in libschema] |
|
101 |
else: |
|
102 |
entities = schema.entities() |
|
103 |
done = set() |
|
104 |
for eschema in sorted(entities): |
|
105 |
etype = eschema.type |
|
106 |
add_msg(w, etype) |
|
107 |
add_msg(w, '%s_plural' % etype) |
|
108 |
if not eschema.is_final(): |
|
109 |
add_msg(w, 'This %s' % etype) |
|
110 |
add_msg(w, 'New %s' % etype) |
|
111 |
add_msg(w, 'add a %s' % etype) |
|
112 |
add_msg(w, 'remove this %s' % etype) |
|
113 |
if eschema.description and not eschema.description in done: |
|
114 |
done.add(eschema.description) |
|
115 |
add_msg(w, eschema.description) |
|
116 |
w('# subject and object forms for each relation type\n') |
|
117 |
w('# (no object form for final relation types)\n') |
|
118 |
w('\n') |
|
119 |
if libschema is not None: |
|
120 |
relations = [r for r in schema.relations() if not r in libschema] |
|
121 |
else: |
|
122 |
relations = schema.relations() |
|
123 |
for rschema in sorted(set(relations)): |
|
124 |
rtype = rschema.type |
|
125 |
add_msg(w, rtype) |
|
57
3ab952845448
[devctl] fix bug in i18nlibupdate
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
126 |
done.add(rtype) |
0 | 127 |
if not (schema.rschema(rtype).is_final() or rschema.symetric): |
128 |
add_msg(w, '%s_object' % rtype) |
|
129 |
if rschema.description and rschema.description not in done: |
|
130 |
done.add(rschema.description) |
|
131 |
add_msg(w, rschema.description) |
|
132 |
w('# add related box generated message\n') |
|
133 |
w('\n') |
|
134 |
for eschema in schema.entities(): |
|
135 |
if eschema.is_final(): |
|
136 |
continue |
|
137 |
entity = vreg.etype_class(eschema)(None, None) |
|
138 |
for x, rschemas in (('subject', eschema.subject_relations()), |
|
139 |
('object', eschema.object_relations())): |
|
140 |
for rschema in rschemas: |
|
141 |
if rschema.is_final(): |
|
142 |
continue |
|
143 |
for teschema in rschema.targets(eschema, x): |
|
144 |
if defined_in_library(libschema, eschema, rschema, teschema, x): |
|
145 |
continue |
|
146 |
if entity.relation_mode(rschema.type, teschema.type, x) == 'create': |
|
147 |
if x == 'subject': |
|
148 |
label = 'add %s %s %s %s' % (eschema, rschema, teschema, x) |
|
149 |
label2 = "creating %s (%s %%(linkto)s %s %s)" % (teschema, eschema, rschema, teschema) |
|
150 |
else: |
|
151 |
label = 'add %s %s %s %s' % (teschema, rschema, eschema, x) |
|
152 |
label2 = "creating %s (%s %s %s %%(linkto)s)" % (teschema, teschema, rschema, eschema) |
|
153 |
add_msg(w, label) |
|
154 |
add_msg(w, label2) |
|
155 |
cube = (cube or 'cubicweb') + '.' |
|
156 |
done = set() |
|
157 |
for reg, objdict in vreg.items(): |
|
158 |
for objects in objdict.values(): |
|
159 |
for obj in objects: |
|
160 |
objid = '%s_%s' % (reg, obj.id) |
|
161 |
if objid in done: |
|
162 |
continue |
|
163 |
if obj.__module__.startswith(cube) and obj.property_defs: |
|
164 |
add_msg(w, '%s_description' % objid) |
|
165 |
add_msg(w, objid) |
|
166 |
done.add(objid) |
|
167 |
||
168 |
def defined_in_library(libschema, etype, rtype, tetype, x): |
|
169 |
"""return true if the given relation definition exists in cubicweb's library""" |
|
170 |
if libschema is None: |
|
171 |
return False |
|
172 |
if x == 'subject': |
|
173 |
subjtype, objtype = etype, tetype |
|
174 |
else: |
|
175 |
subjtype, objtype = tetype, etype |
|
176 |
try: |
|
177 |
return libschema.rschema(rtype).has_rdef(subjtype, objtype) |
|
178 |
except KeyError: |
|
179 |
return False |
|
180 |
||
181 |
||
155
9ed6db94a087
spanish is now a supported language
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
133
diff
changeset
|
182 |
LANGS = ('en', 'fr', 'es') |
0 | 183 |
I18NDIR = join(BASEDIR, 'i18n') |
184 |
DEFAULT_POT_HEAD = r'''msgid "" |
|
185 |
msgstr "" |
|
186 |
"Project-Id-Version: cubicweb %s\n" |
|
187 |
"PO-Revision-Date: 2008-03-28 18:14+0100\n" |
|
188 |
"Last-Translator: Logilab Team <contact@logilab.fr>\n" |
|
189 |
"Language-Team: fr <contact@logilab.fr>\n" |
|
190 |
"MIME-Version: 1.0\n" |
|
191 |
"Content-Type: text/plain; charset=UTF-8\n" |
|
192 |
"Content-Transfer-Encoding: 8bit\n" |
|
193 |
"Generated-By: cubicweb-devtools\n" |
|
194 |
"Plural-Forms: nplurals=2; plural=(n > 1);\n" |
|
195 |
||
196 |
''' % cubicwebversion |
|
197 |
||
198 |
||
199 |
class UpdateCubicWebCatalogCommand(Command): |
|
200 |
"""Update i18n catalogs for cubicweb library. |
|
201 |
|
|
202 |
It will regenerate cubicweb/i18n/xx.po files. You'll have then to edit those |
|
203 |
files to add translations of newly added messages. |
|
204 |
""" |
|
205 |
name = 'i18nlibupdate' |
|
206 |
||
207 |
def run(self, args): |
|
208 |
"""run the command with its specific arguments""" |
|
209 |
if args: |
|
210 |
raise BadCommandUsage('Too much arguments') |
|
211 |
import shutil |
|
212 |
from tempfile import mktemp |
|
213 |
import yams |
|
214 |
from logilab.common.fileutils import ensure_fs_mode |
|
58
c7c22b210372
only try to internationalize our own js files
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
57
diff
changeset
|
215 |
from logilab.common.shellutils import globfind, find, rm |
0 | 216 |
from cubicweb.common.i18n import extract_from_tal, execute |
217 |
tempdir = mktemp() |
|
218 |
mkdir(tempdir) |
|
219 |
potfiles = [join(I18NDIR, 'entities.pot')] |
|
220 |
print '******** extract schema messages' |
|
221 |
schemapot = join(tempdir, 'schema.pot') |
|
222 |
potfiles.append(schemapot) |
|
223 |
# explicit close necessary else the file may not be yet flushed when |
|
224 |
# we'll using it below |
|
225 |
schemapotstream = file(schemapot, 'w') |
|
226 |
generate_schema_pot(schemapotstream.write, cubedir=None) |
|
227 |
schemapotstream.close() |
|
228 |
print '******** extract TAL messages' |
|
229 |
tali18nfile = join(tempdir, 'tali18n.py') |
|
230 |
extract_from_tal(find(join(BASEDIR, 'web'), ('.py', '.pt')), tali18nfile) |
|
231 |
print '******** .pot files generation' |
|
61
081078d5b422
rename one of the generated pot files (cubicweb pycubicweb.pot) to avoid problems when msgcats overwrites cubicweb.pot
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
60
diff
changeset
|
232 |
for id, files, lang in [('pycubicweb', get_module_files(BASEDIR) + list(globfind(join(BASEDIR, 'misc', 'migration'), '*.py')), None), |
58
c7c22b210372
only try to internationalize our own js files
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
57
diff
changeset
|
233 |
('schemadescr', globfind(join(BASEDIR, 'schemas'), '*.py'), None), |
0 | 234 |
('yams', get_module_files(yams.__path__[0]), None), |
235 |
('tal', [tali18nfile], None), |
|
58
c7c22b210372
only try to internationalize our own js files
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
57
diff
changeset
|
236 |
('js', globfind(join(BASEDIR, 'web'), 'cub*.js'), 'java'), |
0 | 237 |
]: |
60
dc90556488d8
oops, bad changeset review, revert debug changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
58
diff
changeset
|
238 |
cmd = 'xgettext --no-location --omit-header -k_ -o %s %s' |
0 | 239 |
if lang is not None: |
240 |
cmd += ' -L %s' % lang |
|
241 |
potfiles.append(join(tempdir, '%s.pot' % id)) |
|
242 |
execute(cmd % (potfiles[-1], ' '.join(files))) |
|
243 |
print '******** merging .pot files' |
|
244 |
cubicwebpot = join(tempdir, 'cubicweb.pot') |
|
245 |
execute('msgcat %s > %s' % (' '.join(potfiles), cubicwebpot)) |
|
246 |
print '******** merging main pot file with existing translations' |
|
247 |
chdir(I18NDIR) |
|
248 |
toedit = [] |
|
249 |
for lang in LANGS: |
|
250 |
target = '%s.po' % lang |
|
251 |
execute('msgmerge -N --sort-output %s %s > %snew' % (target, cubicwebpot, target)) |
|
252 |
ensure_fs_mode(target) |
|
253 |
shutil.move('%snew' % target, target) |
|
254 |
toedit.append(abspath(target)) |
|
255 |
# cleanup |
|
60
dc90556488d8
oops, bad changeset review, revert debug changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
58
diff
changeset
|
256 |
rm(tempdir) |
0 | 257 |
# instructions pour la suite |
258 |
print '*' * 72 |
|
259 |
print 'you can now edit the following files:' |
|
260 |
print '* ' + '\n* '.join(toedit) |
|
261 |
print |
|
262 |
print "then you'll have to update cubes catalogs using the i18nupdate command" |
|
263 |
||
264 |
||
265 |
class UpdateTemplateCatalogCommand(Command): |
|
266 |
"""Update i18n catalogs for cubes. If no cube is specified, update |
|
267 |
catalogs of all registered cubes. |
|
268 |
""" |
|
269 |
name = 'i18nupdate' |
|
270 |
arguments = '[<cube>...]' |
|
271 |
||
272 |
def run(self, args): |
|
273 |
"""run the command with its specific arguments""" |
|
274 |
CUBEDIR = DevConfiguration.cubes_dir() |
|
275 |
if args: |
|
276 |
cubes = [join(CUBEDIR, app) for app in args] |
|
277 |
else: |
|
278 |
cubes = [join(CUBEDIR, app) for app in listdir(CUBEDIR) |
|
279 |
if exists(join(CUBEDIR, app, 'i18n'))] |
|
280 |
update_cubes_catalogs(cubes) |
|
281 |
||
282 |
def update_cubes_catalogs(cubes): |
|
283 |
import shutil |
|
284 |
from tempfile import mktemp |
|
285 |
from logilab.common.fileutils import ensure_fs_mode |
|
286 |
from logilab.common.shellutils import find, rm |
|
287 |
from cubicweb.common.i18n import extract_from_tal, execute |
|
288 |
toedit = [] |
|
289 |
for cubedir in cubes: |
|
290 |
cube = basename(normpath(cubedir)) |
|
291 |
if not isdir(cubedir): |
|
292 |
print 'unknown cube', cube |
|
293 |
continue |
|
294 |
tempdir = mktemp() |
|
295 |
mkdir(tempdir) |
|
296 |
print '*' * 72 |
|
297 |
print 'updating %s cube...' % cube |
|
298 |
chdir(cubedir) |
|
299 |
potfiles = [join('i18n', scfile) for scfile in ('entities.pot',) |
|
300 |
if exists(join('i18n', scfile))] |
|
301 |
print '******** extract schema messages' |
|
302 |
schemapot = join(tempdir, 'schema.pot') |
|
303 |
potfiles.append(schemapot) |
|
304 |
# explicit close necessary else the file may not be yet flushed when |
|
305 |
# we'll using it below |
|
306 |
schemapotstream = file(schemapot, 'w') |
|
307 |
generate_schema_pot(schemapotstream.write, cubedir) |
|
308 |
schemapotstream.close() |
|
309 |
print '******** extract TAL messages' |
|
310 |
tali18nfile = join(tempdir, 'tali18n.py') |
|
311 |
extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile) |
|
312 |
print '******** extract Javascript messages' |
|
58
c7c22b210372
only try to internationalize our own js files
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
57
diff
changeset
|
313 |
jsfiles = [jsfile for jsfile in find('.', '.js') if basename(jsfile).startswith('cub')] |
0 | 314 |
if jsfiles: |
315 |
tmppotfile = join(tempdir, 'js.pot') |
|
316 |
execute('xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s' |
|
317 |
% (tmppotfile, ' '.join(jsfiles))) |
|
318 |
# no pot file created if there are no string to translate |
|
319 |
if exists(tmppotfile): |
|
320 |
potfiles.append(tmppotfile) |
|
321 |
print '******** create cube specific catalog' |
|
322 |
tmppotfile = join(tempdir, 'generated.pot') |
|
323 |
cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',)) |
|
324 |
cubefiles.append(tali18nfile) |
|
325 |
execute('xgettext --no-location --omit-header -k_ -o %s %s' |
|
326 |
% (tmppotfile, ' '.join(cubefiles))) |
|
327 |
if exists(tmppotfile): # doesn't exists of no translation string found |
|
328 |
potfiles.append(tmppotfile) |
|
329 |
potfile = join(tempdir, 'cube.pot') |
|
330 |
print '******** merging .pot files' |
|
331 |
execute('msgcat %s > %s' % (' '.join(potfiles), potfile)) |
|
332 |
print '******** merging main pot file with existing translations' |
|
333 |
chdir('i18n') |
|
334 |
for lang in LANGS: |
|
335 |
print '****', lang |
|
336 |
cubepo = '%s.po' % lang |
|
337 |
if not exists(cubepo): |
|
338 |
shutil.copy(potfile, cubepo) |
|
339 |
else: |
|
340 |
execute('msgmerge -N -s %s %s > %snew' % (cubepo, potfile, cubepo)) |
|
341 |
ensure_fs_mode(cubepo) |
|
342 |
shutil.move('%snew' % cubepo, cubepo) |
|
343 |
toedit.append(abspath(cubepo)) |
|
344 |
# cleanup |
|
345 |
rm(tempdir) |
|
346 |
# instructions pour la suite |
|
347 |
print '*' * 72 |
|
348 |
print 'you can now edit the following files:' |
|
349 |
print '* ' + '\n* '.join(toedit) |
|
350 |
||
351 |
||
352 |
class LiveServerCommand(Command): |
|
353 |
"""Run a server from within a cube directory. |
|
354 |
""" |
|
355 |
name = 'live-server' |
|
356 |
arguments = '' |
|
357 |
options = () |
|
358 |
||
359 |
def run(self, args): |
|
360 |
"""run the command with its specific arguments""" |
|
361 |
from cubicweb.devtools.livetest import runserver |
|
362 |
runserver() |
|
363 |
||
364 |
||
132
561671b87c22
rename NewTemplateCommand class into NewCubeCommand
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
61
diff
changeset
|
365 |
class NewCubeCommand(Command): |
0 | 366 |
"""Create a new cube. |
367 |
||
368 |
<cubename> |
|
369 |
the name of the new cube |
|
370 |
""" |
|
371 |
name = 'newcube' |
|
372 |
arguments = '<cubename>' |
|
373 |
||
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
374 |
options = ( |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
375 |
("verbose", |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
376 |
{'short': 'v', 'type' : 'yn', 'metavar': '<verbose>', |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
377 |
'default': 'n', |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
378 |
'help': 'verbose mode: will ask all possible configuration questions', |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
379 |
} |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
380 |
), |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
381 |
) |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
382 |
|
0 | 383 |
|
384 |
def run(self, args): |
|
385 |
if len(args) != 1: |
|
386 |
raise BadCommandUsage("exactly one argument (cube name) is expected") |
|
387 |
cubename, = args |
|
388 |
if ServerConfiguration.mode != "dev": |
|
389 |
self.fail("you can only create new cubes in development mode") |
|
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
390 |
verbose = self.get('verbose') |
0 | 391 |
cubedir = ServerConfiguration.CUBES_DIR |
392 |
if not isdir(cubedir): |
|
393 |
print "creating apps directory", cubedir |
|
394 |
try: |
|
395 |
mkdir(cubedir) |
|
396 |
except OSError, err: |
|
397 |
self.fail("failed to create directory %r\n(%s)" % (cubedir, err)) |
|
398 |
cubedir = join(cubedir, cubename) |
|
399 |
if exists(cubedir): |
|
400 |
self.fail("%s already exists !" % (cubedir)) |
|
401 |
skeldir = join(BASEDIR, 'skeleton') |
|
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
402 |
if verbose: |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
403 |
distname = raw_input('Debian name for your cube (just type enter to use the cube name): ').strip() |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
404 |
if not distname: |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
405 |
distname = 'cubicweb-%s' % cubename.lower() |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
406 |
elif not distname.startswith('cubicweb-'): |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
407 |
if confirm('do you mean cubicweb-%s ?' % distname): |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
408 |
distname = 'cubicweb-' + distname |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
409 |
else: |
0 | 410 |
distname = 'cubicweb-%s' % cubename.lower() |
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
411 |
|
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
412 |
longdesc = shortdesc = raw_input('Enter a short description for your cube: ') |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
413 |
if verbose: |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
414 |
longdesc = raw_input('Enter a long description (or nothing if you want to reuse the short one): ') |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
415 |
if verbose: |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
416 |
includes = self._ask_for_dependancies() |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
417 |
if len(includes) == 1: |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
418 |
dependancies = '%r,' % includes[0] |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
419 |
else: |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
420 |
dependancies = ', '.join(repr(cube) for cube in includes) |
0 | 421 |
else: |
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
422 |
dependancies = '' |
0 | 423 |
from mx.DateTime import now |
424 |
context = {'cubename' : cubename, |
|
425 |
'distname' : distname, |
|
426 |
'shortdesc' : shortdesc, |
|
427 |
'longdesc' : longdesc or shortdesc, |
|
428 |
'dependancies' : dependancies, |
|
429 |
'version' : cubicwebversion, |
|
430 |
'year' : str(now().year), |
|
431 |
} |
|
432 |
copy_skeleton(skeldir, cubedir, context) |
|
433 |
||
434 |
def _ask_for_dependancies(self): |
|
435 |
includes = [] |
|
436 |
for stdtype in ServerConfiguration.available_cubes(): |
|
437 |
ans = raw_input("Depends on cube %s? (N/y/s(kip)/t(ype)" |
|
438 |
% stdtype).lower().strip() |
|
439 |
if ans == 'y': |
|
440 |
includes.append(stdtype) |
|
441 |
if ans == 't': |
|
442 |
includes = get_csv(raw_input('type dependancies: ')) |
|
443 |
break |
|
444 |
elif ans == 's': |
|
445 |
break |
|
446 |
return includes |
|
447 |
||
448 |
||
449 |
register_commands((UpdateCubicWebCatalogCommand, |
|
450 |
UpdateTemplateCatalogCommand, |
|
451 |
LiveServerCommand, |
|
132
561671b87c22
rename NewTemplateCommand class into NewCubeCommand
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
61
diff
changeset
|
452 |
NewCubeCommand, |
0 | 453 |
)) |