summaryrefslogtreecommitdiff
path: root/lorry-controller
blob: 1b2fb74f62e3db1a0f3fe6faa0a9f6e7452cf66d (plain)
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
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
#
# Copyright (C) 2012  Codethink Limited


import cliapp
import logging
import os

defaults = {
    'work-area': '/home/lorry/controller-area'
}

from lorrycontroller.confparser import LorryControllerConfig

class LorryController(cliapp.Application):

    def add_settings(self):
        self.settings.string(['work-area'],
                             'path to the area for  the controller to work in',
                             metavar='PATH',
                             default=defaults['work-area'])

    def process_args(self, args):
        logging.info("Starting to control lorry")
        try:
            os.chdir(self.settings['work-area'])
        except OSError, e:
            logging.error("Unable to chdir() to %s" % 
                          self.settings['work-area'])
            raise SystemExit(2)
        if not os.path.isdir("git"):
            logging.error("Unable to find git checkout")
            raise SystemExit(3)
        if not os.path.isdir("work"):
            os.mkdir("work")

        logging.info("Updating configuration checkout")
        self.rungit(['remote', 'update', 'origin'])
        self.rungit(['reset', '--hard', 'origin/master'])
        self.rungit(['clean', '-fdx'])

        if not os.path.exists('git/lorry-controller.conf'):
            logging.error("Unable to find lorry-controller.conf in git")
            raise SystemExit(4)

        conf = LorryControllerConfig(self.settings,
                                     'git/lorry-controller.conf')
        

    def rungit(self, args):
        self.runcmd(['git']+args, cwd=os.path.join(self.settings['work-area'],
                                                   'git'))


if __name__ == '__main__':
    LorryController(version='1').run()