From 95c57782b450b3b90184a9ee2063b63a1263d511 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Wed, 15 Apr 2020 10:54:49 +0000 Subject: [PATCH 1/2] async keyword --- tools/apidoc/gen_toc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/apidoc/gen_toc.py b/tools/apidoc/gen_toc.py index ef98b1358987..ceebcdda95c2 100644 --- a/tools/apidoc/gen_toc.py +++ b/tools/apidoc/gen_toc.py @@ -245,10 +245,10 @@ def choose_category(fn): def xml_for(command): name = command['name'] - async = command['async'] and ' (A)' or '' + asyncmethod = command['async'] and ' (A)' or '' dirname = command['dirname'] return ''' -
  • %(async)s
  • +
  • %(asyncmethod)s
  • ''' % locals() From 0bfd70efcbf484afbbf3f1f34774e24c9e9dbe6a Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Wed, 15 Apr 2020 10:55:12 +0000 Subject: [PATCH 2/2] print and urllib --- tools/marvin/marvin/codegenerator.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/tools/marvin/marvin/codegenerator.py b/tools/marvin/marvin/codegenerator.py index f583d526de4a..c694a7b804a1 100644 --- a/tools/marvin/marvin/codegenerator.py +++ b/tools/marvin/marvin/codegenerator.py @@ -21,7 +21,7 @@ from textwrap import dedent import os import sys -import urllib2 +from urllib.request import urlopen class cmdParameterProperty(object): @@ -40,7 +40,7 @@ class cloudStackCmd(object): def __init__(self): self.name = "" self.desc = "" - self.async = "false" + self.asyncmethod = "false" self.request = [] self.response = [] @@ -129,7 +129,7 @@ def generate(self, cmd): self.code += self.space + "def __init__(self):\n" self.code += self.space + self.space - self.code += 'self.isAsync = "%s"\n' % str(self.cmd.async).lower() + self.code += 'self.isAsync = "%s"\n' % str(self.cmd.asyncmethod).lower() for req in self.cmd.request: if req.desc is not None: @@ -305,9 +305,9 @@ def loadCmdFromXML(self, dom): if desc: csCmd.desc = desc - async = getText(cmd.getElementsByTagName('isAsync')) - if async: - csCmd.async = async + asyncmethod = getText(cmd.getElementsByTagName('isAsync')) + if asyncmethod: + csCmd.asyncmethod = asyncmethod argList = cmd.getElementsByTagName("request")[0].\ getElementsByTagName("arg") @@ -398,7 +398,7 @@ def loadCmdFromJSON(self, apiStream): csCmd.desc = cmd['description'] if 'isasync' in cmd: - csCmd.async = cmd['isasync'] + csCmd.asyncmethod = cmd['isasync'] for param in cmd['params']: paramProperty = cmdParameterProperty() @@ -436,7 +436,7 @@ def generateCodeFromJSON(self, endpointUrl): @return: The classes in cloudstackAPI/ formed from api discovery json """ if endpointUrl.find('response=json') >= 0: - apiStream = urllib2.urlopen(endpointUrl) + apiStream = urlopen(endpointUrl) cmds = self.loadCmdFromJSON(apiStream) for cmd in cmds: self.generate(cmd) @@ -468,17 +468,16 @@ def getText(elements): try: os.mkdir(apiModule) except: - print "Failed to create folder %s, due to %s" % (apiModule, - sys.exc_info()) - print parser.print_help() + print ("Failed to create folder {0}, due to {1}".format(apiModule, sys.exc_info())) + print (parser.print_help()) exit(2) apiSpecFile = "/etc/cloud/cli/commands.xml" if options.spec is not None: apiSpecFile = options.spec if not os.path.exists(apiSpecFile): - print "the spec file %s does not exists" % apiSpecFile - print parser.print_help() + print ("the spec file %s does not exists" % apiSpecFile) + print (parser.print_help()) exit(1) cg = CodeGenerator(folder)