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
|
'''
Created on Jan 19, 2014
__author__ = "Elizabeth 'pidge' Flanagan"
__copyright__ = "Copyright 2014, Intel Corp."
__credits__ = ["Elizabeth Flanagan"]
__license__ = "GPL"
__version__ = "2.0"
__maintainer__ = "Elizabeth Flanagan"
__email__ = "elizabeth.flanagan@intel.com"
'''
import os
import time
import json
import codecs
import subprocess
import platform
from autobuilder.config import YOCTO_ABBASE
def capitalize(word):
return ' '.join([s[0].upper() + s[1:] for s in word.split(' ')])
def stringToBool(v):
return v.lower() in ("true", "t", "1")
def get_error_report_controller_dir(buildername, buildnumber):
errordir_base = os.path.join(YOCTO_ABBASE, 'yocto-controller', buildername,
'error-report')
errordir = os.path.join(errordir_base, str(buildnumber))
return errordir
def get_error_report_worker_dir(buildername):
if os.environ.get('ERROR_REPORT_DIR') is None:
workerdir = os.path.join(YOCTO_ABBASE, 'yocto-worker')
errordir = os.path.join(workerdir, buildername,
'build/build/tmp/log/error-report/')
else:
errordir = os.environ.get('ERROR_REPORT_DIR')
return errordir
def save_error_report(buildername, buildnumber, report, report_type):
errordir = get_error_report_controller_dir(buildername, buildnumber)
if not os.path.exists(errordir):
os.makedirs(errordir)
filename = os.path.join(errordir, "error_report_%s_%d.txt" % \
(report_type, int(time.time())))
with codecs.open(filename, 'w', 'utf-8') as f:
json.dump(report, f, indent=4, sort_keys=True)
def get_lsb_distro():
"""
Try to get Linux distribution ID using lsb_release if lsb_release
isn't installed use information provided by linux_distribution()
method in platform returns "DISTRONAME-VERSION".
"""
lsb_distro = None
try:
output = subprocess.check_output("lsb_release -ir", shell=True)
lines = output.splitlines()
# Output example:
# Distributor ID:\tDebian
# Release:\t8.4
distro_name = lines[0].split(':')[1].strip()
version = lines[1].split(':')[1].strip()
lsb_distro = "%s-%s" % (distro_name, version)
except Exception as e:
lsb_distro = "%s-%s" % platform.linux_distribution()[0:2]
return lsb_distro
|