def main(argv=None):
    """Command line options."""
   
    program_name = __programm_name__
    program_version = "v%s" % __version__
    program_descrption = __programm_description__

    try:
        # Setup argument parser
        parser = ArgumentParser(prog=program_name, description=program_descrption)
        parser.add_argument("-v", "--verbose", dest="verbose", action="count", help="run in verbose mode (-vvv for more, -vvvv to enable connection debugging)")
        parser.add_argument("-s", "--sudo", action="store_true", help="run supervisorctl actions with sudo (nopasswd))")
        parser.add_argument("-V", "--version", action="version", version=program_version)
        parser.add_argument("host-pattern", help="A host-pattern usually refers to a group of hosts. For more details, see Ansible documentation about Patterns.")
        #parser.add_argument("supervisorctl-action", help="A supervisorctl action (and optional argument). For more details, see Supervisor documentation about the available supervisorctl actions.")
        
        subparsers = parser.add_subparsers(help="One of the available supervisorctl actions.", dest="supervisorctl-action")
        subparsers.add_parser("status", help="Get status info of all processes.")
        subparsers.add_parser("reread", help="Reread the configuration files of supervisord")
        subparsers.add_parser("reload", help="Restart remote supervisord")
        subparsers.add_parser("update", help="Reload the configuration files of supervisord and add/remove processes as necessary")
        start_subparser = subparsers.add_parser("start", help="Start a process by name")
        start_subparser.add_argument("process-name", help="Name of the process")
        stop_subparser = subparsers.add_parser("stop", help="Stop a process by name")
        stop_subparser.add_argument("process-name", help="Name of the process")
        restart_subparser = subparsers.add_parser("restart", help="Restart a process by name")
        restart_subparser.add_argument("process-name", help="Name of the process")
        remove_subparser = subparsers.add_parser("remove", help="Remove a process by name")
        remove_subparser.add_argument("process-name", help="Name of the process")
        
        # Process arguments
        args = parser.parse_args(argv)
        verbose = args.verbose
        host_pattern = getattr(args, "host-pattern")
        supervisorctl_action = getattr(args, "supervisorctl-action")        
        
        sudo = args.sudo
        ansible_executable = "ansible"
        supervisorctl_executable = "supervisorctl"
        ansible_action_option = "-a"
        
        if sudo:
            supervisorctl_command = "sudo " + supervisorctl_executable + " " + supervisorctl_action
        else:
            supervisorctl_command = supervisorctl_executable + " " + supervisorctl_action
          
        if supervisorctl_action not in ['status', 'reread', 'update', 'reload']:
            supervisorctl_argument = getattr(args, "process-name")
            supervisorctl_command = supervisorctl_command + ' ' + supervisorctl_argument
            
        if verbose >0:
            verbose_level = "-"+ "v"*verbose
            print("Verbose mode on: " + verbose_level)
            print "Parsed arguments:"
            print args   
            retcode = call([ansible_executable, host_pattern, verbose_level, ansible_action_option, supervisorctl_command,])
        else:
            retcode = call([ansible_executable, host_pattern, ansible_action_option, supervisorctl_command])
        
        return retcode
    except KeyboardInterrupt:
        ### handle keyboard interrupt ###
        return 0
def main ( argv = None ) : program_name = __programm_name__ program_version = "v%s" % __version__ program_descrption = __programm_description__ try : parser = ArgumentParser ( prog = program_name , description = program_descrption ) parser . add_argument ( "-v" , "--verbose" , dest = "verbose" , action = "count" , help = "run in verbose mode (-vvv for more, -vvvv to enable connection debugging)" ) parser . add_argument ( "-s" , "--sudo" , action = "store_true" , help = "run supervisorctl actions with sudo (nopasswd))" ) parser . add_argument ( "-V" , "--version" , action = "version" , version = program_version ) parser . add_argument ( "host-pattern" , help = "A host-pattern usually refers to a group of hosts. For more details, see Ansible documentation about Patterns." ) subparsers = parser . add_subparsers ( help = "One of the available supervisorctl actions." , dest = "supervisorctl-action" ) subparsers . add_parser ( "status" , help = "Get status info of all processes." ) subparsers . add_parser ( "reread" , help = "Reread the configuration files of supervisord" ) subparsers . add_parser ( "reload" , help = "Restart remote supervisord" ) subparsers . add_parser ( "update" , help = "Reload the configuration files of supervisord and add/remove processes as necessary" ) start_subparser = subparsers . add_parser ( "start" , help = "Start a process by name" ) start_subparser . add_argument ( "process-name" , help = "Name of the process" ) stop_subparser = subparsers . add_parser ( "stop" , help = "Stop a process by name" ) stop_subparser . add_argument ( "process-name" , help = "Name of the process" ) restart_subparser = subparsers . add_parser ( "restart" , help = "Restart a process by name" ) restart_subparser . add_argument ( "process-name" , help = "Name of the process" ) remove_subparser = subparsers . add_parser ( "remove" , help = "Remove a process by name" ) remove_subparser . add_argument ( "process-name" , help = "Name of the process" ) args = parser . parse_args ( argv ) verbose = args . verbose host_pattern = getattr ( args , "host-pattern" ) supervisorctl_action = getattr ( args , "supervisorctl-action" ) sudo = args . sudo ansible_executable = "ansible" supervisorctl_executable = "supervisorctl" ansible_action_option = "-a" if sudo : supervisorctl_command = "sudo " + supervisorctl_executable + " " + supervisorctl_action else : supervisorctl_command = supervisorctl_executable + " " + supervisorctl_action if supervisorctl_action not in [ 'status' , 'reread' , 'update' , 'reload' ] : supervisorctl_argument = getattr ( args , "process-name" ) supervisorctl_command = supervisorctl_command + ' ' + supervisorctl_argument if verbose > 0 : verbose_level = "-" + "v" * verbose print ( "Verbose mode on: " + verbose_level ) print "Parsed arguments:" print args retcode = call ( [ ansible_executable , host_pattern , verbose_level , ansible_action_option , supervisorctl_command , ] ) else : retcode = call ( [ ansible_executable , host_pattern , ansible_action_option , supervisorctl_command ] ) return retcode except KeyboardInterrupt : return 0
Command line options.