Passed
Push — master ( 04fbbf...5a831b )
by Daniel
01:17
created

project_locale.localizations_maintain_sources   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 52
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B LocalizationsMaintainSources.evaluate_update_necessity() 0 46 6
1
"""
2
localization_update - facilitates localization file maintenance
3
"""
4
import os
5
6
from localizations_common import LocalizationsCommon
7
8
9
class LocalizationsMaintainSources(LocalizationsCommon):
10
11
    def evaluate_update_necessity(self, in_list_localisation_source_files):
12
        list_size = len(in_list_localisation_source_files)
13
        self.operation_is_required = False
14
        file_list_paring_complete = False
15
        file_counter = 0
16
        domains_locale_to_update = []
17
        compiling_files_counter = 0
18
        while not file_list_paring_complete:
19
            template_localisation_file = in_list_localisation_source_files[file_counter]
20
            for current_locale in self.locale_implemented:
21
                join_separator = os.path.altsep
22
                elements_to_join = [
23
                    os.path.dirname(template_localisation_file),
24
                    current_locale,
25
                    'LC_MESSAGES',
26
                    os.path.basename(template_localisation_file).replace('.pot', '.po'),
27
                ]
28
                fn_dict = {
29
                    'destination': join_separator.join(elements_to_join),
30
                    'counter': file_counter,
31
                    'locale': current_locale,
32
                    'source': template_localisation_file,
33
                    'source file type name': 'template',
34
                    'destination operation name': 'update',
35
                }
36
                operation_check_result, file_situation_verdict = self.check_file_pairs(fn_dict)
37
                operation_to_execute = ''
38
                operation_final_flags = ''
39
                if 'missing' in file_situation_verdict:
40
                    operation_to_execute = 'init_catalog'
41
                elif 'newer' in file_situation_verdict:
42
                    operation_to_execute = 'update_catalog'
43
                    operation_final_flags = ' --previous'
44
                if operation_check_result:
45
                    domains_locale_to_update.append(compiling_files_counter)
46
                    domains_locale_to_update[compiling_files_counter] = {
47
                        'input-file': fn_dict['source'],
48
                        'operation': operation_to_execute,
49
                        'operation final flags': operation_final_flags,
50
                        'output-file': fn_dict['destination'],
51
                        'locale': fn_dict['locale'],
52
                    }
53
                    compiling_files_counter += 1
54
            file_counter += 1
55
            file_list_paring_complete = self.file_counter_limit(file_counter, list_size)
56
        return domains_locale_to_update
57
58
59
my_class = LocalizationsMaintainSources()
60
61
locale_source_files = my_class.get_project_localisation_source_files('pot')
62
operation_locale_dict = my_class.evaluate_update_necessity(locale_source_files)
63
print(operation_locale_dict)
64
my_class.operate_localisation_files(operation_locale_dict)
65