File indexing completed on 2024-09-08 06:49:28
0001 #!/usr/bin/python 0002 # -*- coding: utf-8 -*- 0003 0004 # SPDX-FileCopyrightText: 2008-2019 Albert Astals Cid <aacid@kde.org> 0005 0006 # SPDX-License-Identifier: GPL-2.0-or-later 0007 0008 import sys 0009 from PyQt5 import QtCore 0010 from PyQt5 import QtGui 0011 from PyQt5 import QtXml 0012 0013 app = QtGui.QGuiApplication(sys.argv) 0014 0015 if len(sys.argv) != 5: 0016 print("Error: You have to specify the sound theme file to check, the folder containing the graphical themes, the folder where to look for the sound files and the path to ignore in the file tag of the sound object") 0017 print(" E.g: For lt it would be something like 'python soundthemecheker.py /home/kdeunstable/l10n-kde4/lt/data/kdegames/ktuberling/lt.soundtheme /home/kdeunstable/kdegames/ktuberling/pics /home/kdeunstable/l10n-kde4/lt/data/kdegames/ktuberling/ lt'") 0018 sys.exit(1) 0019 0020 soundThemePath = sys.argv[1] 0021 graphicalThemesPath = sys.argv[2] 0022 soundsPath = sys.argv[3] 0023 ignorePath = sys.argv[4] 0024 print("Processing " + soundThemePath + " " + graphicalThemesPath) 0025 soundThemeFile = QtCore.QFile(soundThemePath) 0026 0027 if soundThemeFile.exists(): 0028 if (soundThemeFile.open(QtCore.QIODevice.ReadOnly)): 0029 doc = QtXml.QDomDocument() 0030 doc.setContent(soundThemeFile.readAll()) 0031 root = doc.documentElement() 0032 if (root.tagName() == "language"): 0033 soundList = []; 0034 soundTag = root.firstChildElement("sound"); 0035 while (not soundTag.isNull()): 0036 name = soundTag.attribute("name") 0037 contains = soundList.count(name) 0038 if (contains == 0): 0039 soundList.append(name) 0040 fpath = soundTag.attribute("file") 0041 if (fpath.startswith(ignorePath)): 0042 fpath = fpath[len(ignorePath):] 0043 if (not QtCore.QFile.exists(soundsPath + fpath)): 0044 print("Error: Sound file for " + name + " not found") 0045 else: 0046 print("Error: The name {0} is used more than once in the sound theme file".format(name)) 0047 0048 soundTag = soundTag.nextSiblingElement("sound"); 0049 0050 graphicalThemesDir = QtCore.QDir(graphicalThemesPath) 0051 allSoundsList = [] 0052 for graphicalThemePath in graphicalThemesDir.entryList(["*.theme"]): 0053 graphicalThemeFile = QtCore.QFile(graphicalThemesPath + "/" + graphicalThemePath) 0054 if graphicalThemeFile.exists(): 0055 if (graphicalThemeFile.open(QtCore.QIODevice.ReadOnly)): 0056 doc = QtXml.QDomDocument() 0057 doc.setContent(graphicalThemeFile.readAll()) 0058 root = doc.documentElement() 0059 if (root.tagName() == "playground"): 0060 objectTag = root.firstChildElement("object"); 0061 while (not objectTag.isNull()): 0062 sound = objectTag.attribute("sound") 0063 contains = allSoundsList.count(sound) 0064 if (sound == ""): 0065 print("The sound of " + objectTag.attribute("name") + " in " + graphicalThemeFile.fileName() + " is empty") 0066 if (contains == 0): 0067 allSoundsList.append(sound) 0068 0069 objectTag = objectTag.nextSiblingElement("object"); 0070 else: 0071 print("Error: The graphical theme file should begin with the playground tag " + graphicalThemeFile.fileName()) 0072 else: 0073 print("Error: Could not open {0} for reading".format(graphicalThemePath)) 0074 else: 0075 print("Error: File {0} does not exist".format(graphicalThemePath)) 0076 for sound in soundList: 0077 if (allSoundsList.count(sound) == 1): 0078 allSoundsList.remove(sound) 0079 else: 0080 print("Error: The sound theme defines " + sound + " that is not used in any graphical theme") 0081 if (len(allSoundsList) > 0): 0082 print("The following sounds used in the graphical themes are not defined in the sound theme:") 0083 for sound in allSoundsList: 0084 print("\t" + sound) 0085 else: 0086 print("Error: The sound theme file should begin with the language tag") 0087 soundThemeFile.close(); 0088 else: 0089 print("Error: Could not open {0} for reading".format(path)) 0090 else: 0091 print("Error: File {0} does not exist".format(soundThemePath)) 0092 0093 sys.exit(0)