Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/build_config/status.py
169674 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file status.py
15
# @author Michael Behrisch
16
# @author Laura Bieker
17
# @date 2007-03-13
18
19
from __future__ import absolute_import
20
from __future__ import print_function
21
22
import os
23
import platform
24
import sys
25
import subprocess
26
import smtplib
27
import re
28
import io
29
import time
30
from os.path import basename, commonprefix
31
from datetime import datetime
32
import logging
33
import logging.handlers
34
35
36
def killall(debugSuffix, binaries):
37
bins = set([name + suff + ".exe" for name in binaries for suff in debugSuffix])
38
printLog("Looking for running instances of %s." % bins)
39
for i in range(2): # killing twice is better than once ;-)
40
clean = True
41
for taskline in subprocess.check_output(["tasklist", "/nh"], universal_newlines=True).splitlines():
42
task = taskline.split()
43
if task and task[0] in bins:
44
printLog("Found %s." % task)
45
log_subprocess(["taskkill", "/f", "/im", task[0]])
46
printLog("Sent kill to all %s (try %s)." % (task[0], i))
47
bins.remove(task[0])
48
clean = False
49
if clean:
50
return
51
time.sleep(10)
52
53
54
def set_rotating_log(filename, remove=None):
55
logger = logging.getLogger()
56
logger.setLevel(logging.INFO)
57
try:
58
if remove:
59
logger.removeHandler(remove)
60
handler = logging.handlers.TimedRotatingFileHandler(filename, when="midnight", backupCount=5)
61
logger.addHandler(handler)
62
return handler
63
except Exception as e:
64
logger.error(e)
65
return None
66
67
68
def log_subprocess(call, env=None, cwd=None):
69
process = subprocess.Popen(call, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
70
shell=True, cwd=cwd, env=env)
71
with process.stdout:
72
for line in process.stdout:
73
logging.info(line.rstrip().decode("ascii", "ignore"))
74
return process.wait()
75
76
77
def printLog(msg):
78
logging.info(u"%s: %s" % (datetime.now(), msg))
79
80
81
def findErrors(line, warnings, errors, failed):
82
if re.search("[Ww]arn[ui]ng[: ]", line) or "[WARNING]" in line:
83
if " test-case " not in line:
84
warnings += 1
85
if re.search("[Ee]rror[: ]", line) or re.search("[Ff]ehler:", line) or "[ERROR]" in line:
86
if " test-case " not in line:
87
errors += 1
88
failed += line
89
return warnings, errors, failed
90
91
92
def printStatus(makeLog, makeAllLog, smtpServer="localhost", out=sys.stdout, toAddr="[email protected]", testLog=None):
93
failed = ""
94
build = commonprefix([basename(makeLog), basename(makeAllLog)])
95
print("_".join((platform.system(), platform.machine(), build)), end=' ', file=out)
96
print(datetime.fromtimestamp(os.stat(makeLog).st_ctime).ctime(), file=out)
97
print("--", file=out)
98
print(basename(makeLog), file=out)
99
warnings = 0
100
errors = 0
101
svnLocked = False
102
generator = False
103
for ml in io.open(makeLog, errors="replace"):
104
if ("svn: Working copy" in ml and "locked" in ml) or "svn: Failed" in ml:
105
svnLocked = True
106
failed += ml
107
if ml.startswith("-- Trying ") and "generator" in ml:
108
generator = not generator
109
if not generator:
110
warnings, errors, failed = findErrors(ml, warnings, errors, failed)
111
if svnLocked:
112
failed += "svn up failed\n\n"
113
print(warnings, "warnings", file=out)
114
if errors:
115
print(errors, "errors", file=out)
116
failed += "make failed\n\n"
117
print("--\nbatchreport\n--", file=out)
118
print(basename(makeAllLog), file=out)
119
warnings = 0
120
errors = 0
121
for ml in io.open(makeAllLog, errors="replace"):
122
warnings, errors, failed = findErrors(ml, warnings, errors, failed)
123
print(warnings, "warnings", file=out)
124
if errors:
125
print(errors, "errors", file=out)
126
failed += "make debug failed\n\n"
127
print("--", file=out)
128
if testLog:
129
print(basename(testLog), file=out)
130
print(datetime.now().ctime(), file=out)
131
print("--", file=out)
132
if failed:
133
fromAddr = "[email protected]"
134
message = """From: "%s" <%s>
135
To: %s
136
Subject: Error occurred while building
137
138
%s""" % (build, fromAddr, toAddr, failed)
139
try:
140
server = smtplib.SMTP(smtpServer)
141
server.sendmail(fromAddr, toAddr, message)
142
server.quit()
143
except Exception:
144
print("Could not send mail.")
145
146
147
if __name__ == "__main__":
148
printStatus(sys.argv[1], sys.argv[2], sys.argv[3], sys.stdout, sys.argv[4],
149
sys.argv[5] if len(sys.argv) > 5 else None)
150
151