Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubicweb
Commits
61c4bdd70dd8
Commit
b65acbee
authored
Dec 03, 2012
by
Nicolas Chauvat
Browse files
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
parent
112a04c0473d
Changes
2
Hide whitespace changes
Inline
Side-by-side
devtools/devctl.py
View file @
61c4bdd7
...
...
@@ -302,10 +302,11 @@ class UpdateCubicWebCatalogCommand(Command):
from
logilab.common.fileutils
import
ensure_fs_mode
from
logilab.common.shellutils
import
globfind
,
find
,
rm
from
logilab.common.modutils
import
get_module_files
from
cubicweb.i18n
import
extract_from_tal
,
execute
from
cubicweb.i18n
import
extract_from_tal
,
execute
2
tempdir
=
tempfile
.
mkdtemp
(
prefix
=
'cw-'
)
cwi18ndir
=
WebConfiguration
.
i18n_lib_dir
()
print
'-> extract schema messages.'
print
'-> extract messages:'
,
print
'schema'
,
schemapot
=
osp
.
join
(
tempdir
,
'schema.pot'
)
potfiles
=
[
schemapot
]
potfiles
.
append
(
schemapot
)
...
...
@@ -314,7 +315,7 @@ class UpdateCubicWebCatalogCommand(Command):
schemapotstream
=
file
(
schemapot
,
'w'
)
generate_schema_pot
(
schemapotstream
.
write
,
cubedir
=
None
)
schemapotstream
.
close
()
print
'
-> extract TAL messages.'
print
'
TAL'
,
tali18nfile
=
osp
.
join
(
tempdir
,
'tali18n.py'
)
extract_from_tal
(
find
(
osp
.
join
(
BASEDIR
,
'web'
),
(
'.py'
,
'.pt'
)),
tali18nfile
)
...
...
@@ -329,26 +330,29 @@ class UpdateCubicWebCatalogCommand(Command):
(
'tal'
,
[
tali18nfile
],
None
),
(
'js'
,
jsfiles
,
'java'
),
]:
cmd
=
'xgettext --no-location --omit-header -k_ -o %s %s'
if
lang
is
not
None
:
cmd
+=
' -L %s'
%
lang
potfile
=
osp
.
join
(
tempdir
,
'%s.pot'
%
id
)
execute
(
cmd
%
(
potfile
,
' '
.
join
(
'"%s"'
%
f
for
f
in
files
)))
cmd
=
[
'xgettext'
,
'--no-location'
,
'--omit-header'
,
'-k_'
]
if
lang
is
not
None
:
cmd
.
extend
([
'-L'
,
lang
])
cmd
.
extend
([
'-o'
,
potfile
])
cmd
.
extend
(
files
)
execute2
(
cmd
)
if
osp
.
exists
(
potfile
):
potfiles
.
append
(
potfile
)
else
:
print
'-> WARNING: %s file was not generated'
%
potfile
print
'-> merging %i .pot files'
%
len
(
potfiles
)
cubicwebpot
=
osp
.
join
(
tempdir
,
'cubicweb.pot'
)
execute
(
'msgcat -o %s %s'
%
(
cubicwebpot
,
' '
.
join
(
'"%s"'
%
f
for
f
in
potfiles
))
)
cmd
=
[
'msgcat'
,
'-o'
,
cubicwebpot
]
+
potfiles
execute2
(
cmd
)
print
'-> merging main pot file with existing translations.'
chdir
(
cwi18ndir
)
toedit
=
[]
for
lang
in
CubicWebNoAppConfiguration
.
cw_languages
():
target
=
'%s.po'
%
lang
execute
(
'msgmerge -N --sort-output -o "%snew" "%s" "%s"'
%
(
target
,
target
,
cubicwebpot
))
cmd
=
[
'msgmerge'
,
'-N'
,
'--sort-output'
,
'-o'
,
target
+
'new'
,
target
,
cubicwebpot
]
execute2
(
cmd
)
ensure_fs_mode
(
target
)
shutil
.
move
(
'%snew'
%
target
,
target
)
toedit
.
append
(
osp
.
abspath
(
target
))
...
...
@@ -382,16 +386,21 @@ class UpdateCubeCatalogCommand(Command):
def
update_cubes_catalogs
(
cubes
):
from
subprocess
import
CalledProcessError
for
cubedir
in
cubes
:
if
not
osp
.
isdir
(
cubedir
):
print
'-> ignoring %s that is not a directory.'
%
cubedir
continue
try
:
toedit
=
update_cube_catalogs
(
cubedir
)
except
CalledProcessError
,
exc
:
print
'
\n
*** error while updating catalogs for cube'
,
cubedir
print
'cmd:
\n
%s'
%
exc
.
cmd
print
'stdout:
\n
%s
\n
stderr:
\n
%s'
%
exc
.
data
except
Exception
:
import
traceback
traceback
.
print_exc
()
print
'
->
error while updating catalogs for cube'
,
cubedir
print
'
***
error while updating catalogs for cube'
,
cubedir
return
False
else
:
# instructions pour la suite
...
...
@@ -408,7 +417,7 @@ def update_cube_catalogs(cubedir):
import
tempfile
from
logilab.common.fileutils
import
ensure_fs_mode
from
logilab.common.shellutils
import
find
,
rm
from
cubicweb.i18n
import
extract_from_tal
,
execute
from
cubicweb.i18n
import
extract_from_tal
,
execute
2
cube
=
osp
.
basename
(
osp
.
normpath
(
cubedir
))
tempdir
=
tempfile
.
mkdtemp
()
print
underline_title
(
'Updating i18n catalogs for cube %s'
%
cube
)
...
...
@@ -421,7 +430,8 @@ def update_cube_catalogs(cubedir):
potfiles
=
[
osp
.
join
(
'i18n'
,
'static-messages.pot'
)]
else
:
potfiles
=
[]
print
'-> extract schema messages'
print
'-> extracting messages:'
,
print
'schema'
,
schemapot
=
osp
.
join
(
tempdir
,
'schema.pot'
)
potfiles
.
append
(
schemapot
)
# explicit close necessary else the file may not be yet flushed when
...
...
@@ -429,50 +439,55 @@ def update_cube_catalogs(cubedir):
schemapotstream
=
file
(
schemapot
,
'w'
)
generate_schema_pot
(
schemapotstream
.
write
,
cubedir
)
schemapotstream
.
close
()
print
'
-> extract TAL messages'
print
'
TAL'
,
tali18nfile
=
osp
.
join
(
tempdir
,
'tali18n.py'
)
ptfiles
=
find
(
'.'
,
(
'.py'
,
'.pt'
),
blacklist
=
STD_BLACKLIST
+
(
'test'
,))
extract_from_tal
(
ptfiles
,
tali18nfile
)
print
'
-> extract
Javascript
messages
'
print
'Javascript'
jsfiles
=
[
jsfile
for
jsfile
in
find
(
'.'
,
'.js'
)
if
osp
.
basename
(
jsfile
).
startswith
(
'cub'
)]
if
jsfiles
:
tmppotfile
=
osp
.
join
(
tempdir
,
'js.pot'
)
execute
(
'xgettext --no-location --omit-header -k_ -L java '
'--from-code=utf-8 -o %s %s'
%
(
tmppotfile
,
' '
.
join
(
jsfiles
)))
cmd
=
[
'xgettext'
,
'--no-location'
,
'--omit-header'
,
'-k_'
,
'-L'
,
'java'
,
'--from-code=utf-8'
,
'-o'
,
tmppotfile
]
+
jsfiles
execute2
(
cmd
)
# no pot file created if there are no string to translate
if
osp
.
exists
(
tmppotfile
):
potfiles
.
append
(
tmppotfile
)
print
'-> creat
e
cube-specific catalog'
print
'-> creat
ing
cube-specific catalog'
tmppotfile
=
osp
.
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
(
'"%s"'
%
f
for
f
in
cubefiles
)))
cmd
=
[
'xgettext'
,
'--no-location'
,
'--omit-header'
,
'-k_'
,
'-o'
,
tmppotfile
]
cmd
.
extend
(
cubefiles
)
execute2
(
cmd
)
if
osp
.
exists
(
tmppotfile
):
# doesn't exists of no translation string found
potfiles
.
append
(
tmppotfile
)
potfile
=
osp
.
join
(
tempdir
,
'cube.pot'
)
print
'-> merging %i .pot files:'
%
len
(
potfiles
)
execute
(
'msgcat -o %s %s'
%
(
potfile
,
' '
.
join
(
'"%s"'
%
f
for
f
in
potfiles
)))
print
'-> merging %i .pot files'
%
len
(
potfiles
)
cmd
=
[
'msgcat'
,
'-o'
,
potfile
]
cmd
.
extend
(
potfiles
)
execute2
(
cmd
)
if
not
osp
.
exists
(
potfile
):
print
'no message catalog for cube'
,
cube
,
'nothing to translate'
# cleanup
rm
(
tempdir
)
return
()
print
'-> merging main pot file with existing translations:'
print
'-> merging main pot file with existing translations:'
,
chdir
(
'i18n'
)
toedit
=
[]
for
lang
in
CubicWebNoAppConfiguration
.
cw_languages
():
print
'-> language'
,
lang
print
lang
,
cubepo
=
'%s.po'
%
lang
if
not
osp
.
exists
(
cubepo
):
shutil
.
copy
(
potfile
,
cubepo
)
else
:
execute
(
'msgmerge -N -s -o %snew %s %s'
%
(
cubepo
,
cubepo
,
potfile
))
cmd
=
[
'msgmerge'
,
'-N'
,
'-s'
,
'-o'
,
cubepo
+
'new'
,
cubepo
,
potfile
]
execute2
(
cmd
)
ensure_fs_mode
(
cubepo
)
shutil
.
move
(
'%snew'
%
cubepo
,
cubepo
)
toedit
.
append
(
osp
.
abspath
(
cubepo
))
print
# cleanup
rm
(
tempdir
)
return
toedit
...
...
i18n.py
View file @
61c4bdd7
...
...
@@ -54,19 +54,16 @@ def add_msg(w, msgid, msgctx=None):
w
(
'msgid "%s"
\n
'
%
msgid
[
0
])
w
(
'msgstr ""
\n\n
'
)
def
execute
(
cmd
):
"""display the command, execute it and raise an Exception if returned
status != 0
"""
from
subprocess
import
call
# use getcwdu as cmd may be unicode and cwd may contains non-ascii
# characters
print
cmd
.
replace
(
os
.
getcwdu
()
+
os
.
sep
,
''
)
status
=
call
(
cmd
,
shell
=
True
)
if
status
!=
0
:
raise
Exception
(
'status = %s'
%
status
)
def
execute2
(
args
):
# XXX replace this with check_output in Python 2.7
from
subprocess
import
Popen
,
PIPE
,
CalledProcessError
p
=
Popen
(
args
,
stdout
=
PIPE
,
stderr
=
PIPE
)
out
,
err
=
p
.
communicate
()
if
p
.
returncode
!=
0
:
exc
=
CalledProcessError
(
p
.
returncode
,
args
[
0
])
exc
.
cmd
=
args
exc
.
data
=
(
out
,
err
)
raise
exc
def
available_catalogs
(
i18ndir
=
None
):
if
i18ndir
is
None
:
...
...
@@ -81,6 +78,7 @@ def available_catalogs(i18ndir=None):
def
compile_i18n_catalogs
(
sourcedirs
,
destdir
,
langs
):
"""generate .mo files for a set of languages into the `destdir` i18n directory
"""
from
subprocess
import
CalledProcessError
from
logilab.common.fileutils
import
ensure_fs_mode
print
'-> compiling message catalogs to %s'
%
destdir
errors
=
[]
...
...
@@ -93,17 +91,21 @@ def compile_i18n_catalogs(sourcedirs, destdir, langs):
mergedpo
=
join
(
destdir
,
'%s_merged.po'
%
lang
)
try
:
# merge instance/cubes messages catalogs with the stdlib's one
execute
(
'msgcat --use-first --sort-output --strict -o "%s" %s'
%
(
mergedpo
,
' '
.
join
(
'"%s"'
%
f
for
f
in
pofiles
)))
cmd
=
[
'msgcat'
,
'--use-first'
,
'--sort-output'
,
'--strict'
,
'-o'
,
mergedpo
]
+
pofiles
execute2
(
cmd
)
# make sure the .mo file is writeable and compiles with *msgfmt*
applmo
=
join
(
destdir
,
lang
,
'LC_MESSAGES'
,
'cubicweb.mo'
)
try
:
ensure_fs_mode
(
applmo
)
except
OSError
:
pass
# suppose not exists
execute
(
'msgfmt "%s" -o "%s"'
%
(
mergedpo
,
applmo
))
except
Exception
,
ex
:
errors
.
append
(
'while handling language %s: %s'
%
(
lang
,
ex
))
execute2
([
'msgfmt'
,
mergedpo
,
'-o'
,
applmo
])
except
CalledProcessError
,
exc
:
errors
.
append
(
u
'while handling language %s:
\n
cmd:
\n
%s
\n
stdout:
\n
%s
\n
stderr:
\n
%s
\n
'
%
(
lang
,
exc
.
cmd
,
repr
(
exc
.
data
[
0
]),
repr
(
exc
.
data
[
1
])))
except
Exception
,
exc
:
errors
.
append
(
u
'while handling language %s: %s'
%
(
lang
,
exc
))
try
:
# clean everything
os
.
unlink
(
mergedpo
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment