Cleanup mo packaging.
This commit is contained in:
parent
fe46d242f8
commit
0f17ae5d04
@ -146,18 +146,26 @@ def _get_file_list(manifest):
|
|||||||
else:
|
else:
|
||||||
return _DefaultFileList()
|
return _DefaultFileList()
|
||||||
|
|
||||||
def _include_mo_in_bundle(bundle_zip, bundle_name):
|
def _get_po_list(manifest):
|
||||||
for langdir in os.listdir('locale'):
|
file_list = {}
|
||||||
if os.path.isdir(os.path.join('locale', langdir, 'LC_MESSAGES')):
|
|
||||||
for filename in os.listdir(os.path.join('locale', langdir,
|
po_regex = re.compile("po/(.*)\.po$")
|
||||||
'LC_MESSAGES')):
|
for file_name in _get_file_list(manifest):
|
||||||
if filename.endswith('.mo'):
|
match = po_regex.match(file_name)
|
||||||
arcname = os.path.join(bundle_name + '.activity',
|
if match:
|
||||||
'locale', langdir, 'LC_MESSAGES',
|
file_list[match.group(1)] = file_name
|
||||||
filename)
|
|
||||||
bundle_zip.write(
|
return file_list
|
||||||
os.path.join('locale', langdir, 'LC_MESSAGES', filename),
|
|
||||||
arcname)
|
def _get_mo_list(manifest):
|
||||||
|
mo_list = []
|
||||||
|
|
||||||
|
for lang in _get_po_list(manifest).keys():
|
||||||
|
filename = _get_service_name() + '.mo'
|
||||||
|
mo_list.append(os.path.join(_get_source_path(), 'locale',
|
||||||
|
lang, 'LC_MESSAGES', filename))
|
||||||
|
|
||||||
|
return mo_list
|
||||||
|
|
||||||
def cmd_dist(bundle_name, manifest):
|
def cmd_dist(bundle_name, manifest):
|
||||||
cmd_genmo(bundle_name, manifest)
|
cmd_genmo(bundle_name, manifest)
|
||||||
@ -165,13 +173,13 @@ def cmd_dist(bundle_name, manifest):
|
|||||||
|
|
||||||
zipname = _get_package_name(bundle_name)
|
zipname = _get_package_name(bundle_name)
|
||||||
bundle_zip = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
|
bundle_zip = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
|
||||||
|
base_dir = bundle_name + '.activity'
|
||||||
|
|
||||||
for filename in file_list:
|
for filename in file_list:
|
||||||
arcname = os.path.join(bundle_name + '.activity', filename)
|
bundle_zip.write(filename, os.path.join(base_dir, filename))
|
||||||
bundle_zip.write(filename, arcname)
|
|
||||||
|
|
||||||
if os.path.exists('locale'):
|
for filename in _get_mo_list(manifest):
|
||||||
_include_mo_in_bundle(bundle_zip, bundle_name)
|
bundle_zip.write(filename, os.path.join(base_dir, filename))
|
||||||
|
|
||||||
bundle_zip.close()
|
bundle_zip.close()
|
||||||
|
|
||||||
@ -207,32 +215,28 @@ def cmd_genpot(bundle_name, manifest):
|
|||||||
if retcode:
|
if retcode:
|
||||||
print 'ERROR - xgettext failed with return code %i.' % retcode
|
print 'ERROR - xgettext failed with return code %i.' % retcode
|
||||||
|
|
||||||
po_regex = re.compile("po/.*\.po$")
|
for file_name in _get_po_list(manifest).values():
|
||||||
for file_name in _get_file_list(manifest):
|
args = [ 'msgmerge', '-U', file_name, pot_file ]
|
||||||
if po_regex.match(file_name):
|
retcode = subprocess.call(args)
|
||||||
args = [ 'msgmerge', '-U', file_name, pot_file ]
|
if retcode:
|
||||||
retcode = subprocess.call(args)
|
print 'ERROR - msgmerge failed with return code %i.' % retcode
|
||||||
if retcode:
|
|
||||||
print 'ERROR - msgmerge failed with return code %i.' % retcode
|
|
||||||
|
|
||||||
def cmd_genmo(bundle_name, manifest):
|
def cmd_genmo(bundle_name, manifest):
|
||||||
source_path = _get_source_path()
|
source_path = _get_source_path()
|
||||||
|
|
||||||
po_regex = re.compile("po/(.*)\.po$")
|
po_list = _get_po_list(manifest)
|
||||||
for file_name in _get_file_list(manifest):
|
for lang in po_list.keys():
|
||||||
match = po_regex.match(file_name)
|
file_name = po_list[lang]
|
||||||
if match:
|
|
||||||
lang = match.group(1)
|
|
||||||
|
|
||||||
mo_path = os.path.join(source_path, 'locale', lang, 'LC_MESSAGES')
|
mo_path = os.path.join(source_path, 'locale', lang, 'LC_MESSAGES')
|
||||||
if not os.path.isdir(mo_path):
|
if not os.path.isdir(mo_path):
|
||||||
os.makedirs(mo_path)
|
os.makedirs(mo_path)
|
||||||
|
|
||||||
mo_file = os.path.join(mo_path, "%s.mo" % _get_service_name())
|
mo_file = os.path.join(mo_path, "%s.mo" % _get_service_name())
|
||||||
args = ["msgfmt", "--output-file=%s" % mo_file, file_name]
|
args = ["msgfmt", "--output-file=%s" % mo_file, file_name]
|
||||||
retcode = subprocess.call(args)
|
retcode = subprocess.call(args)
|
||||||
if retcode:
|
if retcode:
|
||||||
print 'ERROR - msgfmt failed with return code %i.' % retcode
|
print 'ERROR - msgfmt failed with return code %i.' % retcode
|
||||||
|
|
||||||
def cmd_release(bundle_name, manifest):
|
def cmd_release(bundle_name, manifest):
|
||||||
if not os.path.isdir('.git'):
|
if not os.path.isdir('.git'):
|
||||||
|
Loading…
Reference in New Issue
Block a user