direct-io.hg

changeset 8028:d1e1d6493d1d

Programmatically generate the xm help strings from the snippets, rather than
splicing the strings together manually.

Replace the word "bogus" with the command in question where it appears, as this
shows up in the Usage statements.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Thu Nov 24 19:56:38 2005 +0000 (2005-11-24)
parents d2b957902c6b
children 78b5e590be34
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Thu Nov 24 19:53:09 2005 +0000
     1.2 +++ b/tools/python/xen/xm/main.py	Thu Nov 24 19:56:38 2005 +0000
     1.3 @@ -24,7 +24,6 @@
     1.4  import os
     1.5  import os.path
     1.6  import sys
     1.7 -import commands
     1.8  import re
     1.9  from getopt import getopt
    1.10  import socket
    1.11 @@ -71,7 +70,7 @@ vcpu_list_help = "vcpu-list <DomId>     
    1.12  vcpu_pin_help = "vcpu-pin <DomId> <VCPU> <CPUs>   Set which cpus a VCPU can use" 
    1.13  dmesg_help =   "dmesg [--clear]                  Read or clear Xen's message buffer"
    1.14  info_help =    "info                             Get information about the xen host"
    1.15 -log_help = "log      Print the xend log"
    1.16 +log_help =     "log                              Print the xend log"
    1.17  sched_bvt_help = """sched-bvt <Parameters>           Set Borrowed Virtual Time scheduler
    1.18                                      parameters"""
    1.19  sched_bvt_ctxallow_help = """sched-bvt-ctxallow <Allow>       Set the BVT scheduler context switch
    1.20 @@ -96,25 +95,87 @@ vnet_create_help = "vnet-create <config>
    1.21  vnet_delete_help = "vnet-delete <vnetid>             delete a vnet"
    1.22  
    1.23  
    1.24 +short_command_list = [
    1.25 +    "console",
    1.26 +    "create",
    1.27 +    "destroy",
    1.28 +    "help",
    1.29 +    "list",
    1.30 +    "mem-max",
    1.31 +    "mem-set",
    1.32 +    "migrate",
    1.33 +    "pause",
    1.34 +    "reboot",
    1.35 +    "restore",
    1.36 +    "save",
    1.37 +    "shutdown",
    1.38 +    "top",
    1.39 +    "unpause",
    1.40 +    ]
    1.41 +
    1.42 +domain_commands = [
    1.43 +    "console",
    1.44 +    "create",
    1.45 +    "destroy",
    1.46 +    "domid",
    1.47 +    "domname",
    1.48 +    "list",
    1.49 +    "mem-max",
    1.50 +    "mem-set",
    1.51 +    "migrate",
    1.52 +    "pause",
    1.53 +    "reboot",
    1.54 +    "restore",
    1.55 +    "save",
    1.56 +    "shutdown",
    1.57 +    "sysrq",
    1.58 +    "top",
    1.59 +    "unpause",
    1.60 +    "set-vcpus",
    1.61 +    "vcpu-pin",
    1.62 +    ]
    1.63 +
    1.64 +host_commands = [
    1.65 +    "dmesg",
    1.66 +    "info",
    1.67 +    "log",
    1.68 +    "top",
    1.69 +    ]
    1.70 +
    1.71 +scheduler_commands = [
    1.72 +    "sched-bvt",
    1.73 +    "sched-bvt-ctxallow",
    1.74 +    "sched-sedf",
    1.75 +    ]
    1.76 +
    1.77 +device_commands = [
    1.78 +    "block-attach",
    1.79 +    "block-detach",
    1.80 +    "block-list",
    1.81 +    "network-attach",
    1.82 +    "network-detach",
    1.83 +    "network-list",
    1.84 +    ]
    1.85 +
    1.86 +vnet_commands = [
    1.87 +    "vnet-list",
    1.88 +    "vnet-create",
    1.89 +    "vnet-delete",
    1.90 +    ]
    1.91 +
    1.92 +all_commands = (domain_commands + host_commands + scheduler_commands +
    1.93 +                device_commands + vnet_commands)
    1.94 +
    1.95 +
    1.96 +def commandToHelp(cmd):
    1.97 +    return eval(cmd.replace("-", "_") + "_help")
    1.98 +
    1.99 +
   1.100  shorthelp = """Usage: xm <subcommand> [args]
   1.101      Control, list, and manipulate Xen guest instances
   1.102  
   1.103 -xm common subcommands:"""  + help_spacer \
   1.104 -+ console_help + help_spacer \
   1.105 -+ create_help + help_spacer \
   1.106 -+ destroy_help + help_spacer \
   1.107 -+ help_help    + help_spacer \
   1.108 -+ list_help    + help_spacer \
   1.109 -+ mem_max_help + help_spacer \
   1.110 -+ mem_set_help + help_spacer \
   1.111 -+ migrate_help + help_spacer \
   1.112 -+ pause_help   + help_spacer \
   1.113 -+ reboot_help  + help_spacer \
   1.114 -+ restore_help + help_spacer \
   1.115 -+ save_help    + help_spacer \
   1.116 -+ shutdown_help + help_spacer \
   1.117 -+ top_help     + help_spacer \
   1.118 -+ unpause_help + """
   1.119 +xm common subcommands:
   1.120 +   """  + help_spacer.join(map(commandToHelp, short_command_list))  + """
   1.121  
   1.122  <DomName> can be substituted for <DomId> in xm subcommands.
   1.123  
   1.124 @@ -127,50 +188,20 @@ longhelp = """Usage: xm <subcommand> [ar
   1.125  
   1.126  xm full list of subcommands:
   1.127  
   1.128 -  Domain Commands: """ + help_spacer \
   1.129 -+ console_help + help_spacer \
   1.130 -+ create_help + help_spacer \
   1.131 -+ destroy_help + help_spacer \
   1.132 -+ domid_help   + help_spacer \
   1.133 -+ domname_help   + help_spacer \
   1.134 -+ list_help    + help_spacer \
   1.135 -+ mem_max_help + help_spacer \
   1.136 -+ mem_set_help + help_spacer \
   1.137 -+ migrate_help + help_spacer \
   1.138 -+ pause_help   + help_spacer \
   1.139 -+ reboot_help  + help_spacer \
   1.140 -+ restore_help + help_spacer \
   1.141 -+ save_help    + help_spacer \
   1.142 -+ shutdown_help + help_spacer \
   1.143 -+ sysrq_help + help_spacer \
   1.144 -+ top_help     + help_spacer \
   1.145 -+ unpause_help + help_spacer \
   1.146 -+ set_vcpus_help + help_spacer \
   1.147 -+ vcpu_pin_help + """
   1.148 +  Domain Commands:
   1.149 +   """ + help_spacer.join(map(commandToHelp,  domain_commands)) + """
   1.150 +
   1.151 +  Xen Host Commands:
   1.152 +   """ + help_spacer.join(map(commandToHelp,  host_commands)) + """
   1.153  
   1.154 -   Xen Host Commands: """ + help_spacer \
   1.155 -+ dmesg_help + help_spacer \
   1.156 -+ info_help + help_spacer \
   1.157 -+ log_help  + help_spacer \
   1.158 -+ top_help  + """
   1.159 -
   1.160 -  Scheduler Commands: """ + help_spacer \
   1.161 -+ sched_bvt_help + help_spacer \
   1.162 -+ sched_bvt_ctxallow_help + help_spacer \
   1.163 -+ sched_sedf_help + """
   1.164 +  Scheduler Commands:
   1.165 +   """ + help_spacer.join(map(commandToHelp,  scheduler_commands)) + """
   1.166  
   1.167 -  Virtual Device Commands:"""  + help_spacer \
   1.168 -+ block_attach_help + help_spacer \
   1.169 -+ block_detach_help + help_spacer \
   1.170 -+ block_list_help + help_spacer \
   1.171 -+ network_attach_help + help_spacer \
   1.172 -+ network_detach_help + help_spacer \
   1.173 -+ network_list_help + """
   1.174 +  Virtual Device Commands:
   1.175 +   """  + help_spacer.join(map(commandToHelp, device_commands)) + """
   1.176  
   1.177 -  Vnet commands: """ + help_spacer \
   1.178 -+ vnet_list_help + help_spacer \
   1.179 -+ vnet_create_help + help_spacer \
   1.180 -+ vnet_delete_help + """
   1.181 +  Vnet commands:
   1.182 +   """ + help_spacer.join(map(commandToHelp,  vnet_commands)) + """
   1.183  
   1.184  <DomName> can be substituted for <DomId> in xm subcommands.
   1.185  
   1.186 @@ -180,48 +211,14 @@ For more help on xm create, see the xmdo
   1.187  
   1.188  # array for xm help <command>
   1.189  help = {
   1.190 -    "--long": longhelp,
   1.191 -    "console": console_help,
   1.192 -# create is handled specially
   1.193 -    "destroy": destroy_help,
   1.194 -    "domid ": domid_help,
   1.195 -    "domname": domname_help,
   1.196 -    "list": list_help,
   1.197 -    "mem-max": mem_max_help,
   1.198 -    "mem-set": mem_set_help,
   1.199 -    "migrate": migrate_help,
   1.200 -    "pause": pause_help,
   1.201 -    "reboot": reboot_help,
   1.202 -    "restore": restore_help,
   1.203 -    "save":  save_help,
   1.204 -    "shutdown": shutdown_help,
   1.205 -    "sysrq": sysrq_help,
   1.206 -    "unpause": unpause_help,
   1.207 -    "set-vcpus": set_vcpus_help,
   1.208 -    "vcpu-list": vcpu_list_help,
   1.209 -    "vcpu-pin": vcpu_pin_help,
   1.210 -#  Xen Host Commands:
   1.211 -    "dmesg": dmesg_help,
   1.212 -    "info":  info_help,
   1.213 -    "log":   log_help,
   1.214 -    "top":  top_help,
   1.215 -#  Scheduler Commands:
   1.216 -    "sched-bvt": sched_bvt_help,
   1.217 -    "sched-bvt-ctxallow": sched_bvt_ctxallow_help,
   1.218 -    "sched-sedf":  sched_sedf_help,
   1.219 +    "--long": longhelp
   1.220 +    }
   1.221  
   1.222 -#  Virtual Device Commands:
   1.223 -    "block-attach": block_attach_help,
   1.224 -    "block-detach": block_detach_help,
   1.225 -    "block-list": block_list_help,
   1.226 -    "network-attach": network_attach_help,
   1.227 -    "network-detach": network_detach_help,
   1.228 -    "network-list":  network_list_help,
   1.229 -# Vnet commands:
   1.230 -    "vnet-list": vnet_list_help,
   1.231 -    "vnet-create": vnet_create_help,
   1.232 -    "vnet-delete": vnet_delete_help
   1.233 -   }
   1.234 +for command in all_commands:
   1.235 +    # create is handled specially
   1.236 +    if (command != 'create'):
   1.237 +        help[command] = commandToHelp(command)
   1.238 +
   1.239  
   1.240  ####################################################################
   1.241  #
   1.242 @@ -484,9 +481,7 @@ def xm_vcpu_list(args):
   1.243  def xm_reboot(args):
   1.244      arg_check(args,1,"reboot")
   1.245      from xen.xm import shutdown
   1.246 -    # ugly hack because the opt parser apparently wants
   1.247 -    # the subcommand name just to throw it away!
   1.248 -    shutdown.main(["bogus", "-R"] + args)
   1.249 +    shutdown.main(["shutdown", "-R"] + args)
   1.250  
   1.251  def xm_pause(args):
   1.252      arg_check(args, 1, "pause")
   1.253 @@ -504,7 +499,7 @@ def xm_unpause(args):
   1.254  
   1.255  def xm_subcommand(command, args):
   1.256      cmd = __import__(command, globals(), locals(), 'xen.xm')
   1.257 -    cmd.main(["bogus"] + args)
   1.258 +    cmd.main([command] + args)
   1.259  
   1.260  
   1.261  #############################################################
   1.262 @@ -632,7 +627,7 @@ its contents if the [-c|--clear] flag is
   1.263                use="Clear the contents of the Xen message buffer.")
   1.264      # Work around for gopts
   1.265      myargs = args
   1.266 -    myargs.insert(0, "bogus")
   1.267 +    myargs.insert(0, 'dmesg')
   1.268      gopts.parse(myargs)
   1.269      if not (1 <= len(myargs) <= 2):
   1.270          err('Invalid arguments: ' + str(myargs))