1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 import koji
16 import logging
17
18 from time import sleep
19 from os.path import join, expanduser
20 from turbogears import config
21
22 log = logging.getLogger(__name__)
23
24
25
26 session = None
27
29 """
30 The parent for our buildsystem. Not only does this help us keep track of
31 the functionality that we expect from our buildsystem, but it also alows
32 us to create a development subclass of this object to use during development
33 so we don't alter any production data.
34 """
35 - def getBuild(self): raise NotImplementedError
37 - def moveBuild(self): raise NotImplementedError
38 - def ssl_login(self): raise NotImplementedError
43
44
46 """
47 A dummy buildsystem instance used during development
48 """
50 log.debug("moveBuild(%s, %s)" % (args, kw))
51
53 log.debug("moveBuild(%s, %s)" % (args, kw))
54
57
59 return { 'state' : koji.TASK_STATES['CLOSED'] }
60
62 return {'build_id': 16058,
63 'completion_time': '2007-08-24 23:26:10.890319',
64 'creation_event_id': 151517,
65 'creation_time': '2007-08-24 19:38:29.422344',
66 'epoch': None,
67 'id': 16058,
68 'name': 'TurboGears',
69 'nvr': 'TurboGears-1.0.2.2-2.fc7',
70 'owner_id': 388,
71 'owner_name': 'lmacken',
72 'package_id': 8,
73 'package_name': 'TurboGears',
74 'release': '2.fc7',
75 'state': 1,
76 'tag_id': 19,
77 'tag_name': 'dist-fc7-updates-testing',
78 'task_id': 127621,
79 'version': '1.0.2.2'}
80
82 return [{'arch': 'src',
83 'build_id': 6475,
84 'buildroot_id': 1883,
85 'buildtime': 1178868422,
86 'epoch': None,
87 'id': 62330,
88 'name': 'TurboGears',
89 'nvr': 'TurboGears-1.0.2.2-2.fc7',
90 'payloadhash': '6787febe92434a9be2a8f309d0e2014e',
91 'release': '2.fc7',
92 'size': 761742,
93 'version': '1.0.2.2'},
94 {'arch': 'noarch',
95 'build_id': 6475,
96 'buildroot_id': 1883,
97 'buildtime': 1178868537,
98 'epoch': None,
99 'id': 62331,
100 'name': 'TurboGears',
101 'nvr': 'TurboGears-1.0.2.2-2.fc7',
102 'payloadhash': 'f3ec9bdce453816f94283a15a47cb952',
103 'release': '2.fc7',
104 'size': 1993385,
105 'version': '1.0.2.2'},]
106
112
114 if tag not in ('dist-fc7', 'dist-fc7-updates-candidate',
115 'dist-fc7-updates-testing', 'dist-fc7-updates'):
116 raise koji.GenericError
117 return [self.getBuild(),]
118
121
122 -def koji_login(client=join(expanduser('~'), '.fedora.cert'),
123 clientca=join(expanduser('~'), '.fedora-upload-ca.cert'),
124 serverca=join(expanduser('~'), '.fedora-server-ca.cert')):
125 """
126 Login to Koji and return the session
127 """
128 koji_session = koji.ClientSession(config.get('koji_hub'), {})
129 koji_session.ssl_login(client, clientca, serverca)
130 return koji_session
131
145
147 """
148 Wait for a list of koji tasks to complete. Return the first task number
149 to fail, otherwise zero.
150 """
151 log.debug("Waiting for tasks to complete: %s" % tasks)
152 for task in tasks:
153 while not session.taskFinished(task):
154 sleep(2)
155 task_info = session.getTaskInfo(task)
156 if task_info['state'] != koji.TASK_STATES['CLOSED']:
157 log.error("Koji task %d failed" % task)
158 return task
159 return 0
160