~dooferlad/+junk/python-ci-config

« back to all changes in this revision

Viewing changes to commands/run.py

  • Committer: James Tunnicliffe
  • Date: 2013-02-07 10:09:31 UTC
  • Revision ID: james.tunnicliffe@linaro.org-20130207100931-spap7i8w109qlrwo
Added more commands.
Slight restructuring for better code re-use.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010, 2011 Linaro
 
2
#
 
3
# Author: James Tunnicliffe <james.tunnicliffe@linaro.org>
 
4
#
 
5
# This file is part of Linaro CI CLI.
 
6
#
 
7
# Linaro CI CLI is free software: you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation, either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# Linaro CI CLI is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with Linaro Image Tools.  If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
import requests
 
21
from base_command import BaseCommandNeedsAuth, CommandFailed
 
22
import argparse
 
23
 
 
24
"""
 
25
Defines the lci run command
 
26
"""
 
27
 
 
28
class Command(BaseCommandNeedsAuth):
 
29
    def run(self, args):
 
30
        parameters = self._args_to_params(args)
 
31
 
 
32
        print "Run task with params %s" % parameters
 
33
 
 
34
        r = self.get("run", parameters)
 
35
 
 
36
        if r.status_code != requests.codes.ok:
 
37
            raise CommandFailed(self.name, parameters, r)
 
38
 
 
39
    def _args_to_params(self, parameters):
 
40
        # lci run <job name>
 
41
        parser = argparse.ArgumentParser(description='Linaro CI: Run task.',
 
42
                                         prog=self.program_name)
 
43
        parser.add_argument('job_name', type=str,
 
44
            help='Job name specified in configuration file.')
 
45
 
 
46
        args = parser.parse_args(parameters)
 
47
        return vars(args)