getsubs()   B
last analyzed

Complexity

Conditions 7

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
dl 0
loc 15
rs 7.3333
c 0
b 0
f 0
1
#! python3
2
# -*- coding: utf-8 -*-
3
4
import os
5
import sys
6
7
8
# change to value of your locale
9
locale = "ru_RU"
10
11
12
def filterFiles(str):
13
    if str.endswith(".py"):
14
        return True
15
    return False
16
17
18
def getsubs(dir):
19
    # get all
20
    dirs = []
21
    files = []
22
    src = []
23
    for dirname, dirnames, filenames in os.walk(dir):
24
        dirs.append(dirname)
25
        for subdirname in dirnames:
26
            dirs.append(os.path.join(dirname, subdirname))
27
            for filename in filenames:
28
                files.append(os.path.join(dirname, filename))
29
    for file in files:
30
        if filterFiles(file) and (file not in src):
31
            src.append(file)
32
    return src
33
34
35
def updateTranslation():
36
    print("__update__")
37
    files = getsubs(os.getcwd())
38
    myString = ' '.join(files)
39
    text = "pylupdate5 {0!s} -ts i18n/{1!s}.ts".format(myString, locale)
40
    os.system(text)
41
42
43
def clearTranslation():
44
    print("__no_obsolete__")
45
    files = getsubs(os.getcwd())
46
    myString = ' '.join(files)
47
    text = "pylupdate5 {0!s} -ts -noobsolete i18n/{1!s}.ts".format(myString, locale)
48
    os.system(text)
49
50
51
def fixationTranslation():
52
    print("__fixation__")
53
    text = "lrelease i18n/{0!s}.ts".format(locale)
54
    os.system(text)
55
56
57
if __name__ == "__main__":
58
    if len(sys.argv) > 1:
59
        if sys.argv[1] == "upd":
60
            updateTranslation()
61
        if sys.argv[1] == "fix":
62
            fixationTranslation()
63
        if sys.argv[1] == "clr":
64
            clearTranslation()
65
    else:
66
        print("Usage: \n params: upd | fix")
67
        print("upd - Update the specified language translations in the variable 'locale'")
68
        print("fix - Compilation of translations specified language")
69
        print("clr - Drop all obsolete strings'")
70
        print("!!!  don't forget update var locale in script !!!")
71