2
""" Skip an arch for a project on a stack
4
# Copyright (C) 2012-2013, Canonical Ltd (http://www.canonical.com/)
6
# Author: Jean-Baptiste Lallement <jean-baptiste.lallement@canonical.com>
7
# Author: Didier Roche <didier.roche@canonical.com>
9
# This software is free software: you can redistribute it
10
# and/or modify it under the terms of the GNU General Public License
11
# as published by the Free Software Foundation, either version 3 of
12
# the License, or (at your option) any later version.
14
# This software is distributed in the hope that it will
15
# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
16
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this software. If not, see <http://www.gnu.org/licenses/>.
29
BINDIR = os.path.dirname(__file__)
31
DEFAULT_CREDENTIALS = os.path.expanduser('~/.cu2d.cred')
32
DEFAULT_RELEASE = 'head'
35
def load_jenkins_credentials(path):
36
""" Load Credentials from credentials configuration file """
37
if not os.path.exists(path):
40
logging.debug('Loading credentials from %s', path)
41
cred = yaml.load(file(path, 'r'))
43
for param in ('username', 'password', 'url', 'token'):
44
if not param in cred['jenkins']:
45
logging.error("Setting missing from jenkins credentials: %s. "
48
return False if not 'jenkins' in cred else cred['jenkins']
51
def run(jkcfg, stack, release, project, archs, **kwargs):
52
""" Force publication of a stack/release
54
:param jkcfg: dictionary with the credentials
55
:param stack: Name of the stack to publish
56
:param release: Name of the release the stack belongs tostack to publish
57
:param project: project on which we want to separate one or more archs
58
:param archs: archs we want to skip
60
logging.debug('Logging to Jenkins')
61
if 'username' in jkcfg:
62
jkh = jenkins.Jenkins(jkcfg['url'],
63
username=jkcfg['username'],
64
password=jkcfg['password'])
66
jkh = jenkins.Jenkins(jkcfg['url'])
68
jobname = "cu2d-skip-project-archs"
69
args = {'stack': stack,
72
'archs': " ".join(archs)}
74
if not jkh.job_exists(jobname):
75
logging.info("Job '%s' doesn't exists.", jobname)
78
logging.info('Triggering build: %s', jobname)
79
jkh.build_job(jobname, args, token=jkcfg['token'])
84
def set_logging(debugmode=False):
85
"""Initialize logging"""
87
level=logging.DEBUG if debugmode else logging.INFO,
88
format="%(asctime)s %(levelname)s %(message)s"
90
logging.debug('Debug mode enabled')
95
parser = argparse.ArgumentParser(
96
description='Tell an existing run to skip one or multiple archs for a build')
97
parser.add_argument('-C', '--credentials', metavar='CREDENTIALFILE',
98
default=DEFAULT_CREDENTIALS,
99
help='use Jenkins and load credentials from '
100
'CREDENTIAL FILE (default: %s)' % DEFAULT_CREDENTIALS)
101
parser.add_argument('-r', '--release',
102
default=DEFAULT_RELEASE,
103
help='Release the stack to publish belongs to '
104
'(default: %s)' % DEFAULT_RELEASE)
105
parser.add_argument('-d', '--debug', action='store_true', default=False,
106
help='enable debug mode')
107
parser.add_argument('stack', help='Name of the stack to publish')
108
parser.add_argument('project', help='Name of the project (source package) to skip one arch')
109
parser.add_argument('archs', nargs='+', help='Archs (separated by commas) to skip')
111
args = parser.parse_args()
112
set_logging(args.debug)
116
credentialsfile = args.credentials
117
credentials = load_jenkins_credentials(
118
os.path.expanduser(credentialsfile))
120
logging.error('Credentials not found. Aborting!')
123
if not run(credentials, args.stack, args.release, args.project, args.archs):
124
logging.error('Failed to run job. Aborting!')
127
if __name__ == "__main__":