forked from KviEt/RimWorldHelpInTranslation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
P2.7 Compare.py
81 lines (75 loc) · 3.38 KB
/
P2.7 Compare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
import os
import xml.etree.ElementTree as ET
path = r".\DefInjected"
pathAnother = r".\DefInjectedAnother"
pathKey = r".\Keyed"
pathKeyAnother = r".\KeyedAnother"
ex = [".label", ".rulesStrings", ".description", ".gerund", ".verb", ".deathMessage", ".pawnsPlural", ".fixedName", ".gerundLabel", ".pawnLabel", ".labelShort",
".labelSocial", ".stuffAdjective", ".labelMale", ".labelFemale", ".quotation", ".formatString", ".skillLabel", ".customLabel",
".text", ".name", ".summary", ".jobString", ".letterLabelFriendly", ".arrivalTextFriendly", ".successfullyRemovedHediffMessage",
".arrivalTextEnemy", ".letterLabelEnemy", ".labelMechanoids", ".recoveryMessage", ".inspectLine", ".beginLetter", ".beginLetterLabel",
".endMessage", ".adjective", ".reportString", ".letterLabel", ".letterText", ".graphLabelY", ".letter", ".oldLabel", ".labelSolidTended",
".labelSolidTendedWell", ".labelTendedInner", ".labelTendedWellInner", ".destroyedLabel", ".labelTended", ".labelTendedWell",
".destroyedOutLabel", ".destroyedLabel", ".discoverLetterText", ".discoverLetterLabel", ".leaderTitle", ".instantlyOldLabel", ".useLabel", ".ingestCommandString", ".ingestReportString", ".Description", ".helpText", ".rejectInputMessage", ".onMapInstruction"
]
ex2 = [".helpTexts.", ".rulesStrings."]
def compare(path, pathRus):
#print u"Началось сравнение с %s"%path
print path
treeEng = ET.parse(path)
rootEng = treeEng.getroot()
listElements = [x.tag for x in rootEng]
treeRus = ET.parse(pathRus)
rootRus = treeRus.getroot()
for elementRus in rootRus:
tagRus = elementRus.tag
ask = True
countTag = len(tagRus)
for x in ex:
count = len(x)
if countTag > count and tagRus[-count:] == x:
ask = False
break
if(ask):
for x in ex2:
if x in tagRus:
ask = False
break
if(ask):
print tagRus
if tagRus in listElements:
if(listElements.count(tagRus) > 1):
i = 1
count = listElements.count(tagRus)
while(i < count):
listElements.remove(tagRus)
i = i + 1
listElements.remove(tagRus)
if(listElements):
print u"Файл: %s"%path
print u"Следующие элементы отсутствуют у русской версии:"
for element in listElements:
print element
print
else:
print u"Успешно\n"
def findXML(path, pathRus):
listOfDir = os.listdir(path)
for element in listOfDir:
if ".xml" in element:
xmlRus = os.path.join(pathRus, element)
if os.path.isfile(xmlRus):
compare(os.path.join(path, element), xmlRus)
else:
print u"У русской версии не существует файла %s\n"%xmlRus
listOfDir = os.listdir(pathAnother)
for element in listOfDir:
sub = os.path.join(pathAnother, element)
if os.path.isdir(sub):
subRus = os.path.join(path, element)
if os.path.exists(subRus):
findXML(sub, subRus)
else:
print u"У русской версии не существует папки %s"%subRus
#findXML(pathKeyAnother, pathKey)