11
11
12
12
13
13
def collect_ci_info ():
14
- d = dict ()
15
14
# Test for jenkins
16
- if "BUILD_NUMBER" in os .environ :
17
- if "BRANCH_NAME" in os .environ or "JOB_NAME" in os .environ :
18
- br = os .environ ["BRANCH_NAME" ] if "BRANCH_NAME" in os .environ else os .environ ["JOB_NAME" ]
19
- d = dict (
20
- pipeline_branch = br ,
21
- pipeline_build_no = os .environ ["BUILD_NUMBER" ],
22
- __ci__ = "jenkinsci" ,
23
- )
15
+ if "BUILD_NUMBER" in os .environ and ("BRANCH_NAME" in os .environ or "JOB_NAME" in os .environ ):
16
+ br = os .environ ["BRANCH_NAME" ] if "BRANCH_NAME" in os .environ else os .environ ["JOB_NAME" ]
17
+ return {
18
+ "pipeline_branch" : br ,
19
+ "pipeline_build_no" : os .environ ["BUILD_NUMBER" ],
20
+ "__ci__" : "jenkinsci" ,
21
+ }
24
22
# Test for CircleCI
25
23
if "CIRCLE_JOB" in os .environ and "CIRCLE_BUILD_NUM" in os .environ :
26
- d = dict (
27
- pipeline_branch = os .environ ["CIRCLE_JOB" ],
28
- pipeline_build_no = os .environ ["CIRCLE_BUILD_NUM" ],
29
- __ci__ = "circleci" ,
30
- )
24
+ return {
25
+ " pipeline_branch" : os .environ ["CIRCLE_JOB" ],
26
+ " pipeline_build_no" : os .environ ["CIRCLE_BUILD_NUM" ],
27
+ " __ci__" : "circleci" ,
28
+ }
31
29
# Test for TravisCI
32
30
if "TRAVIS_BUILD_NUMBER" in os .environ and "TRAVIS_BUILD_ID" in os .environ :
33
- d = dict (
34
- pipeline_branch = os .environ ["TRAVIS_BUILD_ID" ],
35
- pipeline_build_no = os .environ ["TRAVIS_BUILD_NUMBER" ],
36
- __ci__ = "travisci" ,
37
- )
31
+ return {
32
+ " pipeline_branch" : os .environ ["TRAVIS_BUILD_ID" ],
33
+ " pipeline_build_no" : os .environ ["TRAVIS_BUILD_NUMBER" ],
34
+ " __ci__" : "travisci" ,
35
+ }
38
36
# Test for DroneCI
39
37
if "DRONE_REPO_BRANCH" in os .environ and "DRONE_BUILD_NUMBER" in os .environ :
40
- d = dict (
41
- pipeline_branch = os .environ ["DRONE_REPO_BRANCH" ],
42
- pipeline_build_no = os .environ ["DRONE_BUILD_NUMBER" ],
43
- __ci__ = "droneci" ,
44
- )
38
+ return {
39
+ " pipeline_branch" : os .environ ["DRONE_REPO_BRANCH" ],
40
+ " pipeline_build_no" : os .environ ["DRONE_BUILD_NUMBER" ],
41
+ " __ci__" : "droneci" ,
42
+ }
45
43
# Test for Gitlab CI
46
44
if "CI_JOB_NAME" in os .environ and "CI_PIPELINE_ID" in os .environ :
47
- d = dict (
48
- pipeline_branch = os .environ ["CI_JOB_NAME" ],
49
- pipeline_build_no = os .environ ["CI_PIPELINE_ID" ],
50
- __ci__ = "gitlabci" ,
51
- )
52
- return d
45
+ return {
46
+ " pipeline_branch" : os .environ ["CI_JOB_NAME" ],
47
+ " pipeline_build_no" : os .environ ["CI_PIPELINE_ID" ],
48
+ " __ci__" : "gitlabci" ,
49
+ }
50
+ return {}
53
51
54
52
55
53
def determine_scm_revision ():
@@ -68,9 +66,9 @@ def _get_cpu_string():
68
66
if platform .system ().lower () == "darwin" :
69
67
old_path = os .environ ["PATH" ]
70
68
os .environ ["PATH" ] = old_path + ":" + "/usr/sbin"
71
- ret = subprocess .check_output ("sysctl -n machdep.cpu.brand_string" , shell = True ). decode (). strip ()
69
+ ret = subprocess .check_output ("sysctl -n machdep.cpu.brand_string" , shell = True )
72
70
os .environ ["PATH" ] = old_path
73
- return ret
71
+ return ret . decode (). strip ()
74
72
if platform .system ().lower () == "linux" :
75
73
with open ("/proc/cpuinfo" , "r" , encoding = "utf-8" ) as f :
76
74
lines = [i for i in f if i .startswith ("model name" )]
@@ -107,19 +105,19 @@ def _read_cpu_freq_from_env(self):
107
105
self .__cpu_freq_base = 0.0
108
106
109
107
def to_dict (self ):
110
- return dict (
111
- cpu_count = self .cpu_count ,
112
- cpu_frequency = self .cpu_frequency ,
113
- cpu_type = self .cpu_type ,
114
- cpu_vendor = self .cpu_vendor ,
115
- ram_total = self .ram_total ,
116
- machine_node = self .fqdn ,
117
- machine_type = self .machine ,
118
- machine_arch = self .architecture ,
119
- system_info = self .system_info ,
120
- python_info = self .python_info ,
121
- h = self .hash (),
122
- )
108
+ return {
109
+ " cpu_count" : self .cpu_count ,
110
+ " cpu_frequency" : self .cpu_frequency ,
111
+ " cpu_type" : self .cpu_type ,
112
+ " cpu_vendor" : self .cpu_vendor ,
113
+ " ram_total" : self .ram_total ,
114
+ " machine_node" : self .fqdn ,
115
+ " machine_type" : self .machine ,
116
+ " machine_arch" : self .architecture ,
117
+ " system_info" : self .system_info ,
118
+ " python_info" : self .python_info ,
119
+ "h" : self .compute_hash (),
120
+ }
123
121
124
122
@property
125
123
def cpu_count (self ):
@@ -161,7 +159,7 @@ def system_info(self):
161
159
def python_info (self ):
162
160
return self .__py_ver
163
161
164
- def hash (self ):
162
+ def compute_hash (self ):
165
163
hr = hashlib .md5 ()
166
164
hr .update (str (self .__cpu_count ).encode ())
167
165
hr .update (str (self .__cpu_freq_base ).encode ())
0 commit comments