View | Details | Raw Unified | Return to bug 41223 | Differences between
and this patch

Collapse All | Expand All

(-)a/packaging/univention-ucs-translation-template/test0.py (-12 / +18 lines)
 Lines 1-4    Link Here 
1
#!/usr/bin/env python
1
#!/usr/bin/env python
2
from distutils.file_util import copy_file
2
from hashlib import md5
3
from hashlib import md5
3
import logging
4
import logging
4
import os
5
import os
 Lines 45-51   def _change_entry_in_source_file(module_path, po_entry): Link Here 
45
						line = line.replace(po_entry.msgid, 'TEST! {}'.format(po_entry.msgid))
46
						line = line.replace(po_entry.msgid, 'TEST! {}'.format(po_entry.msgid))
46
					changed_js.write(line)
47
					changed_js.write(line)
47
48
48
49
SVN = 'SVN_TEST0'
49
TRANSLATION_PKG_NAME = 'univention-ucs-translation-XX'
50
TRANSLATION_PKG_NAME = 'univention-ucs-translation-XX'
50
# TODO: get latest public branch
51
# TODO: get latest public branch
51
if __name__ == '__main__':
52
if __name__ == '__main__':
 Lines 57-79   if __name__ == '__main__': Link Here 
57
		pass
58
		pass
58
59
59
	try:
60
	try:
60
		tools.call('svn', 'checkout', 'http://forge.univention.org/svn/dev/branches/ucs-4.1/ucs-4.1-1/management/univention-management-console-module-passwordchange/', 'svn_repo/management/univention-management-console-module-passwordchange')
61
		tools.call('svn', 'checkout', 'http://forge.univention.org/svn/dev/branches/ucs-4.1/ucs-4.1-1', SVN)
61
		tools.call('univention-ucs-translation-build-package', '--source=svn_repo', '--languagecode=XX', '--locale=fr_FR.UTF-8:UTF-8', '--languagename=TEST0')
62
		tools.call('univention-ucs-translation-build-package', '--source={}'.format(SVN), '--languagecode=XX', '--locale=fr_FR.UTF-8:UTF-8', '--languagename=TEST0')
62
		tools.call('univention-ucs-translation-fakemessage', TRANSLATION_PKG_NAME)
63
		tools.call('univention-ucs-translation-fakemessage', TRANSLATION_PKG_NAME)
63
	except InvalidCommandError:
64
	except InvalidCommandError:
64
		print('Error: Tried to launch invalid command. Exiting.')
65
		print('Error: Tried to launch invalid command. Exiting.')
65
		sys.exit(1)
66
		sys.exit(1)
66
67
67
	# Choose js files to manipulate
68
	# Choose js files to manipulate
68
	js_po_files = tools.get_matching_file_paths(TRANSLATION_PKG_NAME, '*umc*js*.po')
69
	changes = list()
69
	choosen_po_path = random.choice(js_po_files)
70
	for file_path_pattern in ('*umc*js*.po', '*umc*python*.po'):
70
	choosen_po_pre_changes_path = '{}.pre-change'.format(choosen_po_path)
71
		po_paths = tools.get_matching_file_paths(TRANSLATION_PKG_NAME, '*umc*js*.po')
71
	shutil.copy(choosen_po_path, choosen_po_pre_changes_path)
72
72
	module_path = '/'.join(choosen_po_path.split('/')[2:4])
73
		# po_path, module_path, random_entry
73
	choosen_po = polib.pofile(choosen_po_path)
74
		for i in range(3):
74
	random_entry = random.choice(choosen_po)
75
			random_po_path = po_paths.pop(random.choice(po_paths))
75
76
			# random_po_paths.append(random_po_path)
76
	_change_entry_in_source_file(module_path, random_entry)
77
			copy_file(random_po_path, '{}.pre_change'.format(random_po_path))
78
			module_path = '/'.join(random_po_path.split('/')[2:4])
79
			random_po = polib.pofile(random_po_path)
80
			random_entry = random.choice(random_po)
81
			_change_entry_in_source_file(module_path, random_entry)
82
77
	tools.call('univention-ucs-translation-merge', 'XX', 'svn_repo', TRANSLATION_PKG_NAME)
83
	tools.call('univention-ucs-translation-merge', 'XX', 'svn_repo', TRANSLATION_PKG_NAME)
78
84
79
	if not _entry_is_fuzzy(random_entry, choosen_po_path):
85
	if not _entry_is_fuzzy(random_entry, choosen_po_path):
(-)a/packaging/univention-ucs-translation-template/test1.py (+81 lines)
Line 0    Link Here 
1
import helper
2
import os
3
import sys
4
import shutil
5
from hashlib import md5
6
from difflib import context_diff
7
from distutils.dir_util import copy_tree
8
from distutils.file_util import copy_file
9
10
from pdb import set_trace as dbg
11
12
SVN_PATH = 'SVN_REPO'
13
DUMMY_MOD_DIR = 'management/univention-management-console-module-dummy'
14
DUMMY_MOD_EXPECTED_PO_PATHS = [
15
	'univention-ucs-translation-XX/XX/management/univention-management-console-module-dummy/umc/python/dummy/XX.po',
16
	'univention-ucs-translation-XX/XX/management/univention-management-console-module-dummy/umc/XX.po',
17
	'univention-ucs-translation-XX/XX/management/univention-management-console-module-dummy/umc/js/XX.po'
18
]
19
20
MAKEFILE_EXPECTED_DIFF = [
21
	'+ \t$(DESTDIR)/usr/share/locale/XX/LC_MESSAGES/univention-management-console-module-dummy.mo \\\n',
22
	'+ \t$(DESTDIR)/usr/share/univention-management-console-frontend/js/umc/modules/i18n/XX/dummy.json \\\n',
23
	'+ \t$(DESTDIR)/usr/share/univention-management-console/i18n/XX/dummy.mo \\\n',
24
	'+ $(DESTDIR)/usr/share/locale/XX/LC_MESSAGES/univention-management-console-module-dummy.mo: XX/management/univention-management-console-module-dummy/umc/python/dummy/XX.po\n',
25
	'+ $(DESTDIR)/usr/share/univention-management-console-frontend/js/umc/modules/i18n/XX/dummy.json: XX/management/univention-management-console-module-dummy/umc/js/XX.po\n',
26
	'+ $(DESTDIR)/usr/share/univention-management-console/i18n/XX/dummy.mo: XX/management/univention-management-console-module-dummy/umc/XX.po\n'
27
]
28
29
TRANSLATION_PKG_NAME = 'univention-ucs-translation-XX'
30
if __name__ == '__main__':
31
	# TODO: run whole test in tmp dir
32
	try:
33
		shutil.rmtree(SVN_PATH+'/management/univention-management-console-module-dummy')
34
		shutil.rmtree(TRANSLATION_PKG_NAME)
35
	except Exception:
36
		pass
37
38
	try:
39
		helper.call('svn', 'checkout', 'http://forge.univention.org/svn/dev/branches/ucs-4.1/ucs-4.1-1', SVN_PATH)
40
		helper.call('univention-ucs-translation-build-package', '--source=' + SVN_PATH, '--languagecode=XX', '--locale=fr_FR.UTF-8:UTF-8', '--languagename=TEST0')
41
		helper.call('univention-ucs-translation-fakemessage', TRANSLATION_PKG_NAME)
42
	except helper.InvalidCommandError:
43
		print('Error: Tried to launch invalid command. Exiting.')
44
		sys.exit(1)
45
	copy_file(os.path.join(TRANSLATION_PKG_NAME, 'all_targets.mk'), 'all_targets.mk.pre_merge')
46
47
	# Add dummy module with new translations
48
	copy_tree('./dummy_module', SVN_PATH)
49
	helper.call('univention-ucs-translation-merge', 'XX', SVN_PATH, TRANSLATION_PKG_NAME)
50
	helper.call('univention-ucs-translation-fakemessage', TRANSLATION_PKG_NAME)
51
52
	translation_tree_path = os.path.join(TRANSLATION_PKG_NAME, 'XX', DUMMY_MOD_DIR)
53
	new_po_paths = helper.get_matching_file_paths(translation_tree_path, '*.po')
54
	if not set(new_po_paths) == set(DUMMY_MOD_EXPECTED_PO_PATHS):
55
		print('Test: Failed')
56
		sys.exit(1)
57
	with open('all_targets.mk.pre_merge', 'r') as pre, open(os.path.join(TRANSLATION_PKG_NAME, 'all_targets.mk')) as after:
58
		diff = [line for line in context_diff(pre.readlines(), after.readlines()) if line.startswith('+ ')]
59
60
	if set(diff) != set(MAKEFILE_EXPECTED_DIFF):
61
		dbg()
62
		print('Test: Failed. Diff didn\'t yield expected result.')
63
		print(diff)
64
		sys.exit(1)
65
66
	shutil.rmtree(SVN_PATH+'/management/univention-management-console-module-dummy')
67
	helper.call('univention-ucs-translation-merge', 'XX', SVN_PATH, TRANSLATION_PKG_NAME)
68
69
	# Files obsoleted upstream detected?
70
	new_po_paths = helper.get_matching_file_paths(translation_tree_path, '*.obsolete')
71
	expected_obsoleted_po_paths = ['{}.obsolete'.format(path) for path in DUMMY_MOD_EXPECTED_PO_PATHS]
72
	if set(new_po_paths) != set(expected_obsoleted_po_paths):
73
		print('Test: Failed. Merge didn\'t detect obsoleted po files.')
74
		#sys.exit(1)
75
	
76
	# Makefile should ne the same as before adding the dummy module
77
	with open('all_targets.mk.pre_merge', 'rb') as pre_change, open(os.path.join(TRANSLATION_PKG_NAME, 'all_targets.mk'), 'rb') as after:
78
		if md5(pre_change.read()).hexdigest() != md5(after.read()).hexdigest():
79
			dbg()
80
			print('Test: Failed! Makefile was changed.')
81
			sys.exit(1)
(-)a/packaging/univention-ucs-translation-template/tools.py (+66 lines)
Line 0    Link Here 
1
import subprocess
2
import fnmatch
3
import os
4
import polib
5
import logging
6
7
8
class InvalidCommandError(Exception):
9
	pass
10
11
12
def get_matching_file_paths(path, pattern):
13
	matched_files_paths = list()
14
	for dirname, dns, fnames in os.walk(path):
15
		for fn in fnames:
16
			matched_files_paths.append(os.path.join(dirname, fn))
17
	return fnmatch.filter(matched_files_paths, pattern)
18
19
20
def call(*command_parts):
21
	if not command_parts:
22
		raise InvalidCommandError()
23
	try:
24
		subprocess.check_call([part for part in command_parts])
25
	except subprocess.CalledProcessError as exc:
26
		print('Error: Subprocess exited unsuccessfully. Attempted command:')
27
		print(' '.join(exc.cmd))
28
		raise InvalidCommandError()
29
	except AttributeError as exc:
30
		print('Command must be a string like object.')
31
		raise InvalidCommandError()
32
	except OSError as exc:
33
		print('Error: Command exited unsuccessfully. Operating System error during command execution.')
34
		print('Error: {}'.format(exc.strerror))
35
		raise InvalidCommandError()
36
37
38
#def _entry_is_fuzzy(changed_entry, po_file_path):
39
#	po_file = polib.pofile(po_file_path)
40
#	found_change = False
41
#	for fuzzy in po_file.fuzzy_entries():
42
#		if fuzzy.occurrences == changed_entry.occurrences:
43
#			found_change = True
44
#	return found_change
45
#
46
#
47
#def _remove_fuzzy_flags(po_file_path):
48
#	po_file = polib.pofile(po_file_path)
49
#	for fuzzy_entry in po_file.fuzzy_entries():
50
#		fuzzy_entry.flags.remove('fuzzy')
51
#	po_file.save()
52
#
53
#
54
#SVN_PATH = 'SVN_REPO'
55
#def _change_entry_in_source_file(module_path, po_entry):
56
#	for source_file, line_number in po_entry.occurrences:
57
#		source_file = os.path.join(SVN_PATH, module_path, source_file)
58
#		original_source_file = '{}.orig'.format(source_file)
59
#		os.rename(source_file, original_source_file)
60
#		with open(source_file, 'w') as changed_js:
61
#			with open(original_source_file, 'r') as fd:
62
#				for i, line in enumerate(fd):
63
#					if i == int(line_number) - 1:
64
#						logging.info('Changing {} in line {}'.format(source_file, line_number))
65
#						line = line.replace(po_entry.msgid, 'TEST! {}'.format(po_entry.msgid))
66
#					changed_js.write(line)

Return to bug 41223