~dooferlad/+junk/python-ci-config

« back to all changes in this revision

Viewing changes to commands/add.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
import defaults
 
24
 
 
25
"""
 
26
Defines the lci add command
 
27
"""
 
28
 
 
29
class Command(BaseCommandNeedsAuth):
 
30
    def run(self, args):
 
31
        parameters = self._args_to_params(args)
 
32
 
 
33
        print "Add task with params %s" % parameters
 
34
 
 
35
        r = self.post("CIJobLoop", parameters)
 
36
 
 
37
        # TODO: server side needs to check that the job name is unique at some
 
38
        # point.
 
39
        if r.status_code != requests.codes.ok:
 
40
            raise CommandFailed(self.name, parameters, r)
 
41
 
 
42
    def _args_to_params(self, parameters):
 
43
        # lci add <VCS URL> [--file-name file_name] [--class-name class_name]
 
44
        # [--run]
 
45
        parser = argparse.ArgumentParser(description='Linaro CI: Add task.',
 
46
                                         prog=self.program_name)
 
47
        parser.add_argument('vcs_url', type=str,
 
48
            help='URL to check out test configuration from.')
 
49
        parser.add_argument('--file-name', type=str,
 
50
            default=defaults.file_name,
 
51
            help='Name of the configuration file.'
 
52
                 ' Default is %s' % defaults.file_name)
 
53
        parser.add_argument('--class-name', type=str,
 
54
            default=defaults.class_name,
 
55
            help='Name of the job class in the configuration file. '
 
56
                 'Default is %s' % defaults.class_name)
 
57
        parser.add_argument('--run', action='store_true',
 
58
            help='Enqueue job immediately')
 
59
 
 
60
        args = parser.parse_args(parameters)
 
61
        return vars(args)