~dobey/tarmac/commands-errors-decorator

« back to all changes in this revision

Viewing changes to tarmac/plugins/recipebuilder.py

  • Committer: Tarmac
  • Author(s): Rodney Dawes
  • Date: 2010-09-02 20:41:41 UTC
  • mfrom: (345.1.2 recipe-builder-plugin)
  • Revision ID: paul@eventuallyanyway.com-20100902204141-hpij29v3reb7j6q1
Add a plug-in to trigger a Package Recipe build on Launchpad

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file is part of Tarmac.
 
2
#
 
3
# Copyright 2010 Canonical, LTd.
 
4
#
 
5
# Tarmac is free software: you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License version 3 as
 
7
# published by the Free Software Foundation.
 
8
#
 
9
# Tarmac is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with Tarmac.  If not, see <http://www.gnu.org/licenses/>.
 
16
'''Tarmac plug-in for triggering package recipe builds on Launchpad.'''
 
17
from tarmac.hooks import tarmac_hooks
 
18
from tarmac.plugins import TarmacPlugin
 
19
 
 
20
 
 
21
class PackageRecipe(TarmacPlugin):
 
22
    '''Tarmac plug-in for triggering a package recipe build.
 
23
 
 
24
    This plug-in checks for the package_recipe setting on the target branch
 
25
    configuration, and if found, triggers that recipe to build on Launchpad.
 
26
    '''
 
27
 
 
28
    def run(self, command, branch_url):
 
29
        '''Trigger a package recipe build.'''
 
30
        try:
 
31
            self.package_recipe = target.config.package_recipe
 
32
            self.series_list = target.config.recipe_series.split(',')
 
33
        except AttributeError:
 
34
            return
 
35
 
 
36
        self.logger.debug('Triggering package recipe: %s' % self.package_recipe)
 
37
        (owner, recipe) = self.package_recipe.split('/')
 
38
        try:
 
39
            for series in self.series_list:
 
40
                lp_recipe = command.launchpad.people[owner].getRecipe(
 
41
                    name=recipe)
 
42
                archive = lp_recipe.daily_build_archive
 
43
                distro = self.launchpad.distributions[u'Ubuntu']
 
44
                lp_series = [x for x in distro.series if x.name == series][0]
 
45
                lp_recipe.requestBuild(archive=archive,
 
46
                                       distroseries=lp_series,
 
47
                                       pocket=u'Release')
 
48
        except (KeyError, ValueError, AttributeError):
 
49
            self.logger.error('Recipe not found: %s' % self.package_recipe)
 
50
            return
 
51
 
 
52
 
 
53
tarmac_hooks['tarmac_post_merge'].hook(PackageRecipe(),
 
54
                                       'Package recipe builder plug-in.')