Package bodhi :: Module buildsys
[hide private]
[frames] | no frames]

Source Code for Module bodhi.buildsys

  1  # $Id: $ 
  2  # This program is free software; you can redistribute it and/or modify 
  3  # it under the terms of the GNU General Public License as published by 
  4  # the Free Software Foundation; version 2 of the License. 
  5  # 
  6  # This program is distributed in the hope that it will be useful, 
  7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  9  # GNU Library General Public License for more details. 
 10  # 
 11  # You should have received a copy of the GNU General Public License 
 12  # along with this program; if not, write to the Free Software 
 13  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 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  ## Our buildsystem session.  This could be a koji ClientSession or an instance 
 25  ## of our Buildsystem class. 
 26  session = None 
 27   
28 -class Buildsystem:
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
36 - def getLatestBuilds(self): raise NotImplementedError
37 - def moveBuild(self): raise NotImplementedError
38 - def ssl_login(self): raise NotImplementedError
39 - def listBuildRPMs(self):raise NotImplementedError
40 - def listTags(self): raise NotImeplementedError
41 - def listTagged(self): raise NotImplementedError
42 - def taskFinished(self): raise NotImplementedError
43 44
45 -class DevBuildsys(Buildsystem):
46 """ 47 A dummy buildsystem instance used during development 48 """
49 - def moveBuild(self, *args, **kw):
50 log.debug("moveBuild(%s, %s)" % (args, kw))
51
52 - def ssl_login(self, *args, **kw):
53 log.debug("moveBuild(%s, %s)" % (args, kw))
54
55 - def taskFinished(self, task):
56 return True
57
58 - def getTaskInfo(self, task):
59 return { 'state' : koji.TASK_STATES['CLOSED'] }
60
61 - def getBuild(self, *args, **kw):
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
81 - def listBuildRPMs(self, *args, **kw):
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
107 - def listTags(self, *args, **kw):
108 return [{'arches': 'i386 x86_64 ppc ppc64', 'id': 10, 'locked': True, 109 'name': 'dist-fc7-updates-candidate', 'perm': None, 'perm_id': None}, 110 {'arches': 'i386 x86_64 ppc ppc64', 'id': 5, 'locked': True, 111 'name': 'dist-fc7', 'perm': None, 'perm_id': None}]
112
113 - def listTagged(self, tag, *args, **kw):
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
119 - def getLatestBuilds(self, *args, **kw):
120 return [self.getBuild(),]
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
132 -def get_session():
133 """ 134 Get our buildsystem instance. 135 """ 136 global session 137 if not session: 138 buildsys = config.get('buildsystem') 139 log.info("Creating new %s buildsystem instance" % buildsys) 140 if buildsys == 'koji': 141 session = koji_login() 142 elif buildsys == 'dev': 143 session = DevBuildsys() 144 return session
145
146 -def wait_for_tasks(tasks):
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