summaryrefslogtreecommitdiffstats
path: root/cobbler/cobbler.py
blob: 627e398f90a65e9cdbc5a0586f59d9f83adb7cec (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
58
59
60
61
62
63
64
65
"""
Command line interface for cobbler, a network provisioning configuration
library.  Consult 'man cobbler' for general info.  This class serves
as a good reference on how to drive the API (api.py).

Copyright 2006, Red Hat, Inc
Michael DeHaan <mdehaan@redhat.com>

This software may be freely redistributed under the terms of the GNU
general public license.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""

import sys
import api
import os
import os.path
import traceback
import optparse
import commands
import cexceptions
from cexceptions import *

from utils import _
I18N_DOMAIN = "cobbler"

####################################################

class BootCLI:

    def __init__(self):
        self.api = api.BootAPI()
        self.loader = commands.FunctionLoader()
        climods = self.api.get_modules_in_category("cli")
        for mod in climods:
            for fn in mod.cli_functions(self.api):
                self.loader.add_func(fn)
      
    def run(self,args):
        return self.loader.run(args)

####################################################

def main():
    """
    CLI entry point
    """
    exitcode = 0
    try:
        return BootCLI().run(sys.argv)
    except Exception, exc:
        if isinstance(exc, cexceptions.CobblerException) or \
           isinstance(exc, cexceptions.CX) or \
           str(type(exc)).find("CX") != -1 or \
           str(type(exc)).find("CobblerException") != -1:
            print str(exc)[1:-1]  # remove framing air quotes
        else:
            traceback.print_exc()
        return 1

if __name__ == "__main__":
    sys.exit(main())