--- a/cwvreg.py Wed May 13 08:58:32 2009 +0200
+++ b/cwvreg.py Wed May 13 09:13:26 2009 +0200
@@ -5,6 +5,7 @@
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
__docformat__ = "restructuredtext en"
+_ = unicode
from logilab.common.decorators import cached, clear_cache
@@ -12,8 +13,8 @@
from cubicweb import Binary, UnknownProperty, UnknownEid
from cubicweb.vregistry import VRegistry, ObjectNotFound, NoSelectableObject
+from cubicweb.rtags import RTAGS
-_ = unicode
def use_interfaces(obj):
"""return interfaces used by the given object by searchinf for implements
@@ -122,9 +123,10 @@
for appobjects in objects.itervalues():
for appobject in appobjects:
appobject.vreg_initialization_completed()
- from cubicweb.rtags import RTAGS
+ # don't check rtags if we don't want to cleanup_interface_sobjects
for rtag in RTAGS:
- rtag.init(self.schema)
+ rtag.init(self.schema,
+ check=self.config.cleanup_interface_sobjects)
def initialization_completed(self):
# clear etype cache if you don't want to run into deep weirdness
--- a/devtools/devctl.py Wed May 13 08:58:32 2009 +0200
+++ b/devtools/devctl.py Wed May 13 09:13:26 2009 +0200
@@ -77,6 +77,11 @@
if mod.__file__.startswith(path):
del sys.modules[name]
break
+ # fresh rtags
+ from cubicweb import rtags
+ from cubicweb.web import uicfg
+ rtags.RTAGS[:] = []
+ reload(uicfg)
def generate_schema_pot(w, cubedir=None):
"""generate a pot file with schema specific i18n messages
@@ -320,74 +325,86 @@
cubes = [cubepath for cubepath in cubes if exists(join(cubepath, 'i18n'))]
update_cubes_catalogs(cubes)
+
def update_cubes_catalogs(cubes):
+ toedit = []
+ for cubedir in cubes:
+ if not isdir(cubedir):
+ print 'not a directory', cubedir
+ continue
+ try:
+ toedit += update_cube_catalogs(cubedir)
+ except Exception:
+ import traceback
+ traceback.print_exc()
+ print 'error while updating catalogs for', cubedir
+ # instructions pour la suite
+ print '*' * 72
+ print 'you can now edit the following files:'
+ print '* ' + '\n* '.join(toedit)
+
+
+def update_cube_catalogs(cubedir):
import shutil
from tempfile import mktemp
from logilab.common.fileutils import ensure_fs_mode
from logilab.common.shellutils import find, rm
from cubicweb.common.i18n import extract_from_tal, execute
toedit = []
- for cubedir in cubes:
- cube = basename(normpath(cubedir))
- if not isdir(cubedir):
- print 'unknown cube', cube
- continue
- tempdir = mktemp()
- mkdir(tempdir)
- print '*' * 72
- print 'updating %s cube...' % cube
- chdir(cubedir)
- potfiles = [join('i18n', scfile) for scfile in ('entities.pot',)
- if exists(join('i18n', scfile))]
- print '******** extract schema messages'
- schemapot = join(tempdir, 'schema.pot')
- potfiles.append(schemapot)
- # explicit close necessary else the file may not be yet flushed when
- # we'll using it below
- schemapotstream = file(schemapot, 'w')
- generate_schema_pot(schemapotstream.write, cubedir)
- schemapotstream.close()
- print '******** extract TAL messages'
- tali18nfile = join(tempdir, 'tali18n.py')
- extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile)
- print '******** extract Javascript messages'
- jsfiles = [jsfile for jsfile in find('.', '.js') if basename(jsfile).startswith('cub')]
- if jsfiles:
- tmppotfile = join(tempdir, 'js.pot')
- execute('xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s'
- % (tmppotfile, ' '.join(jsfiles)))
- # no pot file created if there are no string to translate
- if exists(tmppotfile):
- potfiles.append(tmppotfile)
- print '******** create cube specific catalog'
- tmppotfile = join(tempdir, 'generated.pot')
- cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',))
- cubefiles.append(tali18nfile)
- execute('xgettext --no-location --omit-header -k_ -o %s %s'
- % (tmppotfile, ' '.join(cubefiles)))
- if exists(tmppotfile): # doesn't exists of no translation string found
+ cube = basename(normpath(cubedir))
+ tempdir = mktemp()
+ mkdir(tempdir)
+ print '*' * 72
+ print 'updating %s cube...' % cube
+ chdir(cubedir)
+ potfiles = [join('i18n', scfile) for scfile in ('entities.pot',)
+ if exists(join('i18n', scfile))]
+ print '******** extract schema messages'
+ schemapot = join(tempdir, 'schema.pot')
+ potfiles.append(schemapot)
+ # explicit close necessary else the file may not be yet flushed when
+ # we'll using it below
+ schemapotstream = file(schemapot, 'w')
+ generate_schema_pot(schemapotstream.write, cubedir)
+ schemapotstream.close()
+ print '******** extract TAL messages'
+ tali18nfile = join(tempdir, 'tali18n.py')
+ extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile)
+ print '******** extract Javascript messages'
+ jsfiles = [jsfile for jsfile in find('.', '.js') if basename(jsfile).startswith('cub')]
+ if jsfiles:
+ tmppotfile = join(tempdir, 'js.pot')
+ execute('xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s'
+ % (tmppotfile, ' '.join(jsfiles)))
+ # no pot file created if there are no string to translate
+ if exists(tmppotfile):
potfiles.append(tmppotfile)
- potfile = join(tempdir, 'cube.pot')
- print '******** merging .pot files'
- execute('msgcat %s > %s' % (' '.join(potfiles), potfile))
- print '******** merging main pot file with existing translations'
- chdir('i18n')
- for lang in LANGS:
- print '****', lang
- cubepo = '%s.po' % lang
- if not exists(cubepo):
- shutil.copy(potfile, cubepo)
- else:
- execute('msgmerge -N -s %s %s > %snew' % (cubepo, potfile, cubepo))
- ensure_fs_mode(cubepo)
- shutil.move('%snew' % cubepo, cubepo)
- toedit.append(abspath(cubepo))
- # cleanup
- rm(tempdir)
- # instructions pour la suite
- print '*' * 72
- print 'you can now edit the following files:'
- print '* ' + '\n* '.join(toedit)
+ print '******** create cube specific catalog'
+ tmppotfile = join(tempdir, 'generated.pot')
+ cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',))
+ cubefiles.append(tali18nfile)
+ execute('xgettext --no-location --omit-header -k_ -o %s %s'
+ % (tmppotfile, ' '.join(cubefiles)))
+ if exists(tmppotfile): # doesn't exists of no translation string found
+ potfiles.append(tmppotfile)
+ potfile = join(tempdir, 'cube.pot')
+ print '******** merging .pot files'
+ execute('msgcat %s > %s' % (' '.join(potfiles), potfile))
+ print '******** merging main pot file with existing translations'
+ chdir('i18n')
+ for lang in LANGS:
+ print '****', lang
+ cubepo = '%s.po' % lang
+ if not exists(cubepo):
+ shutil.copy(potfile, cubepo)
+ else:
+ execute('msgmerge -N -s %s %s > %snew' % (cubepo, potfile, cubepo))
+ ensure_fs_mode(cubepo)
+ shutil.move('%snew' % cubepo, cubepo)
+ toedit.append(abspath(cubepo))
+ # cleanup
+ rm(tempdir)
+ return toedit
class LiveServerCommand(Command):
--- a/rtags.py Wed May 13 08:58:32 2009 +0200
+++ b/rtags.py Wed May 13 09:13:26 2009 +0200
@@ -30,7 +30,7 @@
self._allowed_values = allowed_values
self._initfunc = initfunc
register_rtag(self)
-
+
def __repr__(self):
return repr(self._tagdefs)
@@ -52,14 +52,16 @@
keys.remove((rtype, tagged, stype, '*'))
return keys
- def init(self, schema):
+ def init(self, schema, check=True):
# XXX check existing keys against schema
- for (rtype, tagged, stype, otype), value in self._tagdefs.items():
- for ertype in (stype, rtype, otype):
- if ertype != '*' and not ertype in schema:
- self.warning('removing rtag %s: %s, %s undefined in schema',
- (stype, rtype, otype, tagged), value, ertype)
- self.del_rtag(stype, rtype, otype, tagged)
+ if check:
+ for (rtype, tagged, stype, otype), value in self._tagdefs.items():
+ for ertype in (stype, rtype, otype):
+ if ertype != '*' and not ertype in schema:
+ self.warning('removing rtag %s: %s, %s undefined in schema',
+ (stype, rtype, otype, tagged), value, ertype)
+ self.del_rtag(stype, rtype, otype, tagged)
+ break
if self._initfunc is not None:
for eschema in schema.entities():
for rschema, tschemas, role in eschema.relation_definitions(True):