-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_agicen_builds.py
executable file
·119 lines (91 loc) · 3.64 KB
/
get_agicen_builds.py
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
#!/usr/bin/env python
import sys
import time
import yaml
sys.path.insert(0, 'bldeif')
__version__ = '0.2.2'
#from agicen_bld_connection import AgileCentralConnection
from bldeif.agicen_bld_connection import AgileCentralConnection
from bldeif.utils.eif_exception import ConfigurationError, OperationalError
from bldeif.utils.klog import ActivityLogger
from pprint import pprint
config_chunk = """
AgileCentral:
Server : rally1.rallydev.com
Username : [email protected]
Password : "big**WHUPj9876"
#API_Key : _xxdabas3892qytqhqb89qev4h279ygb3497qy4739387y0
Workspace: Wonnicam
#DefaultProject: Engineering
DefaultProject: Dancing Fruit Boggles
Service:
LogLevel: INFO
Preview: True
"""
CONFIG_CHUNK = """
AgileCentral:
Server : rally1.rallydev.com
#Username : [email protected]
#Password : abc123!!
APIKey : _x6CZhqQgiist6kTtwthsAAKHtjWE7ivqimQdpP3T4
Workspace: Rally
DefaultProject: Engineering
Service:
LogLevel: INFO
Preview: True
"""
###########################################################################################################
def main(args):
if args:
config_file_name = args.pop(0)
with open("config/%s" % config_file_name, 'r') as f:
uber_conf = yaml.load(f)
conf = uber_conf['JenkinsBuildConnector']
else:
conf = yaml.load(CONFIG_CHUNK)
ac_conf = conf['AgileCentral']
#pprint(ac_conf)
#print("=" * 80)
#print("")
logger = ActivityLogger("agicen.builds.log", policy='calls', limit=1000)
agicen = AgileCentralConnection(ac_conf, logger)
agicen_headers = {'name' : 'AgileCentral Build Lister', 'version' : __version__,
'vendor' : 'Open Source Galaxy', 'other_version' : 'placeholder' }
agicen.set_integration_header(agicen_headers)
agicen.setSourceIdentification('placeholder', '0.0.0')
agicen.connect()
ref_timestamp = (2016, 3, 1, 0, 0, 0, 5, 0, -1)
started = time.time()
builds = agicen.getRecentBuilds(ref_timestamp)
print("%d Projects had Build items within the defined scope" % len(builds))
finished = time.time()
for project in builds:
##
# if project != ac_conf['DefaultProject']:
# break
##
print("AgileCentral Project: %s" % project)
job_names = builds[project].keys()
for job_name in job_names:
for build in builds[project][job_name]:
build_date = build.Start[:-5].replace('T', ' ')
duration = pretty_duration(build.Duration)
print(" %-24.24s %5d %-10.10s %s %15.15s" % \
(job_name, int(build.Number), build.Status, build_date, duration))
print("")
print("Elapsed retrieval time: %6.3f seconds" % (finished - started))
###########################################################################################################
def pretty_duration(value_in_secs_millis):
whole_secs, millis = str(value_in_secs_millis).split('.')
hours, seconds = divmod(int(whole_secs), 3600)
minutes, secs = divmod(seconds, 60)
duration = "%02d:%02d.%-3.3s" % (minutes, secs, millis[:3])
if hours:
duration = ("%d:" % hours) + duration
else:
duration = "%d:%02d.%-3.3s" % (minutes, secs, millis[:3])
return duration
###########################################################################################################
###########################################################################################################
if __name__ == '__main__':
main(sys.argv[1:])