| 
 | 1 | +#!/usr/bin/python  | 
 | 2 | +# -*- coding: utf-8 -*-  | 
 | 3 | +# (c) 2010 Werner Mayer LGPL  | 
 | 4 | + | 
 | 5 | +#***************************************************************************  | 
 | 6 | +#*                                                                         *  | 
 | 7 | +#*   Copyright (c) 2010 Werner Mayer <[email protected]>        *  | 
 | 8 | +#*                                                                         *  | 
 | 9 | +#*   This program is free software; you can redistribute it and/or modify  *  | 
 | 10 | +#*   it under the terms of the GNU Library General Public License (LGPL)   *  | 
 | 11 | +#*   as published by the Free Software Foundation; either version 2 of     *  | 
 | 12 | +#*   the License, or (at your option) any later version.                   *  | 
 | 13 | +#*   for detail see the LICENCE text file.                                 *  | 
 | 14 | +#*                                                                         *  | 
 | 15 | +#*   This program is distributed in the hope that it will be useful,       *  | 
 | 16 | +#*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *  | 
 | 17 | +#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *  | 
 | 18 | +#*   GNU Library General Public License for more details.                  *  | 
 | 19 | +#*                                                                         *  | 
 | 20 | +#*   You should have received a copy of the GNU Library General Public     *  | 
 | 21 | +#*   License along with this program; if not, write to the Free Software   *  | 
 | 22 | +#*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *  | 
 | 23 | +#*   USA                                                                   *  | 
 | 24 | +#*                                                                         *  | 
 | 25 | +#***************************************************************************  | 
 | 26 | + | 
 | 27 | + | 
 | 28 | +Usage = """updatets - update all .ts files found in the source directories  | 
 | 29 | +
  | 
 | 30 | +Usage:  | 
 | 31 | +   updatets  | 
 | 32 | +
  | 
 | 33 | +Author:  | 
 | 34 | +  (c) 2010 Werner Mayer  | 
 | 35 | +  Licence: GPL  | 
 | 36 | +
  | 
 | 37 | +Version:  | 
 | 38 | +  0.1  | 
 | 39 | +"""  | 
 | 40 | + | 
 | 41 | +import os, re  | 
 | 42 | + | 
 | 43 | +# folders that should not be treated by standard Qt tools  | 
 | 44 | +DirFilter = ["^Attic$",  | 
 | 45 | +             "^CVS$",  | 
 | 46 | +             "^\\.svn$",  | 
 | 47 | +             "^\\.deps$",  | 
 | 48 | +             "^\\.libs$"  | 
 | 49 | +             "oDraft.py"]  | 
 | 50 | + | 
 | 51 | +# python folders that need a special pylupdate command  | 
 | 52 | +PyCommands = [["./",  | 
 | 53 | +               'pylupdate `find ./ -name "*.py"` -ts Resources/translations/Manipulator.ts'],  | 
 | 54 | +               ]  | 
 | 55 | + | 
 | 56 | +# add python folders to exclude list  | 
 | 57 | +for c in PyCommands:  | 
 | 58 | +    DirFilter.append(c[0])  | 
 | 59 | + | 
 | 60 | +QMAKE = ""  | 
 | 61 | +LUPDATE = ""  | 
 | 62 | +PYLUPDATE = ""  | 
 | 63 | + | 
 | 64 | +def find_tools():  | 
 | 65 | +    global QMAKE, LUPDATE, PYLUPDATE  | 
 | 66 | +    if (os.system("qmake -version") == 0):  | 
 | 67 | +        QMAKE = "qmake"  | 
 | 68 | +    elif (os.system("qmake-qt4 -version") == 0):  | 
 | 69 | +        QMAKE = "qmake-qt4"  | 
 | 70 | +    elif (os.system("qmake-qt5 -version") == 0):  | 
 | 71 | +        QMAKE = "qmake-qt5"  | 
 | 72 | +    else:  | 
 | 73 | +        raise Exception("Cannot find qmake")  | 
 | 74 | +    if (os.system("lupdate -version") == 0):  | 
 | 75 | +        LUPDATE = "lupdate"  | 
 | 76 | +    if (os.system("lupdate-qt4 -version") == 0):  | 
 | 77 | +        LUPDATE = "lupdate-qt4"  | 
 | 78 | +    elif (os.system("lupdate-qt5 -version") == 0):  | 
 | 79 | +        LUPDATE = "lupdate-qt5"  | 
 | 80 | +    else:  | 
 | 81 | +        raise Exception("Cannot find lupdate")  | 
 | 82 | +    if (os.system("pylupdate -version") == 0):  | 
 | 83 | +        PYLUPDATE = "pylupdate"  | 
 | 84 | +    elif (os.system("pylupdate4 -version") == 0):  | 
 | 85 | +        PYLUPDATE = "pylupdate4"  | 
 | 86 | +    elif (os.system("pylupdate5 -version") == 0):  | 
 | 87 | +        PYLUPDATE = "pylupdate5"  | 
 | 88 | +    else:  | 
 | 89 | +        raise Exception("Cannot find pylupdate")  | 
 | 90 | +    print("Qt tools:", QMAKE, LUPDATE, PYLUPDATE)  | 
 | 91 | + | 
 | 92 | +def filter_dirs(item):  | 
 | 93 | +    global DirFilter  | 
 | 94 | +    if not os.path.isdir(item):  | 
 | 95 | +        return False  | 
 | 96 | +    for regexp in DirFilter:  | 
 | 97 | +        a = re.compile(regexp)  | 
 | 98 | +        if (re.match(a, item)):  | 
 | 99 | +            return False  | 
 | 100 | +    return True  | 
 | 101 | + | 
 | 102 | +def update_translation(path):  | 
 | 103 | +    global QMAKE, LUPDATE  | 
 | 104 | +    cur = os.getcwd()  | 
 | 105 | +    os.chdir(path)  | 
 | 106 | +    filename = os.path.basename(path) + ".pro"  | 
 | 107 | +    os.system(QMAKE + " -project")  | 
 | 108 | +    os.system(LUPDATE + " " + filename)  | 
 | 109 | +    os.remove(filename)  | 
 | 110 | +    os.chdir(cur)  | 
 | 111 | + | 
 | 112 | +def update_python_translation(item):  | 
 | 113 | +    global PYLUPDATE  | 
 | 114 | +    cur = os.getcwd()  | 
 | 115 | +    os.chdir(item[0])  | 
 | 116 | +    execline = item[1].replace("pylupdate",PYLUPDATE)  | 
 | 117 | +    print("Executing special command in ",item[0],": ",execline)  | 
 | 118 | +    os.system(execline)  | 
 | 119 | +    os.chdir(cur)  | 
 | 120 | + | 
 | 121 | +def main():  | 
 | 122 | +    find_tools()  | 
 | 123 | +    path = os.path.realpath(__file__)  | 
 | 124 | +    path = os.path.dirname(path)  | 
 | 125 | +    os.chdir(path)  | 
 | 126 | +    os.chdir("..")  | 
 | 127 | +    os.chdir("..")  | 
 | 128 | +    dirs=os.listdir("src/Mod")  | 
 | 129 | +    for i in range(len(dirs)):  | 
 | 130 | +        dirs[i] = "src/Mod/" + dirs[i]  | 
 | 131 | +    # dirs.append("src/Base")  | 
 | 132 | +    # dirs.append("src/App")  | 
 | 133 | +    # dirs.append("src/Gui")  | 
 | 134 | +    dirs = filter(filter_dirs, dirs)  | 
 | 135 | +    for i in dirs:  | 
 | 136 | +        update_translation(i)  | 
 | 137 | +    for j in PyCommands:  | 
 | 138 | +        update_python_translation(j)  | 
 | 139 | + | 
 | 140 | +if __name__ == "__main__":  | 
 | 141 | +    main()  | 
0 commit comments