| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ad3c18a commit fe2fc63
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,26 +58,32 @@ def getText(nodelist): | |||
| 58 | 58 | name = getText(cmd.getElementsByTagName('name')[0].childNodes).strip() | |
| 59 | 59 | assert name | |
| 60 | 60 | ||
| 61 | - description = cmd.getElementsByTagName('name')[0].getAttribute("description") | ||
| 62 | - if description: description = '"""%s"""' % description | ||
| 61 | + description = getText(cmd.getElementsByTagName('description')[0].childNodes).strip() | ||
| 62 | + if description: | ||
| 63 | + description = '"""%s"""' % description | ||
| 63 | 64 | else: description = '' | |
| 64 | 65 | arguments = [] | |
| 65 | 66 | options = [] | |
| 66 | 67 | descriptions = [] | |
| 67 | 68 | ||
| 68 | - for param in cmd.getElementsByTagName('arg'): | ||
| 69 | - argname = getText(param.childNodes).strip() | ||
| 69 | + for param in cmd.getElementsByTagName("request")[0].getElementsByTagName("arg"): | ||
| 70 | + argname = getText(param.getElementsByTagName('name')[0].childNodes).strip() | ||
| 70 | 71 | assert argname | |
| 71 | 72 | ||
| 72 | - required = param.getAttribute("required").strip() | ||
| 73 | + required = getText(param.getElementsByTagName('required')[0].childNodes).strip() | ||
| 73 | 74 | if required == 'true': required = True | |
| 74 | 75 | elif required == 'false': required = False | |
| 75 | 76 | else: raise AssertionError, "Not reached" | |
| 76 | 77 | if required: arguments.append(argname) | |
| 77 | 78 | options.append(argname) | |
| 78 | 79 | ||
| 79 | - description = param.getAttribute("description").strip() | ||
| 80 | - if description: descriptions.append( (argname,description) ) | ||
| 80 | + #import ipdb; ipdb.set_trace() | ||
| 81 | + requestDescription = param.getElementsByTagName('description') | ||
| 82 | + if requestDescription: | ||
| 83 | + descriptionParam = getText(requestDescription[0].childNodes) | ||
| 84 | + else: | ||
| 85 | + descriptionParam = '' | ||
| 86 | + if descriptionParam: descriptions.append( (argname,descriptionParam) ) | ||
| 81 | 87 | ||
| 82 | 88 | funcparams = ["self"] + [ "%s=None"%o for o in options ] | |
| 83 | 89 | funcparams = ", ".join(funcparams) | |
@@ -95,7 +101,7 @@ def %s(%s): | |||
| 95 | 101 | output = self._make_request("%s",parms) | |
| 96 | 102 | return output | |
| 97 | 103 | """%(name,funcparams,description,arguments,name) | |
| 98 | - | ||
| 104 | + | ||
| 99 | 105 | namespace = {} | |
| 100 | 106 | exec code.strip() in namespace | |
| 101 | 107 | ||
@@ -106,7 +112,8 @@ def %s(%s): | |||
| 106 | 112 | yield (name,func) | |
| 107 | 113 | ||
| 108 | 114 | ||
| 109 | - for name,meth in load_dynamic_methods(): setattr(CloudAPI,name,meth) | ||
| 115 | + for name,meth in load_dynamic_methods(): | ||
| 116 | + setattr(CloudAPI, name, meth) | ||
| 110 | 117 | ||
| 111 | 118 | implementor = CloudAPI | |
| 112 | 119 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,25 +11,27 @@ | |||
| 11 | 11 | ||
| 12 | 12 | def main(argv=None): | |
| 13 | 13 | ||
| 14 | + #import ipdb; ipdb.set_trace() | ||
| 14 | 15 | if argv == None: | |
| 15 | 16 | argv = sys.argv | |
| 16 | 17 | ||
| 17 | - prelim_args = [ x for x in argv[1:] if not x.startswith('-') ] | ||
| 18 | + prelim_args = [ x for x in argv[0:] if not x.startswith('-') ] | ||
| 18 | 19 | parser = utils.get_parser() | |
| 19 | - | ||
| 20 | + | ||
| 20 | 21 | api = __import__("cloudapis") | |
| 21 | 22 | apis = getattr(api, "implementor") | |
| 22 | - if len(prelim_args) == 0: | ||
| 23 | - parser.error("you need to specify an API as the first argument\n\nSupported APIs:\n" + "\n".join(utils.get_api_list(apis))) | ||
| 24 | - elif len(prelim_args) == 1: | ||
| 23 | + if len(prelim_args) == 1: | ||
| 25 | 24 | commandlist = utils.get_command_list(apis) | |
| 26 | - parser.error("you need to specify a command name as the second argument\n\nCommands supported by the %s API:\n"%prelim_args[0] + "\n".join(commandlist)) | ||
| 25 | + parser.error("you need to specify a command name as the first argument\n\nCommands supported by the %s API:\n"%prelim_args[0] + "\n".join(commandlist)) | ||
| 27 | 26 | ||
| 28 | 27 | command = utils.lookup_command_in_api(apis,prelim_args[1]) | |
| 29 | 28 | if not command: parser.error("command %r not supported by the %s API"%(prelim_args[1],prelim_args[0])) | |
| 29 | + | ||
| 30 | + argv = argv[1:] | ||
| 31 | + if len(argv) == 1: | ||
| 32 | + argv.append("--help") | ||
| 30 | 33 | ||
| 31 | 34 | parser = utils.get_parser(apis.__init__,command) | |
| 32 | - argv = argv[1:] | ||
| 33 | 35 | opts,args,api_optionsdict,cmd_optionsdict = parser.parse_args(argv) | |
| 34 | 36 | ||
| 35 | 37 | ||
@@ -38,7 +40,7 @@ def main(argv=None): | |||
| 38 | 40 | except utils.OptParseError,e: | |
| 39 | 41 | parser.error(str(e)) | |
| 40 | 42 | ||
| 41 | - command = utils.lookup_command_in_api(api,args[1]) | ||
| 43 | + command = utils.lookup_command_in_api(api,args[0]) | ||
| 42 | 44 | ||
| 43 | 45 | # we now discard the first two arguments as those necessarily are the api and command names | |
| 44 | 46 | args = args[2:] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -112,51 +112,18 @@ def get_arguments_and_options(callable): | |||
| 112 | 112 | group = parser.add_option_group("General options") | |
| 113 | 113 | group.add_option('-v', '--verbose', dest="verbose", help="Print extra output") | |
| 114 | 114 | ||
| 115 | - # now we need to derive the short options. we initialize the known fixed longopts and shortopts | ||
| 116 | - longopts = [ '--verbose' ] | ||
| 117 | - | ||
| 118 | - # we add the known long options, sorted and grouped to guarantee a stable short opt set regardless of order | ||
| 119 | - if api_callable and api_options: | ||
| 120 | - longopts += sorted([ x[0][0] for x in api_options ]) | ||
| 121 | - if cmd_callable and cmd_options: | ||
| 122 | - longopts += sorted([ x[0][0] for x in cmd_options ]) | ||
| 123 | - | ||
| 124 | - # we use this function to derive a suitable short option and remember the already-used short options | ||
| 125 | - def derive_shortopt(longopt,usedopts): | ||
| 126 | - """longopt begins with a dash""" | ||
| 127 | - shortopt = None | ||
| 128 | - for x in xrange(2,10000): | ||
| 129 | - try: shortopt = "-" + longopt[x] | ||
| 130 | - except IndexError: | ||
| 131 | - shortopt = None | ||
| 132 | - break | ||
| 133 | - if shortopt in usedopts: continue | ||
| 134 | - usedopts.append(shortopt) | ||
| 135 | - break | ||
| 136 | - return shortopt | ||
| 137 | - | ||
| 138 | - # now we loop through the long options and assign a suitable short option, saving the short option for later use | ||
| 139 | - long_to_short = {} | ||
| 140 | - alreadyusedshorts = [] | ||
| 141 | - for longopt in longopts: | ||
| 142 | - long_to_short[longopt] = derive_shortopt(longopt,alreadyusedshorts) | ||
| 143 | - | ||
| 144 | 115 | parser.api_dests = [] | |
| 145 | 116 | if api_callable and api_options: | |
| 146 | 117 | group = parser.add_option_group("Options for the %s API"%api_name) | |
| 147 | 118 | for a in api_options: | |
| 148 | - shortopt = long_to_short[a[0][0]] | ||
| 149 | - if shortopt: group.add_option(shortopt,a[0][0],**a[1]) | ||
| 150 | - else: group.add_option(a[0][0],**a[1]) | ||
| 119 | + group.add_option(a[0][0],**a[1]) | ||
| 151 | 120 | parser.api_dests.append(a[1]["dest"]) | |
| 152 | 121 | ||
| 153 | 122 | parser.cmd_dests = [] | |
| 154 | 123 | if cmd_callable and cmd_options: | |
| 155 | 124 | group = parser.add_option_group("Options for the %s command"%cmd_name) | |
| 156 | 125 | for a in cmd_options: | |
| 157 | - shortopt = long_to_short[a[0][0]] | ||
| 158 | - if shortopt: group.add_option(shortopt,a[0][0],**a[1]) | ||
| 159 | - else: group.add_option(a[0][0],**a[1]) | ||
| 126 | + group.add_option(a[0][0],**a[1]) | ||
| 160 | 127 | parser.cmd_dests.append(a[1]["dest"]) | |
| 161 | 128 | ||
| 162 | 129 | return parser | |
@@ -178,7 +145,7 @@ def get_command_list(api): | |||
| 178 | 145 | for cmd_name in dir(api): | |
| 179 | 146 | cmd = getattr(api,cmd_name) | |
| 180 | 147 | if callable(cmd) and not cmd_name.startswith("_"): | |
| 181 | - if cmd.__doc__: docstring = cmd.__doc__ | ||
| 182 | - else: docstring = '' | ||
| 183 | - cmds.append( " %s %s"%(cmd_name.replace('_','-'),docstring) ) | ||
| 148 | + if cmd.__doc__:docstring = cmd.__doc__ | ||
| 149 | + else:docstring = '' | ||
| 150 | + cmds.append( " %s" % (cmd_name.replace('_','-')) ) | ||
| 184 | 151 | return cmds | |
| Back | FazBrowse Home | New Git URL |
0 commit comments