FreeCAD

Форк
0
/
dir2qrc.py 
164 строки · 4.8 Кб
1
#! python
2
# -*- coding: utf-8 -*-
3
# (c) 2007 Juergen Riegel GPL
4

5
Usage = """dir2qrc - merging all files in a directory in a qrc file
6

7
Usage:
8
   dir2qrc [Optionen]
9

10
Options:
11
 -v, --verbose            print out all files collected
12
 -o  --out-file=FILENAME  use this file name for output, default resources.qrc
13
 -d, --directory=DIRNAME  directory to search, default PWD
14
 -h, --help               print this help message
15

16
This program walks a directory (tree) and collects all supported files
17
and put them in a .qrc file, to compile in with the QT resource facility.
18

19
Examples:
20

21
   dir2qrc  -v -o resource.qrc -d "d:/Develop/Resources"
22

23
Author:
24
  (c) 2007 Juergen Riegel
25
  juergen.riegel@web.de
26
  Licence: GPL
27

28
Version:
29
  0.1
30
"""
31

32
import os, sys, getopt
33
from os.path import join
34

35
# Globals
36
Verbose = False
37
Automatic = False
38
ExtraDist = False
39
Dir = "."
40
Output = "resources.qrc"
41

42
hhcHeader = """<RCC>
43
    <qresource%s>
44
"""
45
hhcFooter = """    </qresource>
46
</RCC>
47
"""
48

49
EndingList = [".xpm", ".svg", ".qm", ".png", ".ui"]
50

51
locations = [
52
    ["../Gui/Language", "translation.qrc", ' prefix="/translations"'],
53
    ["../Gui/Icons", "resource.qrc", ' prefix="/icons"'],
54
    ["../Mod/Assembly/Gui/Resources", "Assembly.qrc"],
55
    ["../Mod/Complete/Gui/Resources", "Complete.qrc"],
56
    ["../Mod/Draft/Resources", "Draft.qrc"],
57
    ["../Mod/Drawing/Gui/Resources", "Drawing.qrc"],
58
    ["../Mod/Fem/Gui/Resources", "Fem.qrc"],
59
    ["../Mod/Image/Gui/Resources", "Image.qrc"],
60
    ["../Mod/Mesh/Gui/Resources", "Mesh.qrc"],
61
    ["../Mod/MeshPart/Gui/Resources", "MeshPart.qrc"],
62
    ["../Mod/Part/Gui/Resources", "Part.qrc"],
63
    ["../Mod/PartDesign/Gui/Resources", "PartDesign.qrc"],
64
    ["../Mod/Points/Gui/Resources", "Points.qrc"],
65
    ["../Mod/ReverseEngineering/Gui/Resources", "ReverseEngineering.qrc"],
66
    ["../Mod/Robot/Gui/Resources", "Robot.qrc"],
67
    ["../Mod/Sketcher/Gui/Resources", "Sketcher.qrc"],
68
]
69

70

71
def main():
72
    global Verbose, Automatic, ExtraDist, Dir, Output
73

74
    try:
75
        opts, args = getopt.getopt(
76
            sys.argv[1:],
77
            "hvd:o:",
78
            ["help", "verbose", "auto", "dist", "directory=", "out-file="],
79
        )
80
    except getopt.GetoptError:
81
        # print help information and exit:
82
        sys.stderr.write(Usage)
83
        sys.exit(2)
84

85
    # checking on the options
86
    for o, a in opts:
87
        if o == "-v":
88
            Verbose = True
89
        if o in ("-h", "--help"):
90
            sys.stderr.write(Usage)
91
            sys.exit()
92
        if o in ("-a", "--auto"):
93
            Automatic = True
94
        if o in ("--dist"):
95
            ExtraDist = True
96
        if o in ("-o", "--out-file"):
97
            Output = a
98
        if o in ("-d", "--directory"):
99
            print("Using path: " + a + "\n")
100
            Dir = a
101

102
    if Automatic:
103
        path = os.path.realpath(__file__)
104
        path = os.path.dirname(path)
105
        for i in locations:
106
            qrcDir = os.path.realpath(join(path, i[0]))
107
            if len(i) > 2:
108
                updateResourceFile(qrcDir, i[1], i[2])
109
            else:
110
                updateResourceFile(qrcDir, i[1])
111
            if ExtraDist:
112
                makeTargetExtraDist(qrcDir)
113
    else:
114
        updateResourceFile(Dir, Output)
115
        if ExtraDist:
116
            makeTargetExtraDist(Dir)
117

118

119
def updateResourceFile(Dir, Output, prefix=""):
120
    global Verbose
121
    Output = join(Dir, Output)
122
    file = open(Output, "w")
123
    file.write(hhcHeader % (prefix))
124
    DirPath = Dir + os.path.sep
125
    filelist = []
126
    for root, dirs, files in os.walk(Dir):
127
        for name in files:
128
            if (1 in [c in name for c in EndingList]) and not (".svn" in root):
129
                FilePathOrg = join(root, name)
130
                FilePath = FilePathOrg.replace(DirPath, "")
131
                FilePath = FilePath.replace(".\\", "")
132
                FilePath = FilePath.replace("\\", "/")
133
                if Verbose:
134
                    print(FilePathOrg + " -> " + FilePath)
135
                filelist.append(FilePath)
136

137
    filelist.sort()
138
    for i in filelist:
139
        file.write("        <file>" + i + "</file>\n")
140

141
    file.write(hhcFooter)
142
    file.close()
143

144

145
def makeTargetExtraDist(Dir):
146
    extensions = EndingList[:]
147
    extensions.append(".qrc")
148
    extensions.append(".bat")
149
    extensions.append(".ts")
150
    print("EXTRA_DIST = \\")
151
    DirPath = Dir + os.path.sep
152
    for root, dirs, files in os.walk(Dir):
153
        for name in files:
154
            if (1 in [c in name for c in extensions]) and not (".svn" in root):
155
                FilePathOrg = join(root, name)
156
                FilePath = FilePathOrg.replace(DirPath, "")
157
                FilePath = FilePath.replace(".\\", "")
158
                FilePath = FilePath.replace("\\", "/")
159
                print("\t\t%s \\" % (FilePath))
160
    print()
161

162

163
if __name__ == "__main__":
164
    main()
165

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.