3
# (c) 2007 Juergen Riegel GPL
5
Usage = """dir2qrc - merging all files in a directory in a qrc file
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
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.
21
dir2qrc -v -o resource.qrc -d "d:/Develop/Resources"
24
(c) 2007 Juergen Riegel
33
from os.path import join
40
Output = "resources.qrc"
45
hhcFooter = """ </qresource>
49
EndingList = [".xpm", ".svg", ".qm", ".png", ".ui"]
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"],
72
global Verbose, Automatic, ExtraDist, Dir, Output
75
opts, args = getopt.getopt(
78
["help", "verbose", "auto", "dist", "directory=", "out-file="],
80
except getopt.GetoptError:
81
# print help information and exit:
82
sys.stderr.write(Usage)
85
# checking on the options
89
if o in ("-h", "--help"):
90
sys.stderr.write(Usage)
92
if o in ("-a", "--auto"):
96
if o in ("-o", "--out-file"):
98
if o in ("-d", "--directory"):
99
print("Using path: " + a + "\n")
103
path = os.path.realpath(__file__)
104
path = os.path.dirname(path)
106
qrcDir = os.path.realpath(join(path, i[0]))
108
updateResourceFile(qrcDir, i[1], i[2])
110
updateResourceFile(qrcDir, i[1])
112
makeTargetExtraDist(qrcDir)
114
updateResourceFile(Dir, Output)
116
makeTargetExtraDist(Dir)
119
def updateResourceFile(Dir, Output, prefix=""):
121
Output = join(Dir, Output)
122
file = open(Output, "w")
123
file.write(hhcHeader % (prefix))
124
DirPath = Dir + os.path.sep
126
for root, dirs, files in os.walk(Dir):
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("\\", "/")
134
print(FilePathOrg + " -> " + FilePath)
135
filelist.append(FilePath)
139
file.write(" <file>" + i + "</file>\n")
141
file.write(hhcFooter)
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):
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))
163
if __name__ == "__main__":