~dooferlad/+junk/python-ci-config

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
# Copyright (C) 2010, 2011 Linaro
#
# Author: James Tunnicliffe <james.tunnicliffe@linaro.org>
#
# This file is part of Linaro CI CLI.
#
# Linaro CI CLI is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Linaro CI CLI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Linaro Image Tools.  If not, see <http://www.gnu.org/licenses/>.

import requests
from base_command import BaseCommandNeedsAuth, CommandFailed
import argparse

"""
Defines the lci run command
"""

class Command(BaseCommandNeedsAuth):
    def run(self, args):
        parameters = self._args_to_params(args)

        print "Run task with params %s" % parameters

        r = self.get("run", parameters)

        if r.status_code != requests.codes.ok:
            raise CommandFailed(self.name, parameters, r)

    def _args_to_params(self, parameters):
        # lci run <job name>
        parser = argparse.ArgumentParser(description='Linaro CI: Run task.',
                                         prog=self.program_name)
        parser.add_argument('job_name', type=str,
            help='Job name specified in configuration file.')

        args = parser.parse_args(parameters)
        return vars(args)