Exemple #1
0
    def __init__(self):
        CoreEvent.__init__(self)

        # Parser which reads the command line
        self._mop = None
        # Store the options parsed
        self._options = None
        # Store the configuration parsed
        self._conf = None
        # Store the arguments parsed
        self._args = None
        # Store executed actions
        self.actions = []
        # Displayer
        self._console = ConsoleDisplay()
        # Store interactive mode
        self.interactive = Terminal.isinteractive()

        self._logger = ConfigParser.install_logger()

        call_back_self().attach(self)
        self.inter_thread = InteractiveThread(self._console)
Exemple #2
0
    def execute(self, command_line):
        '''
        Ask for the manager to execute orders given by the command line.
        '''
        self._mop = McOptionParser()
        self._mop.configure_mop()
        retcode = RC_OK

        try:
            (self._options, self._args) = self._mop.parse_args(command_line)

            self._conf = ConfigParser(self._options)

            # Configure ActionManager
            action_manager_self().default_fanout = self._conf['fanout']
            action_manager_self().dryrun = self._conf['dryrun']

            manager = service_manager_self()
            # Case 0: build the graph
            if self._conf.get('graph', False):
                manager.load_config(self._conf['config_dir'])
                # Deps graph generation
                self._console.output(manager.output_graph(self._args,
                                     self._conf.get('excluded_svc', [])))
            # Case 1 : call services referenced in the manager with
            # the required action
            elif self._args:
                # Compute all services with the required action
                services = self._args[:-1]
                action = self._args[-1]

                # Create a thread in interactive mode to manage
                # current running status
                if self.interactive:
                    self.inter_thread.start()

                # Run tasks
                manager.call_services(services, action, conf=self._conf)
                retcode = self.retcode()

                if self._conf.get('summary', False):
                    self._console.print_summary(self.actions)
            # Case 2 : Check configuration
            elif self._conf.get('config_dir', False):
                self._console.output("No actions specified, "
                                     "checking configuration...")
                manager.load_config(self._conf['config_dir'])
                self._console.output("%s seems good" % self._conf['config_dir'])
            # Case 3: Nothing to do so just print MilkCheck help
            else:
                self._mop.print_help()
        except (ServiceNotFoundError, 
                ActionNotFoundError,
                InvalidVariableError,
                UndefinedVariableError,
                VariableAlreadyExistError,
                DependencyAlreadyReferenced,
                UnknownDependencyError,
                IllegalDependencyTypeError,
                ConfigParserError,
                ConfigurationError,
                ScannerError), exc:
            self._logger.error(str(exc))
            retcode = RC_EXCEPTION
Exemple #3
0
class CommandLine(CoreEvent):
    '''
    This class models the Command Line which is a CoreEvent. From
    this class you can get back events generated by the engine and send order
    to the ServiceManager.
    '''

    def __init__(self):
        CoreEvent.__init__(self)

        # Parser which reads the command line
        self._mop = None
        # Store the options parsed
        self._options = None
        # Store the configuration parsed
        self._conf = None
        # Store the arguments parsed
        self._args = None
        # Store executed actions
        self.actions = []
        # Displayer
        self._console = ConsoleDisplay()
        # Store interactive mode
        self.interactive = Terminal.isinteractive()

        self._logger = ConfigParser.install_logger()

        call_back_self().attach(self)
        self.inter_thread = InteractiveThread(self._console)

    def execute(self, command_line):
        '''
        Ask for the manager to execute orders given by the command line.
        '''
        self._mop = McOptionParser()
        self._mop.configure_mop()
        retcode = RC_OK

        try:
            (self._options, self._args) = self._mop.parse_args(command_line)

            self._conf = ConfigParser(self._options)

            # Configure ActionManager
            action_manager_self().default_fanout = self._conf['fanout']
            action_manager_self().dryrun = self._conf['dryrun']

            manager = service_manager_self()
            # Case 0: build the graph
            if self._conf.get('graph', False):
                manager.load_config(self._conf['config_dir'])
                # Deps graph generation
                self._console.output(manager.output_graph(self._args,
                                     self._conf.get('excluded_svc', [])))
            # Case 1 : call services referenced in the manager with
            # the required action
            elif self._args:
                # Compute all services with the required action
                services = self._args[:-1]
                action = self._args[-1]

                # Create a thread in interactive mode to manage
                # current running status
                if self.interactive:
                    self.inter_thread.start()

                # Run tasks
                manager.call_services(services, action, conf=self._conf)
                retcode = self.retcode()

                if self._conf.get('summary', False):
                    self._console.print_summary(self.actions)
            # Case 2 : Check configuration
            elif self._conf.get('config_dir', False):
                self._console.output("No actions specified, "
                                     "checking configuration...")
                manager.load_config(self._conf['config_dir'])
                self._console.output("%s seems good" % self._conf['config_dir'])
            # Case 3: Nothing to do so just print MilkCheck help
            else:
                self._mop.print_help()
        except (ServiceNotFoundError, 
                ActionNotFoundError,
                InvalidVariableError,
                UndefinedVariableError,
                VariableAlreadyExistError,
                DependencyAlreadyReferenced,
                UnknownDependencyError,
                IllegalDependencyTypeError,
                ConfigParserError,
                ConfigurationError,
                ScannerError), exc:
            self._logger.error(str(exc))
            retcode = RC_EXCEPTION
        except InvalidOptionError, exc:
            self._logger.critical('Invalid options: %s\n' % exc)
            self._mop.print_help()
            retcode = RC_EXCEPTION