|
Lines 44-69
MODULE_BLACKLIST = [
Link Here
|
| 44 |
'0001-6-7' |
44 |
'0001-6-7' |
| 45 |
] |
45 |
] |
| 46 |
|
46 |
|
| 47 |
MAKEFILE_HEADER = """#!/usr/bin/make -f |
|
|
| 48 |
|
| 49 |
%.mo: |
| 50 |
mkdir -p $(@D) |
| 51 |
msgfmt --check --output-file="$@" "$<" |
| 52 |
|
| 53 |
%.json: |
| 54 |
#python -c "import univention.dh_umc as dhumc; dhumc.create_json_file('$<')" |
| 55 |
dh-umc-po2json "$<" # creates .json file in the same directory as the .po file |
| 56 |
mkdir -p $(@D) |
| 57 |
mv "$(patsubst %.po,%.json,$<)" "$@" |
| 58 |
#install -D $($<:.po=.json) "$@" |
| 59 |
|
| 60 |
""" |
| 61 |
|
| 62 |
MAKEFILE_END = """build: |
| 63 |
|
| 64 |
install: $(ALL_TARGETS) |
| 65 |
""" |
| 66 |
|
| 67 |
|
47 |
|
| 68 |
class UMCModuleTranslation(dh_umc.UMC_Module): |
48 |
class UMCModuleTranslation(dh_umc.UMC_Module): |
| 69 |
def __init__(self, attrs, target_language): |
49 |
def __init__(self, attrs, target_language): |
|
Lines 96-102
class UMCModuleTranslation(dh_umc.UMC_Module):
Link Here
|
| 96 |
try: |
76 |
try: |
| 97 |
module = UMCModuleTranslation._get_core_module_from_source_package(module_in_source_tree, target_language) |
77 |
module = UMCModuleTranslation._get_core_module_from_source_package(module_in_source_tree, target_language) |
| 98 |
except AttributeError as e: |
78 |
except AttributeError as e: |
| 99 |
print "%s core module load failed" % str(e) |
79 |
print("%s core module load failed" % str(e)) |
| 100 |
# TODO: Module not loaded at all --> exception? |
80 |
# TODO: Module not loaded at all --> exception? |
| 101 |
else: |
81 |
else: |
| 102 |
print("Successfully loaded as core module: {}".format(module_in_source_tree.get('abs_path_to_src_pkg'))) |
82 |
print("Successfully loaded as core module: {}".format(module_in_source_tree.get('abs_path_to_src_pkg'))) |
|
Lines 134-140
class UMCModuleTranslation(dh_umc.UMC_Module):
Link Here
|
| 134 |
attrs['relative_path_src_pkg'] = module.get('relative_path_src_pkg') |
114 |
attrs['relative_path_src_pkg'] = module.get('relative_path_src_pkg') |
| 135 |
return UMCModuleTranslation(attrs, target_language) |
115 |
return UMCModuleTranslation(attrs, target_language) |
| 136 |
|
116 |
|
| 137 |
#TODO: actually.. (module, output_dir) |
117 |
|
|
|
118 |
# TODO: actually.. (module, output_dir) |
| 138 |
def update_package_translation_files(module, output_dir): |
119 |
def update_package_translation_files(module, output_dir): |
| 139 |
print("Creating directories and PO files for {module_name} in translation source package".format(**module)) |
120 |
print("Creating directories and PO files for {module_name} in translation source package".format(**module)) |
| 140 |
start_dir = os.getcwd() |
121 |
start_dir = os.getcwd() |
|
Lines 154-160
def update_package_translation_files(module, output_dir):
Link Here
|
| 154 |
try: |
135 |
try: |
| 155 |
dh_umc.create_po_file(new_po_file_abs_path, module['module_name'], src_files) |
136 |
dh_umc.create_po_file(new_po_file_abs_path, module['module_name'], src_files) |
| 156 |
except dh_umc.Error as exc: |
137 |
except dh_umc.Error as exc: |
| 157 |
print str(exc) |
138 |
print(str(exc)) |
| 158 |
|
139 |
|
| 159 |
# build python po files |
140 |
# build python po files |
| 160 |
_create_po_files(module.python_po_files, module.python_files) |
141 |
_create_po_files(module.python_po_files, module.python_files) |
|
Lines 168-178
def update_package_translation_files(module, output_dir):
Link Here
|
| 168 |
try: |
149 |
try: |
| 169 |
dh_umc.module_xml2po(module, po_file_full_path, lang) |
150 |
dh_umc.module_xml2po(module, po_file_full_path, lang) |
| 170 |
except dh_umc.Error as exc: |
151 |
except dh_umc.Error as exc: |
| 171 |
print str(exc) |
152 |
print(str(exc)) |
| 172 |
|
153 |
|
| 173 |
except OSError as exc: |
154 |
except OSError as exc: |
| 174 |
print traceback.format_exc() |
155 |
print(traceback.format_exc()) |
| 175 |
print "error in update_package_translation_files: %s" % (exc,) |
156 |
print("error in update_package_translation_files: %s" % (exc,)) |
| 176 |
finally: |
157 |
finally: |
| 177 |
os.chdir(start_dir) |
158 |
os.chdir(start_dir) |
| 178 |
return abs_path_translated_src_pkg |
159 |
return abs_path_translated_src_pkg |
|
Lines 195-206
def write_makefile(all_modules, special_cases, new_package_dir, target_language)
Link Here
|
| 195 |
|
176 |
|
| 196 |
for scase in special_cases: |
177 |
for scase in special_cases: |
| 197 |
_append_to_target_lists(scase.get('mo_destination'), '{lang}/{po_subdir}/{lang}.po'.format(lang=target_language, **scase)) |
178 |
_append_to_target_lists(scase.get('mo_destination'), '{lang}/{po_subdir}/{lang}.po'.format(lang=target_language, **scase)) |
| 198 |
with open(os.path.join(new_package_dir, 'Makefile'), 'w') as fd: |
179 |
with open(os.path.join(new_package_dir, 'all_targets.mk'), 'w') as fd: |
| 199 |
fd.writelines(MAKEFILE_HEADER) |
180 |
fd.write("# This file is auto-generated by univention-ucs-translation-build-package and should not be edited!\n\n") |
| 200 |
fd.write('ALL_TARGETS = {}\n\n'.format(' \\\n\t'.join(mo_targets_list))) |
181 |
fd.write('ALL_TARGETS = {}\n\n'.format(' \\\n\t'.join(mo_targets_list))) |
| 201 |
fd.write('\n'.join(target_prerequisite)) |
182 |
fd.write('\n'.join(target_prerequisite)) |
| 202 |
fd.write('\n') |
183 |
fd.write('\n') |
| 203 |
fd.writelines(MAKEFILE_END) |
|
|
| 204 |
|
184 |
|
| 205 |
|
185 |
|
| 206 |
# special case e.g. univention-management-modules-frontend: translation files are built with a makefile |
186 |
# special case e.g. univention-management-modules-frontend: translation files are built with a makefile |
|
Lines 212-218
def translate_special_case(special_case, source_dir, target_language, output_dir
Link Here
|
| 212 |
# TODO: Checks whether a special case is valid should be done on special case parsing |
192 |
# TODO: Checks whether a special case is valid should be done on special case parsing |
| 213 |
path_src_pkg = os.path.join(source_dir, special_case.get('package_dir')) |
193 |
path_src_pkg = os.path.join(source_dir, special_case.get('package_dir')) |
| 214 |
if not os.path.isdir(path_src_pkg): |
194 |
if not os.path.isdir(path_src_pkg): |
| 215 |
# TODO: Exception |
195 |
# TODO: Exception |
| 216 |
return |
196 |
return |
| 217 |
|
197 |
|
| 218 |
new_po_path = os.path.join(output_dir, special_case.get('po_subdir')) |
198 |
new_po_path = os.path.join(output_dir, special_case.get('po_subdir')) |
|
Lines 229-245
def translate_special_case(special_case, source_dir, target_language, output_dir
Link Here
|
| 229 |
if not matches: |
209 |
if not matches: |
| 230 |
# TODO: Exception |
210 |
# TODO: Exception |
| 231 |
print('Error: specialcase for {} didn\'t match any files.'.format(special_case.get('package_dir'))) |
211 |
print('Error: specialcase for {} didn\'t match any files.'.format(special_case.get('package_dir'))) |
|
|
212 |
# FIXME: create_po should handle path itself? |
| 213 |
cwd = os.getcwd() |
| 214 |
os.chdir(path_src_pkg) |
| 232 |
try: |
215 |
try: |
|
|
216 |
matches = [os.path.relpath(match, start=os.getcwd()) for match in matches] |
| 233 |
dh_umc.create_po_file(new_po_path, special_case.get('package_name'), matches) |
217 |
dh_umc.create_po_file(new_po_path, special_case.get('package_name'), matches) |
| 234 |
except dh_umc.Error as exc: |
218 |
except dh_umc.Error as exc: |
| 235 |
repr(exc) |
219 |
repr(exc) |
| 236 |
except TypeError as exc: |
220 |
except TypeError as exc: |
| 237 |
repr(exc) |
221 |
repr(exc) |
|
|
222 |
os.chdir(cwd) |
| 238 |
|
223 |
|
| 239 |
|
224 |
|
| 240 |
def find_base_translation_modules(startdir, source_dir, module_basefile_name): |
225 |
def find_base_translation_modules(startdir, source_dir, module_basefile_name): |
| 241 |
print 'looking in %s' % source_dir |
226 |
print('looking in %s' % source_dir) |
| 242 |
print 'looking for files matching %s' % module_basefile_name |
227 |
print('looking for files matching %s' % module_basefile_name) |
| 243 |
os.chdir(source_dir) |
228 |
os.chdir(source_dir) |
| 244 |
matches = [] |
229 |
matches = [] |
| 245 |
for root, dirnames, filenames in os.walk('.'): |
230 |
for root, dirnames, filenames in os.walk('.'): |
|
Lines 250-267
def find_base_translation_modules(startdir, source_dir, module_basefile_name):
Link Here
|
| 250 |
|
235 |
|
| 251 |
regex = re.compile(".*/(.*)/debian/.*%s$" % re.escape(module_basefile_name)) |
236 |
regex = re.compile(".*/(.*)/debian/.*%s$" % re.escape(module_basefile_name)) |
| 252 |
for match in matches: |
237 |
for match in matches: |
| 253 |
print match |
238 |
print(match) |
| 254 |
packagenameresult = regex.search(match) |
239 |
packagenameresult = regex.search(match) |
| 255 |
if packagenameresult: |
240 |
if packagenameresult: |
| 256 |
packagename = packagenameresult.group(1) |
241 |
packagename = packagenameresult.group(1) |
| 257 |
|
242 |
|
| 258 |
modulename = os.path.basename(match.replace(module_basefile_name, '')) |
243 |
modulename = os.path.basename(match.replace(module_basefile_name, '')) |
| 259 |
if modulename in MODULE_BLACKLIST: |
244 |
if modulename in MODULE_BLACKLIST: |
| 260 |
print "Ignoring module %s: Module is blacklisted\n" % modulename |
245 |
print("Ignoring module %s: Module is blacklisted\n" % modulename) |
| 261 |
continue |
246 |
continue |
| 262 |
|
247 |
|
| 263 |
package_dir = os.path.dirname(os.path.dirname(match)) |
248 |
package_dir = os.path.dirname(os.path.dirname(match)) |
| 264 |
print "Found package: %s" % package_dir |
249 |
print("Found package: %s" % package_dir) |
| 265 |
module = {} |
250 |
module = {} |
| 266 |
module['module_name'] = modulename |
251 |
module['module_name'] = modulename |
| 267 |
module['binary_package_name'] = packagename |
252 |
module['binary_package_name'] = packagename |
|
Lines 269-275
def find_base_translation_modules(startdir, source_dir, module_basefile_name):
Link Here
|
| 269 |
module['relative_path_src_pkg'] = os.path.relpath(package_dir) |
254 |
module['relative_path_src_pkg'] = os.path.relpath(package_dir) |
| 270 |
base_translation_modules.append(module) |
255 |
base_translation_modules.append(module) |
| 271 |
else: |
256 |
else: |
| 272 |
print "could not obtain packagename from directory %s" % match |
257 |
print("could not obtain packagename from directory %s" % match) |
| 273 |
|
258 |
|
| 274 |
os.chdir(startdir) |
259 |
os.chdir(startdir) |
| 275 |
return base_translation_modules |
260 |
return base_translation_modules |
|
Lines 278-284
def find_base_translation_modules(startdir, source_dir, module_basefile_name):
Link Here
|
| 278 |
def create_new_package(new_package_dir, target_language, target_locale, language_name, startdir): |
263 |
def create_new_package(new_package_dir, target_language, target_locale, language_name, startdir): |
| 279 |
new_package_dir_debian = os.path.join(new_package_dir, 'debian') |
264 |
new_package_dir_debian = os.path.join(new_package_dir, 'debian') |
| 280 |
if not os.path.exists(new_package_dir_debian): |
265 |
if not os.path.exists(new_package_dir_debian): |
| 281 |
print "creating directory: %s" % new_package_dir_debian |
266 |
print("creating directory: %s" % new_package_dir_debian) |
| 282 |
os.makedirs(new_package_dir_debian) |
267 |
os.makedirs(new_package_dir_debian) |
| 283 |
|
268 |
|
| 284 |
translation_package_name = "univention-ucs-translation-%s" % target_language |
269 |
translation_package_name = "univention-ucs-translation-%s" % target_language |
|
Lines 409-415
usr/share/univention-management-console/i18n/%(lang)s
Link Here
|
| 409 |
usr/share/locale/%(lang)s/LC_MESSAGES |
394 |
usr/share/locale/%(lang)s/LC_MESSAGES |
| 410 |
""" % language_dict) |
395 |
""" % language_dict) |
| 411 |
|
396 |
|
| 412 |
### Move source files and installed .mo files to new package dir |
397 |
shutil.copyfile('/usr/share/univention-ucs-translation-template/base_makefile', os.path.join(new_package_dir, 'Makefile')) |
|
|
398 |
# Move source files and installed .mo files to new package dir |
| 413 |
if os.path.exists(os.path.join(new_package_dir, 'usr')): |
399 |
if os.path.exists(os.path.join(new_package_dir, 'usr')): |
| 414 |
shutil.rmtree(os.path.join(new_package_dir, 'usr')) |
400 |
shutil.rmtree(os.path.join(new_package_dir, 'usr')) |
| 415 |
#shutil.copytree(os.path.join(startdir, 'usr'), os.path.join(new_package_dir, 'usr')) |
401 |
#shutil.copytree(os.path.join(startdir, 'usr'), os.path.join(new_package_dir, 'usr')) |
|
Lines 419-422
usr/share/locale/%(lang)s/LC_MESSAGES
Link Here
|
| 419 |
shutil.rmtree(os.path.join(new_package_dir, target_language)) |
405 |
shutil.rmtree(os.path.join(new_package_dir, target_language)) |
| 420 |
shutil.copytree(os.path.join(startdir, target_language), os.path.join(new_package_dir, target_language)) |
406 |
shutil.copytree(os.path.join(startdir, target_language), os.path.join(new_package_dir, target_language)) |
| 421 |
shutil.rmtree(os.path.join(startdir, target_language)) |
407 |
shutil.rmtree(os.path.join(startdir, target_language)) |
| 422 |
|
|
|