~milo/linaro-ci-dashboard/xml-to-dict

« back to all changes in this revision

Viewing changes to dashboard/frontend/management/commands/stopjenkins.py

  • Committer: Deepti B. Kalakeri
  • Date: 2012-07-17 15:56:44 UTC
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: deepti.kalakeri@linaro.org-20120717155644-tj3ecfzor0t7ldhz
Adding runjenkins and stop jenkins command changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2012 Linaro
 
2
#
 
3
# This file is part of linaro-ci-dashboard.
 
4
#
 
5
# linaro-ci-dashboard is free software: you can redistribute it and/or modify
 
6
# it under the terms of the GNU Affero General Public License as published by
 
7
# the Free Software Foundation, either version 3 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# linaro-ci-dashboard is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU Affero General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU Affero General Public License
 
16
# along with linaro-ci-dashboard.  If not, see <http://www.gnu.org/licenses/>.
 
17
# Django settings for dashboard project.
 
18
 
 
19
import sys
 
20
from subprocess import check_call, CalledProcessError
 
21
from django.core.management.base import BaseCommand, CommandError
 
22
 
 
23
class Command(BaseCommand):
 
24
    args = 'pid pid ...'
 
25
    help = 'Specify the jenkins pid to stop'
 
26
 
 
27
    def handle(self, *args, **options):
 
28
       for pid in args:
 
29
           self.terminate(pid)
 
30
           self.stdout.write('Successfully terminated jenkins with pid %s\n'\
 
31
                             % pid)
 
32
         
 
33
    def terminate(self, pid):
 
34
        try:
 
35
            cmd = 'kill -9 %s' % pid
 
36
            check_call(cmd, shell=True)
 
37
        except CalledProcessError:
 
38
            raise CalledProcessError(1, cmd, "Command Error")
 
39
            sys.exit(1)