Example #1
0
 def main(self, args=None):
     """Handles execution through command line interface"""
     # Load all of the available commands
     self.set_args(args)
     self.load_commands()
     parser = self.create_parser()
     if not args:
         args = sys.argv[1:]
     cli_args = parser.parse_args(args=args)
     self.handle_global_options(cli_args)
     command = cli_args.command
     # Run the command
     exit_code = 0
     try:
         exit_code = self.run_command(command, cli_args)
     except CommandDoesNotExist:
         exit_code = EXIT_FAIL
         logger.debug('Unknown command "%s"' % command)
         parser.error('"%s" is not a vstrap command. (use "vstrap help" '
                 'to see a list of commands)' % command)
     finally:
         self.close_context()
     if exit_code == EXIT_OK:
         # TODO actually delete the correct log file
         if os.path.exists(constants.LOG_FILE): 
             os.remove(constants.LOG_FILE)
     return exit_code
Example #2
0
 def main(self, args=None):
     """Handles execution through command line interface"""
     # Load all of the available commands
     self.set_args(args)
     self.load_commands()
     parser = self.create_parser()
     if not args:
         args = sys.argv[1:]
     cli_args = parser.parse_args(args=args)
     self.handle_global_options(cli_args)
     command = cli_args.command
     # Run the command
     try:
         exit_code = self.run_command(command, cli_args)
     except CommandDoesNotExist:
         exit_code = EXIT_FAIL
         logger.debug('Unknown command "%s"' % command)
         parser.error('"%s" is not a vstrap command. (use "vstrap help" '
                      'to see a list of commands)' % command)
     finally:
         self.close_context()
     if exit_code == EXIT_OK:
         # TODO actually delete the correct log file
         if os.path.exists(constants.LOG_FILE):
             os.remove(constants.LOG_FILE)
     return exit_code
Example #3
0
 def main(self, args=None):
     """Handles execution through command line interface"""
     # This is so you can see virtstrap starting in the log file
     logger.debug('------------------- vstrap starting -------------------')
     # Load all of the available commands
     if not args:
         args = sys.argv[1:]
     self.set_args(args)
     self.load_commands()
     parser = self.create_parser()
     # Get the arguments minus the command name
     raw_command_args = args[1:]
     # Parse the known args
     cli_args, remaining = parser.parse_known_args(args=args)
     self.handle_global_options(cli_args)
     command = cli_args.command
     # Run the command
     exit_code = 0
     try:
         exit_code = self.run_command(command,
                                      cli_args,
                                      project=self.project,
                                      raw_args=raw_command_args)
     except CommandDoesNotExist:
         exit_code = EXIT_FAIL
         logger.debug('Unknown command "%s"' % command)
         parser.error('"%s" is not a vstrap command. (use "vstrap help" '
                      'to see a list of commands)' % command)
     except SystemExit, e:
         if e.code == 0:
             exit_code = EXIT_OK
         else:
             logger.error(
                 "virtstrap did not finish it's"
                 " task correctly check the log. for more information")
Example #4
0
 def main(self, args=None):
     """Handles execution through command line interface"""
     # This is so you can see virtstrap starting in the log file
     logger.debug('------------------- vstrap starting -------------------')
     # Load all of the available commands
     if not args:
         args = sys.argv[1:]
     self.set_args(args)
     self.load_commands()
     parser = self.create_parser()
     # Get the arguments minus the command name
     raw_command_args = args[1:] 
     # Parse the known args
     cli_args, remaining = parser.parse_known_args(args=args)
     self.handle_global_options(cli_args)
     command = cli_args.command
     # Run the command
     exit_code = 0
     try:
         exit_code = self.run_command(command, cli_args, 
                 project=self.project, raw_args=raw_command_args)
     except CommandDoesNotExist:
         exit_code = EXIT_FAIL
         logger.debug('Unknown command "%s"' % command)
         parser.error('"%s" is not a vstrap command. (use "vstrap help" '
                 'to see a list of commands)' % command)
     except SystemExit, e:
         if e.code == 0:
             exit_code = EXIT_OK
         else:
             logger.error("virtstrap did not finish it's"
                     " task correctly check the log. for more information")
Example #5
0
def call_project_command(project, command_name, command_args, output_errors=False,
        **subprocess_options):
    virtstrap_bin = constants.PROJECT_VIRTSTRAP_BIN_NAME
    args = [command_name]
    args.extend(command_args)
    try:
        return_data = project.call_bin(virtstrap_bin, args,
                **subprocess_options)
    except OSError:
        logger.debug('Error executing virtstrap local command')
        command_bin_path = project.bin_path(virtstrap_bin)
        command_list = [command_bin_path]
        command_list.extend(args)
        command_string = ' '.join(command_list)
        logger.debug('Command called: %s' % command_string)
        sys.exit(2)
Example #6
0
def call_project_command(project,
                         command_name,
                         command_args,
                         output_errors=False,
                         **subprocess_options):
    virtstrap_bin = constants.PROJECT_VIRTSTRAP_BIN_NAME
    args = [command_name]
    args.extend(command_args)
    try:
        return_data = project.call_bin(virtstrap_bin, args,
                                       **subprocess_options)
    except OSError:
        logger.debug('Error executing virtstrap local command')
        command_bin_path = project.bin_path(virtstrap_bin)
        command_list = [command_bin_path]
        command_list.extend(args)
        command_string = ' '.join(command_list)
        logger.debug('Command called: %s' % command_string)
        sys.exit(2)
Example #7
0
 def main(self, args=None):
     """Handles execution through command line interface"""
     # Load all of the available commands
     self.load_commands()
     parser = self.create_parser()
     if not args:
         args = sys.argv[1:]
     cli_args = parser.parse_args(args=args)
     config = self.handle_global_options(cli_args)
     command = cli_args.command
     # Run the command
     try:
         exit_code = self.run_command(command, config, cli_args)
     except CommandDoesNotExist:
         exit_code = EXIT_FAIL
         logger.debug('Unknown command "%s"' % command)
         parser.error('"%s" is not a vstrap command. (use "vstrap help" '
                      'to see a list of commands)' % command)
     return exit_code
Example #8
0
 def main(self, args=None):
     """Handles execution through command line interface"""
     # Load all of the available commands
     self.load_commands()
     parser = self.create_parser()
     if not args:
         args = sys.argv[1:]
     cli_args = parser.parse_args(args=args)
     config = self.handle_global_options(cli_args)
     command = cli_args.command
     # Run the command
     try:
         exit_code = self.run_command(command, config, cli_args)
     except CommandDoesNotExist:
         exit_code = EXIT_FAIL
         logger.debug('Unknown command "%s"' % command)
         parser.error('"%s" is not a vstrap command. (use "vstrap help" '
                 'to see a list of commands)' % command)
     return exit_code
 def collect(self):
     project = self._project
     collected_commands = []
     if project:
         virtstrap_bin = constants.PROJECT_VIRTSTRAP_BIN_NAME
         try:
             json_data = project.call_bin(virtstrap_bin,
                                          ['commands', '--as-json'],
                                          collect_stdout=True)
         except OSError:
             logger.debug('Found a possible project directory at %s'
                          ' but it was not configured correctly.' %
                          project.path())
             return collected_commands
         if json_data:
             commands_json = json.loads(json_data)
             command_dicts = commands_json['commands']
             for command_dict in command_dicts:
                 command = self.make_local_project_command(
                     command_dict['name'], command_dict['description'])
                 collected_commands.append(command)
     return collected_commands
 def collect(self):
     project = self._project
     collected_commands = []
     if project:
         virtstrap_bin = constants.PROJECT_VIRTSTRAP_BIN_NAME
         try:
             json_data = project.call_bin(virtstrap_bin, ['commands',
                 '--as-json'], collect_stdout=True)
         except OSError:
             logger.debug('Found a possible project directory at %s'
                     ' but it was not configured correctly.' % 
                     project.path())
             return collected_commands
         if json_data:
             commands_json = json.loads(json_data)
             command_dicts = commands_json['commands']
             for command_dict in command_dicts:
                 command = self.make_local_project_command(
                         command_dict['name'], 
                         command_dict['description'])
                 collected_commands.append(command)
     return collected_commands
Example #11
0
 def run_command(self, name, cli_args, **kwargs):
     """Load command from virtstrap.commands"""
     logger.debug('Command "%s" chosen' % name)
     return self.registry.run(name, cli_args, **kwargs)
Example #12
0
 def run_command(self, name, config, cli_args):
     """Load command from virtstrap.commands"""
     logger.debug('Command "%s" chosen' % name)
     options = cli_args.__dict__
     return registry.run(name, config, **options)
Example #13
0
 def run_command(self, name, config, cli_args):
     """Load command from virtstrap.commands"""
     logger.debug('Command "%s" chosen' % name)
     options = cli_args.__dict__
     return registry.run(name, config, **options)
Example #14
0
 def run_command(self, name, cli_args, **kwargs):
     """Load command from virtstrap.commands"""
     logger.debug('Command "%s" chosen' % name)
     return self.registry.run(name, cli_args, **kwargs)