comparison mxtool/mx.py @ 14539:47b775458982

Merged
author Christian Wirth <christian.wirth@oracle.com>
date Fri, 14 Mar 2014 09:58:31 +0100
parents 5454f6bf50bf 7c36ec150036
children 6fb61ad67962
comparison
equal deleted inserted replaced
14538:5454f6bf50bf 14539:47b775458982
347 print 'Downloading ' + ("Sources " if sources else "") + name + ' from ' + str(urls) 347 print 'Downloading ' + ("Sources " if sources else "") + name + ' from ' + str(urls)
348 download(path, urls) 348 download(path, urls)
349 349
350 def _sha1Cached(): 350 def _sha1Cached():
351 with open(sha1path, 'r') as f: 351 with open(sha1path, 'r') as f:
352 return f.readline()[0:40] 352 return f.read()[0:40]
353 353
354 def _writesha1Cached(): 354 def _writeSha1Cached():
355 with open(sha1path, 'w') as f: 355 with open(sha1path, 'w') as f:
356 f.write(_sha1OfFile()) 356 f.write(_sha1OfFile())
357 357
358 def _sha1OfFile(): 358 def _sha1OfFile():
359 with open(path, 'rb') as f: 359 with open(path, 'rb') as f:
360 return hashlib.sha1(f.read()).hexdigest() 360 d = hashlib.sha1()
361 361 while True:
362 buf = f.read(4096)
363 if not buf:
364 break
365 d.update(buf)
366 return d.hexdigest()
362 367
363 if resolve and mustExist and not exists(path): 368 if resolve and mustExist and not exists(path):
364 assert not len(urls) == 0, 'cannot find required library ' + name + ' ' + path 369 assert not len(urls) == 0, 'cannot find required library ' + name + ' ' + path
365 _download_lib() 370 _download_lib()
366 371
367 if sha1 and not exists(sha1path): 372 if sha1 and not exists(sha1path):
368 _writesha1Cached() 373 _writeSha1Cached()
369 374
370 if sha1 and sha1 != _sha1Cached(): 375 if sha1 and sha1 != _sha1Cached():
371 _download_lib() 376 _download_lib()
372 if sha1 != _sha1OfFile(): 377 if sha1 != _sha1OfFile():
373 abort("SHA1 does not match for " + name + ". Broken download? SHA1 not updated in projects file?") 378 abort("SHA1 does not match for " + name + ". Broken download? SHA1 not updated in projects file?")
374 _writesha1Cached() 379 _writeSha1Cached()
375 380
376 return path 381 return path
377 382
378 class Library(Dependency): 383 class Library(Dependency):
379 def __init__(self, suite, name, path, mustExist, urls, sha1, sourcePath, sourceUrls, sourceSha1): 384 def __init__(self, suite, name, path, mustExist, urls, sha1, sourcePath, sourceUrls, sourceSha1):
425 return None 430 return None
426 if not isabs(path): 431 if not isabs(path):
427 path = join(self.suite.dir, path) 432 path = join(self.suite.dir, path)
428 sha1path = path + '.sha1' 433 sha1path = path + '.sha1'
429 434
430 return _download_file_with_sha1(self.name, path, self.sourceUrls, self.sha1, sha1path, resolve, len(self.sourceUrls) != 0, sources=True) 435 return _download_file_with_sha1(self.name, path, self.sourceUrls, self.sourceSha1, sha1path, resolve, len(self.sourceUrls) != 0, sources=True)
431 436
432 def append_to_classpath(self, cp, resolve): 437 def append_to_classpath(self, cp, resolve):
433 path = self.get_path(resolve) 438 path = self.get_path(resolve)
434 if path and (exists(path) or not resolve): 439 if path and (exists(path) or not resolve):
435 cp.append(path) 440 cp.append(path)
1091 return _java 1096 return _java
1092 1097
1093 def run_java(args, nonZeroIsFatal=True, out=None, err=None, cwd=None, addDefaultArgs=True): 1098 def run_java(args, nonZeroIsFatal=True, out=None, err=None, cwd=None, addDefaultArgs=True):
1094 return run(java().format_cmd(args, addDefaultArgs), nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd) 1099 return run(java().format_cmd(args, addDefaultArgs), nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd)
1095 1100
1096 def _kill_process_group(pid, sig=None): 1101 def _kill_process_group(pid, sig):
1097 if not sig: 1102 if not sig:
1098 sig = signal.SIGKILL 1103 sig = signal.SIGKILL
1099 pgid = os.getpgid(pid) 1104 pgid = os.getpgid(pid)
1100 try: 1105 try:
1101 os.killpg(pgid, sig) 1106 os.killpg(pgid, sig)
1271 """ 1276 """
1272 def __init__(self, restrictTo=None, out=sys.stdout): 1277 def __init__(self, restrictTo=None, out=sys.stdout):
1273 self.restrictTo = restrictTo 1278 self.restrictTo = restrictTo
1274 self.seen = set() 1279 self.seen = set()
1275 self.out = out 1280 self.out = out
1281 self.currentFilteredLineCount = 0
1282 self.currentFilteredTime = None
1276 1283
1277 def isSuppressionCandidate(self, line): 1284 def isSuppressionCandidate(self, line):
1278 if self.restrictTo: 1285 if self.restrictTo:
1279 for p in self.restrictTo: 1286 for p in self.restrictTo:
1280 if p in line: 1287 if p in line:
1284 return True 1291 return True
1285 1292
1286 def write(self, line): 1293 def write(self, line):
1287 if self.isSuppressionCandidate(line): 1294 if self.isSuppressionCandidate(line):
1288 if line in self.seen: 1295 if line in self.seen:
1296 self.currentFilteredLineCount += 1
1297 if self.currentFilteredTime:
1298 if time.time() - self.currentFilteredTime > 1 * 60:
1299 self.out.write(" Filtered " + str(self.currentFilteredLineCount) + " repeated lines...\n")
1300 self.currentFilteredTime = time.time()
1301 else:
1302 self.currentFilteredTime = time.time()
1289 return 1303 return
1290 self.seen.add(line) 1304 self.seen.add(line)
1305 self.currentFilteredLineCount = 0
1291 self.out.write(line) 1306 self.out.write(line)
1307 self.currentFilteredTime = None
1292 1308
1293 """ 1309 """
1294 A JavaCompliance simplifies comparing Java compliance values extracted from a JDK version string. 1310 A JavaCompliance simplifies comparing Java compliance values extracted from a JDK version string.
1295 """ 1311 """
1296 class JavaCompliance: 1312 class JavaCompliance:
1469 def _send_sigquit(): 1485 def _send_sigquit():
1470 p, args = _currentSubprocess 1486 p, args = _currentSubprocess
1471 1487
1472 def _isJava(): 1488 def _isJava():
1473 if args: 1489 if args:
1474 name = args[0].split("/")[-1] 1490 name = args[0].split(os.sep)[-1]
1475 return name == "java" 1491 return name == "java"
1476 return False 1492 return False
1477 1493
1478 if p is not None and _isJava(): 1494 if p is not None and _isJava():
1479 if get_os() == 'windows': 1495 if get_os() == 'windows':
1498 p, _ = _currentSubprocess 1514 p, _ = _currentSubprocess
1499 if p is not None: 1515 if p is not None:
1500 if get_os() == 'windows': 1516 if get_os() == 'windows':
1501 p.kill() 1517 p.kill()
1502 else: 1518 else:
1503 _kill_process_group(p.pid) 1519 _kill_process_group(p.pid, signal.SIGKILL)
1504 1520
1505 raise SystemExit(codeOrMessage) 1521 raise SystemExit(codeOrMessage)
1506 1522
1507 def download(path, urls, verbose=False): 1523 def download(path, urls, verbose=False):
1508 """ 1524 """