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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
|
#!/usr/bin/env python3
import os
import re
import sys
root = "."
if len(sys.argv) > 1:
root = sys.argv[1]
#print "root: ", root
#################################################################
# read in label and property files:
#################################################################
# read in dtd labels and check for duplicates:
dtdFilename = os.path.join(root,"ui","locale","en-US","enigmail.dtd")
dtdLabels = re.findall(r'ENTITY[ \t]*(enigmail[^ \t"]*)[ \t]*"', open(dtdFilename).read())
#print dtdLabels
#print len(dtdLabels)
dtdLabels.sort()
prev=None
for label in dtdLabels:
if label == prev:
print("DUPLICATE label in enigmail.dtd file:", label)
sys.exit(1)
# read in property labels and check for duplicates:
propFilename = os.path.join(root,"ui","locale","en-US","enigmail.properties")
propLabels = []
for line in open(propFilename, 'r'):
if re.match('[ \t]*#.*', line):
continue
match = re.match('[ \t]*([^ \t=]+)[ \t]*=.*', line)
if match:
label = match.group(1)
#print label
propLabels += [label]
#print propLabels
#print len(propLabels)
propLabels.sort()
prev=None
for label in propLabels:
if label == prev:
print("DUPLICATE property in enigmail.properties file:", label)
sys.exit(1)
#################################################################
# used thunderbird labels and properties:
#################################################################
tbLabels = [
"12511",
"copyCmd.accesskey",
"copyCmd.label",
"sendMessageCheckWindowTitle",
"sendMessageCheckLabel",
"sendMessageCheckSendButtonLabel",
"CheckMsg",
"FNC_enigmailVersion",
"FNC_isGpgWorking",
"contextMoveCopyMsgFavoritesMenu.label",
"contextMoveCopyMsgFavoritesMenu.accesskey"
]
#################################################################
# read in label and property files:
#################################################################
allMissingLabels = []
allFoundLabels = []
numLabels = 0
def checkLabel (label, fromFilename):
global numLabels
numLabels += 1
# ignore used thunderbird labels:
if label in tbLabels:
return
if label in dtdLabels:
global allFoundLabels
if not label in allFoundLabels:
allFoundLabels += [label]
else:
print("MISSING LABEL: " + label)
global allMissingLabels
allMissingLabels += [ (label, fromFilename) ]
allMissingProps = []
allFoundProps = []
numProps = 0
def checkProperty (label, fromFilename):
global numProps
numProps += 1
# ignore used thunderbird labels:
if label in tbLabels:
return
# ignore "keyAlgorithm_..."
if label.find("keyAlgorithm_") == 0:
return
# ignore "errorType..."
if label.find("errorType") == 0:
return
if label in propLabels:
global allFoundProps
if not label in allFoundProps:
allFoundProps += [label]
else:
print("MISSING PROPERTY: " + label)
global allMissingProps
allMissingProps += [ (label, fromFilename) ]
#################################################################
# check XUL files:
#################################################################
allLines = ""
def checkXUL (filename):
# print "----------------------------------------"
print(" checkXUL() " + filename)
global allLines
allLines += open(filename, 'r').read()
inComment = False
for line in open(filename, 'r'):
# process comments
# - can't deal with multiple comments in one line
if inComment:
commentEnd = line.find("-->")
if (commentEnd >= 0):
# end of multiline comment:
line = line[commentEnd+3:]
#print line
inComment = False
else:
# stay inside multiline comment:
#print "ignore: ", line
continue
commentBeg = line.find("<!--")
if commentBeg >= 0:
#print line
commentEnd = line.find("-->",commentBeg)
if (commentEnd >= 0):
# comment in one line:
line = line[0:commentBeg] + line[commentEnd+3:]
#print line
else:
# begin of multiline comment:
line = line[0:commentBeg]
inComment = True
# extract and check labels:
match = re.search('&([^;"<]*);', line)
if match:
label = match.group(1)
#print " " + label
checkLabel(label,filename)
match = re.search('Locale\.getString *\("([^;"]*)"', line)
if match:
label = match.group(1)
#print " " + label
checkProperty(label,filename)
matches = re.findall('EnigGetString *\("([^;"]*)"', line)
for label in matches:
#print " " + label
checkProperty(label,filename)
matches = re.findall("EnigGetString *\('([^;']*)'", line)
for label in matches:
#print " " + label
checkProperty(label,filename)
matches = re.findall('\.onError *\("([^;"]*)"', line)
for label in matches:
#print " " + label
checkProperty(label,filename)
def checkJS (filename):
#print "----------------------------------------"
print(" checkJS() " + filename)
global allLines
allLines += open(filename, 'r').read()
inComment = False
for line in open(filename, 'r'):
# process comments
# - can't deal with multiple comments in one line
if inComment:
commentEnd = line.find("*/")
if (commentEnd >= 0):
# end of multiline comment:
line = line[commentEnd+2:]
#print line
inComment = False
else:
# stay inside multiline comment:
#print "ignore: ", line
continue
commentBeg = line.find("/*")
if commentBeg >= 0:
#print line
commentEnd = line.find("*/",commentBeg)
if (commentEnd >= 0):
# comment in one line:
line = line[0:commentBeg] + line[commentEnd+3:]
#print line
else:
# begin of multiline comment:
line = line[0:commentBeg]
inComment = True
commentBeg = line.find("//")
if commentBeg >= 0:
line = line[0:commentBeg]
# extract and check labels:
matches = re.findall('\.getString *\("([^;"]*)"', line)
for label in matches:
#print " " + label
checkProperty(label,filename)
matches = re.findall("\.getString *\('([^;']*)'", line)
for label in matches:
#print " " + label
checkProperty(label,filename)
matches = re.findall('EnigGetString *\("([^;"]*)"', line)
for label in matches:
#print " " + label
checkProperty(label,filename)
matches = re.findall("EnigGetString *\('([^;']*)'", line)
for label in matches:
#print " " + label
checkProperty(label,filename)
matches = re.findall('\.onError *\("([^;"]*)"', line)
for label in matches:
#print " " + label
checkProperty(label,filename)
def checkHTML (filename):
# print "----------------------------------------"
print(" checkHTML() " + filename)
global allLines
allLines += open(filename, 'r').read()
inComment = False
for line in open(filename, 'r'):
# process comments
# - can't deal with multiple comments in one line
if inComment:
commentEnd = line.find("-->")
if (commentEnd >= 0):
# end of multiline comment:
line = line[commentEnd+3:]
#print line
inComment = False
else:
# stay inside multiline comment:
#print "ignore: ", line
continue
commentBeg = line.find("<!--")
if commentBeg >= 0:
#print line
commentEnd = line.find("-->",commentBeg)
if (commentEnd >= 0):
# comment in one line:
line = line[0:commentBeg] + line[commentEnd+3:]
#print line
else:
# begin of multiline comment:
line = line[0:commentBeg]
inComment = True
# extract and check labels:
matches = re.findall('txtId *= *"([^;"]*)"', line)
for label in matches:
#print " " + label
checkProperty(label,filename)
def checkAllXULFiles():
# check XUL files:
path = os.path.join(root)
for path, dirs, files in os.walk(path):
for name in files:
#if name.endswith(".xhtml"):
if name.endswith(".xhtml"):
filename = os.path.join(path,name)
checkXUL(filename)
def checkAllJSFiles():
# check JS/JSM files:
path = os.path.join(root)
for path, dirs, files in os.walk(path):
if str(path).find("build") < 0:
for name in files:
if name.endswith(".js") or name.endswith(".jsm"):
filename = os.path.join(path,name)
checkJS(filename)
def checkAllHtmlFiles():
# check HTML files:
path = os.path.join(root,"ui","content")
for path, dirs, files in os.walk(path):
for name in files:
#if name.endswith(".html"):
if name.endswith(".html"):
filename = os.path.join(path,name)
checkHTML(filename)
def processLabelResults():
# Labels:
knownLabelBugs=0
if len(allMissingLabels) != knownLabelBugs:
print("")
print("All Missing Labels:")
print("===================")
for missing in allMissingLabels:
print(" ", missing[0], " (defined in " + missing[1] + ")")
print("missing ", len(allMissingLabels), "out of", numLabels, "labels")
sys.exit(1)
else:
#print "all", numLabels, "labels (except the", knownLabelBugs, "standard errors) are defined"
print("all", numLabels, "labels usages are defined")
# Properties:
knownPropBugs=0
if len(allMissingProps) != knownPropBugs:
print("")
print("All Missing Properties:")
print("=======================")
for missing in allMissingProps:
print(" ", missing[0], " (defined in " + missing[1] + ")")
print("missing ", len(allMissingProps), "out of", numProps, "properties")
sys.exit(1)
else:
#print "all", numProps, "properties (except the", knownPropBugs, "standard errors) are defined"
print("all", numProps, "property usages are defined")
unusedFile = open('unused.txt',"w")
print("")
print("=============================================")
print("dtdLabels: ", len(dtdLabels))
print("found Labels: ", len(allFoundLabels))
unusedFile.write('unused labels:\n')
numUnusedLabels=0
for label in dtdLabels:
if not label in allFoundLabels:
#print " ", label
if allLines.find(label) >= 0:
print("false positive (or correct because in comment)?: ", label)
else:
numUnusedLabels += 1
unusedFile.write(' '+label+'\n')
print("unused labels in 'unused.txt'")
print("")
print("=============================================")
print("propLabels: ", len(propLabels))
print("found Props: ", len(allFoundProps))
unusedFile.write('\nunused properties:\n')
numUnusedProps=0
for label in propLabels:
# ignore "keyAlgorithm_..."
if label.find("keyAlgorithm_") == 0:
continue
# ignore "errorType..."
if label.find("errorType") == 0:
continue
if not label in allFoundProps:
#print " ", label
if allLines.find(label) >= 0:
print("false positive (or correct because in comment)?: ", label)
else:
numUnusedProps += 1
unusedFile.write(' '+label+'\n')
print("unused props in 'unused.txt'")
print("")
print("=============================================")
print("dtdLabels: ", len(dtdLabels))
print("found Labels: ", len(allFoundLabels))
print("UNUSED Labels: ", numUnusedLabels, " (after double check)")
print("=============================================")
print("propLabels: ", len(propLabels))
print("found Props: ", len(allFoundProps))
print("UNUSED Props: ", numUnusedProps, " (after double check)")
#---------------------------------------------
# check icons
#---------------------------------------------
# return all rows in CSS files that should be equal
def checkCSS (filename):
#print "----------------------------------------"
print(" checkCSS " + filename)
response = []
for line in open(filename, 'r'):
# grep status-bar and list-style-image rows
# extract and check labels:
match = re.search('#enigmail-status-bar.*{', line)
if match:
row = match.group()
#print " " + row
response += [row.strip().replace(' ','')]
match = re.search('list-style-image.*enig[ES].*;', line)
if match:
row = match.group()
#print " " + row
response += [row.strip().replace(' ','')]
return response
def checkAllCSSFiles ():
# reference is classic/enigmail.css:
classicCSS = os.path.join(root,"ui","skin","classic","enigmail.css")
rows = checkCSS (classicCSS)
#print "-----------"
#print rows
#print "-----------"
# other CSS files:
otherFiles = [
os.path.join(root,"ui","skin","classic-seamonkey","enigmail.css"),
os.path.join(root,"ui","skin","classic","enigmail-aero.css"),
os.path.join(root,"ui","skin","modern","enigmail.css"),
os.path.join(root,"ui","skin","tb-linux","enigmail.css"),
os.path.join(root,"ui","skin","tb-mac","enigmail.css"),
];
# find critical differences between CSS files:
for file in otherFiles:
otherRows = checkCSS (file)
if rows != otherRows:
if len(rows) > len(otherRows):
print("ERROR:")
else:
print("WARNING:")
print(" icon entries in ")
print(" ", classicCSS)
print(" and")
print(" ", file)
print(" differ")
print(" first differences:")
diffs = 0;
for i in range(0,min(len(rows),len(otherRows))):
#print "-------"
#print rows[i]
#print otherRows[i]
if rows[i] != otherRows[i]:
diffs += 1
# this difference is OK:
if rows[i].find("enigmail-settings.png") and otherRows[i].find("enigmail-send.png"):
continue
print(rows[i])
print(otherRows[i])
if diffs > 10:
print("...")
print("ERROR => ABORT")
sys.exit(1)
if diffs > 10:
print("ERROR => ABORT")
sys.exit(1)
for i in range(min(len(rows),len(otherRows)),max(len(rows),len(otherRows))):
if i >= len(rows):
print(" only in", file + ":")
print(" " + otherRows[i])
# this is NOT an error
elif i >= len(otherRows):
print(" only in", classicCSS + ":")
print(" " + rows[i])
print("ERROR => ABORT")
sys.exit(1)
#---------------------------------------------
# main()
#---------------------------------------------
# after inits on top...
print("")
checkAllXULFiles()
print("")
checkAllJSFiles()
print("")
checkAllHtmlFiles()
print("")
processLabelResults()
print("")
#checkAllCSSFiles()
|