mirror of https://gitee.com/openkylin/libvirt.git
python: sanitize blank line usage
Coding style expects 1 blank line between each method and 2 blank lines before each class. docs/apibuild.py:171:5: E303 too many blank lines (2) def set_header(self, header): ^ docs/apibuild.py:230:1: E302 expected 2 blank lines, found 1 class index: ^ docs/apibuild.py:175:5: E301 expected 1 blank line, found 0 def set_module(self, module): ^ ...more... Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
2ba699cbd5
commit
bc59247df9
|
@ -885,13 +885,11 @@ sc_require_enum_last_marker:
|
|||
# Validate many python style rules
|
||||
FLAKE8_INDENTATION = E114,E115,E116,E121,E125,E126,E127,E128,E129,E131
|
||||
FLAKE8_WHITESPACE = E211,E221,E222,E225,E226,E231,E261
|
||||
FLAKE8_BLANK_LINES = E301,E302,E303,E305
|
||||
FLAKE8_LINE_LENGTH = E501
|
||||
FLAKE8_WARNINGS = W504
|
||||
|
||||
FLAKE8_IGNORE = $(FLAKE8_INDENTATION),$\
|
||||
$(FLAKE8_WHITESPACE),$\
|
||||
$(FLAKE8_BLANK_LINES),$\
|
||||
$(FLAKE8_LINE_LENGTH),$\
|
||||
$(FLAKE8_WARNINGS) \
|
||||
$(NULL)
|
||||
|
|
|
@ -123,6 +123,7 @@ hidden_macros = {
|
|||
"VIR_EXPORT_VAR": "internal macro to mark exported vars",
|
||||
}
|
||||
|
||||
|
||||
def escape(raw):
|
||||
raw = raw.replace('&', '&')
|
||||
raw = raw.replace('<', '<')
|
||||
|
@ -131,9 +132,11 @@ def escape(raw):
|
|||
raw = raw.replace('"', '"')
|
||||
return raw
|
||||
|
||||
|
||||
def uniq(items):
|
||||
return sorted(set(items))
|
||||
|
||||
|
||||
class identifier:
|
||||
def __init__(self, name, header=None, module=None, type=None, lineno=0,
|
||||
info=None, extra=None, conditionals=None):
|
||||
|
@ -167,21 +170,27 @@ class identifier:
|
|||
r = r + " " + repr(self.conditionals)
|
||||
return r
|
||||
|
||||
|
||||
def set_header(self, header):
|
||||
self.header = header
|
||||
|
||||
def set_module(self, module):
|
||||
self.module = module
|
||||
|
||||
def set_type(self, type):
|
||||
self.type = type
|
||||
|
||||
def set_info(self, info):
|
||||
self.info = info
|
||||
|
||||
def set_extra(self, extra):
|
||||
self.extra = extra
|
||||
|
||||
def set_lineno(self, lineno):
|
||||
self.lineno = lineno
|
||||
|
||||
def set_static(self, static):
|
||||
self.static = static
|
||||
|
||||
def set_conditionals(self, conditionals):
|
||||
if conditionals is None or len(conditionals) == 0:
|
||||
self.conditionals = None
|
||||
|
@ -190,20 +199,28 @@ class identifier:
|
|||
|
||||
def get_name(self):
|
||||
return self.name
|
||||
|
||||
def get_header(self):
|
||||
return self.module
|
||||
|
||||
def get_module(self):
|
||||
return self.module
|
||||
|
||||
def get_type(self):
|
||||
return self.type
|
||||
|
||||
def get_info(self):
|
||||
return self.info
|
||||
|
||||
def get_lineno(self):
|
||||
return self.lineno
|
||||
|
||||
def get_extra(self):
|
||||
return self.extra
|
||||
|
||||
def get_static(self):
|
||||
return self.static
|
||||
|
||||
def get_conditionals(self):
|
||||
return self.conditionals
|
||||
|
||||
|
@ -225,6 +242,7 @@ class identifier:
|
|||
if conditionals is not None:
|
||||
self.set_conditionals(conditionals)
|
||||
|
||||
|
||||
class index:
|
||||
def __init__(self, name="noname"):
|
||||
self.name = name
|
||||
|
@ -409,7 +427,6 @@ class index:
|
|||
elif count != 0:
|
||||
print(" %d public %s" % (count, type))
|
||||
|
||||
|
||||
def analyze(self):
|
||||
if not quiet:
|
||||
self.analyze_dict("functions", self.functions)
|
||||
|
@ -419,6 +436,7 @@ class index:
|
|||
self.analyze_dict("typedefs", self.typedefs)
|
||||
self.analyze_dict("macros", self.macros)
|
||||
|
||||
|
||||
class CLexer:
|
||||
"""A lexer for the C language, tokenize the input by reading and
|
||||
analyzing it line by line"""
|
||||
|
@ -584,6 +602,7 @@ class CLexer:
|
|||
self.last = tok
|
||||
return tok
|
||||
|
||||
|
||||
class CParser:
|
||||
"""The C module parser"""
|
||||
def __init__(self, filename, idx=None):
|
||||
|
@ -745,6 +764,7 @@ class CParser:
|
|||
% name)
|
||||
|
||||
return desc
|
||||
|
||||
#
|
||||
# Parse a comment block associate to a macro
|
||||
#
|
||||
|
@ -945,7 +965,6 @@ class CParser:
|
|||
if desc == "":
|
||||
self.warning("Function comment for %s lacks description of the function" % name)
|
||||
|
||||
|
||||
return (ret[0], retdesc), args, desc
|
||||
|
||||
def parsePreproc(self, token):
|
||||
|
@ -1434,7 +1453,6 @@ class CParser:
|
|||
if token[0] == "comment":
|
||||
token = self.token()
|
||||
|
||||
|
||||
if token[0] == "sep" and token[1] == ';':
|
||||
token = self.token()
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import sys
|
|||
|
||||
COLUMNS = 80
|
||||
|
||||
|
||||
def reformat_with_indent(text, initial_indent, indent):
|
||||
|
||||
res = ""
|
||||
|
|
|
@ -29,7 +29,6 @@ import os
|
|||
import os.path
|
||||
|
||||
|
||||
|
||||
OCCURRENCE__REQUIRED_ITEM = "r"
|
||||
OCCURRENCE__REQUIRED_LIST = "rl"
|
||||
OCCURRENCE__OPTIONAL_ITEM = "o"
|
||||
|
@ -47,30 +46,24 @@ autobind_names = set()
|
|||
separator = "/* " + ("* " * 37) + "*\n"
|
||||
|
||||
|
||||
|
||||
def aligned(left, right, length=59):
|
||||
return left.ljust(length, ' ') + right
|
||||
|
||||
|
||||
|
||||
class Member:
|
||||
def __init__(self, type, occurrence):
|
||||
self.type = type
|
||||
self.occurrence = occurrence
|
||||
|
||||
|
||||
def is_enum(self):
|
||||
return self.type in predefined_enums or self.type in enums_by_name
|
||||
|
||||
|
||||
def is_object(self):
|
||||
return self.type in predefined_objects or self.type in objects_by_name
|
||||
|
||||
|
||||
def is_type_generated(self):
|
||||
return self.type in enums_by_name or self.type in objects_by_name
|
||||
|
||||
|
||||
def get_occurrence_comment(self):
|
||||
occurrence_map = {
|
||||
OCCURRENCE__REQUIRED_ITEM: "/* required */",
|
||||
|
@ -84,8 +77,6 @@ class Member:
|
|||
raise ValueError("unknown occurrence value '%s'" % self.occurrence)
|
||||
|
||||
|
||||
|
||||
|
||||
class Parameter(Member):
|
||||
def __init__(self, type, name, occurrence):
|
||||
Member.__init__(self, type, occurrence)
|
||||
|
@ -96,7 +87,6 @@ class Parameter(Member):
|
|||
self.name = name
|
||||
self.autobind_name = None
|
||||
|
||||
|
||||
def generate_parameter(self, is_last=False, is_header=True, offset=0):
|
||||
if self.occurrence == OCCURRENCE__IGNORED:
|
||||
raise ValueError("invalid function parameter occurrence value '%s'"
|
||||
|
@ -118,7 +108,6 @@ class Parameter(Member):
|
|||
|
||||
return aligned(string, self.get_occurrence_comment() + "\n")
|
||||
|
||||
|
||||
def generate_return(self, offset=0, end_of_line=";"):
|
||||
if self.occurrence == OCCURRENCE__IGNORED:
|
||||
raise ValueError("invalid function parameter occurrence value '%s'"
|
||||
|
@ -131,7 +120,6 @@ class Parameter(Member):
|
|||
|
||||
return aligned(string, self.get_occurrence_comment() + "\n")
|
||||
|
||||
|
||||
def generate_require_code(self):
|
||||
if self.occurrence in [OCCURRENCE__REQUIRED_ITEM,
|
||||
OCCURRENCE__REQUIRED_LIST]:
|
||||
|
@ -139,7 +127,6 @@ class Parameter(Member):
|
|||
else:
|
||||
return ""
|
||||
|
||||
|
||||
def generate_serialize_code(self):
|
||||
if self.occurrence in [OCCURRENCE__REQUIRED_LIST,
|
||||
OCCURRENCE__OPTIONAL_LIST]:
|
||||
|
@ -152,7 +139,6 @@ class Parameter(Member):
|
|||
return " ESX_VI__METHOD__PARAMETER__SERIALIZE(%s, %s)\n" \
|
||||
% (self.type, self.name)
|
||||
|
||||
|
||||
def get_type_string(self, as_return_value=False):
|
||||
string = ""
|
||||
|
||||
|
@ -173,7 +159,6 @@ class Parameter(Member):
|
|||
|
||||
return string
|
||||
|
||||
|
||||
def get_occurrence_short_enum(self):
|
||||
if self.occurrence == OCCURRENCE__REQUIRED_ITEM:
|
||||
return "RequiredItem"
|
||||
|
@ -187,7 +172,6 @@ class Parameter(Member):
|
|||
raise ValueError("unknown occurrence value '%s'" % self.occurrence)
|
||||
|
||||
|
||||
|
||||
class Method:
|
||||
def __init__(self, name, parameters, returns):
|
||||
self.name = name
|
||||
|
@ -201,7 +185,6 @@ class Method:
|
|||
else:
|
||||
self.autobind_parameter = parameter
|
||||
|
||||
|
||||
def generate_header(self):
|
||||
header = "int esxVI_%s\n" % self.name
|
||||
header += " (esxVI_Context *ctx"
|
||||
|
@ -224,7 +207,6 @@ class Method:
|
|||
|
||||
return header
|
||||
|
||||
|
||||
def generate_source(self):
|
||||
source = "/* esxVI_%s */\n" % self.name
|
||||
source += "ESX_VI__METHOD(%s," % self.name
|
||||
|
@ -288,14 +270,12 @@ class Method:
|
|||
return source
|
||||
|
||||
|
||||
|
||||
class Property(Member):
|
||||
def __init__(self, type, name, occurrence):
|
||||
Member.__init__(self, type, occurrence)
|
||||
|
||||
self.name = name
|
||||
|
||||
|
||||
def generate_struct_member(self):
|
||||
if self.occurrence == OCCURRENCE__IGNORED:
|
||||
return " /* FIXME: %s is currently ignored */\n" % self.name
|
||||
|
@ -304,7 +284,6 @@ class Property(Member):
|
|||
|
||||
return aligned(string, self.get_occurrence_comment() + "\n")
|
||||
|
||||
|
||||
def generate_free_code(self):
|
||||
if self.type == "String" and \
|
||||
self.occurrence not in [OCCURRENCE__REQUIRED_LIST,
|
||||
|
@ -319,7 +298,6 @@ class Property(Member):
|
|||
else:
|
||||
return " esxVI_%s_Free(&item->%s);\n" % (self.type, self.name)
|
||||
|
||||
|
||||
def generate_validate_code(self, managed=False):
|
||||
if managed:
|
||||
macro = "ESX_VI__TEMPLATE__PROPERTY__MANAGED_REQUIRE"
|
||||
|
@ -334,7 +312,6 @@ class Property(Member):
|
|||
else:
|
||||
return ""
|
||||
|
||||
|
||||
def generate_deep_copy_code(self):
|
||||
if self.occurrence == OCCURRENCE__IGNORED:
|
||||
return " /* FIXME: %s is currently ignored */\n" % self.name
|
||||
|
@ -351,7 +328,6 @@ class Property(Member):
|
|||
return " ESX_VI__TEMPLATE__PROPERTY__DEEP_COPY(%s, %s)\n" \
|
||||
% (self.type, self.name)
|
||||
|
||||
|
||||
def generate_serialize_code(self):
|
||||
if self.occurrence == OCCURRENCE__IGNORED:
|
||||
return " /* FIXME: %s is currently ignored */\n" % self.name
|
||||
|
@ -366,7 +342,6 @@ class Property(Member):
|
|||
return " ESX_VI__TEMPLATE__PROPERTY__SERIALIZE(%s, %s)\n" \
|
||||
% (self.type, self.name)
|
||||
|
||||
|
||||
def generate_deserialize_code(self):
|
||||
if self.occurrence == OCCURRENCE__IGNORED:
|
||||
return " ESX_VI__TEMPLATE__PROPERTY__DESERIALIZE_IGNORE(%s) /* FIXME */\n" \
|
||||
|
@ -382,7 +357,6 @@ class Property(Member):
|
|||
return " ESX_VI__TEMPLATE__PROPERTY__DESERIALIZE(%s, %s)\n" \
|
||||
% (self.type, self.name)
|
||||
|
||||
|
||||
def generate_lookup_code(self):
|
||||
if self.occurrence == OCCURRENCE__IGNORED:
|
||||
return " ESX_VI__TEMPLATE__PROPERTY__CAST_FROM_ANY_TYPE_IGNORE(%s) /* FIXME */\n" \
|
||||
|
@ -398,7 +372,6 @@ class Property(Member):
|
|||
return " ESX_VI__TEMPLATE__PROPERTY__CAST_FROM_ANY_TYPE(%s, %s)\n" \
|
||||
% (self.type, self.name)
|
||||
|
||||
|
||||
def get_type_string(self):
|
||||
if self.type == "String" and \
|
||||
self.occurrence not in [OCCURRENCE__REQUIRED_LIST,
|
||||
|
@ -410,29 +383,24 @@ class Property(Member):
|
|||
return "esxVI_%s *" % self.type
|
||||
|
||||
|
||||
|
||||
class Type:
|
||||
def __init__(self, kind, name):
|
||||
self.kind = kind
|
||||
self.name = name
|
||||
|
||||
|
||||
def generate_typedef(self):
|
||||
return "typedef %s _esxVI_%s esxVI_%s;\n" \
|
||||
% (self.kind, self.name, self.name)
|
||||
|
||||
|
||||
def generate_typeenum(self):
|
||||
return " esxVI_Type_%s,\n" % self.name
|
||||
|
||||
|
||||
def generate_typetostring(self):
|
||||
string = " case esxVI_Type_%s:\n" % self.name
|
||||
string += " return \"%s\";\n\n" % self.name
|
||||
|
||||
return string
|
||||
|
||||
|
||||
def generate_typefromstring(self):
|
||||
string = " if (STREQ(type, \"%s\"))\n" % self.name
|
||||
string += " return esxVI_Type_%s;\n" % self.name
|
||||
|
@ -448,14 +416,12 @@ class GenericObject(Type):
|
|||
FEATURE__SERIALIZE = (1 << 5)
|
||||
FEATURE__DESERIALIZE = (1 << 6)
|
||||
|
||||
|
||||
def __init__(self, name, category, managed, generic_objects_by_name):
|
||||
Type.__init__(self, "struct", name)
|
||||
self.category = category
|
||||
self.managed = managed
|
||||
self.generic_objects_by_name = generic_objects_by_name
|
||||
|
||||
|
||||
def generate_comment(self):
|
||||
comment = separator
|
||||
comment += " * %s: %s\n" % (self.category, self.name)
|
||||
|
@ -480,7 +446,6 @@ class GenericObject(Type):
|
|||
|
||||
return comment
|
||||
|
||||
|
||||
def generate_struct_members(self, add_banner=False, struct_gap=False):
|
||||
members = ""
|
||||
|
||||
|
@ -503,7 +468,6 @@ class GenericObject(Type):
|
|||
|
||||
return members
|
||||
|
||||
|
||||
def generate_dispatch(self, suffix, is_first=True):
|
||||
source = ""
|
||||
|
||||
|
@ -523,7 +487,6 @@ class GenericObject(Type):
|
|||
|
||||
return source
|
||||
|
||||
|
||||
def generate_free_code(self, add_banner=False):
|
||||
source = ""
|
||||
|
||||
|
@ -549,7 +512,6 @@ class GenericObject(Type):
|
|||
|
||||
return source
|
||||
|
||||
|
||||
def generate_validate_code(self, add_banner=False):
|
||||
source = ""
|
||||
|
||||
|
@ -576,7 +538,6 @@ class GenericObject(Type):
|
|||
return source
|
||||
|
||||
|
||||
|
||||
class Object(GenericObject):
|
||||
def __init__(self, name, extends, properties, features=0, extended_by=None):
|
||||
GenericObject.__init__(self, name, 'VI Object', False, objects_by_name)
|
||||
|
@ -589,7 +550,6 @@ class Object(GenericObject):
|
|||
if self.extended_by is not None:
|
||||
self.extended_by.sort()
|
||||
|
||||
|
||||
def generate_dynamic_cast_code(self, is_first=True):
|
||||
source = ""
|
||||
|
||||
|
@ -609,7 +569,6 @@ class Object(GenericObject):
|
|||
|
||||
return source
|
||||
|
||||
|
||||
def generate_deep_copy_code(self, add_banner=False):
|
||||
source = ""
|
||||
|
||||
|
@ -635,7 +594,6 @@ class Object(GenericObject):
|
|||
|
||||
return source
|
||||
|
||||
|
||||
def generate_serialize_code(self, add_banner=False):
|
||||
source = ""
|
||||
|
||||
|
@ -654,7 +612,6 @@ class Object(GenericObject):
|
|||
|
||||
return source
|
||||
|
||||
|
||||
def generate_deserialize_code(self, add_banner=False):
|
||||
source = ""
|
||||
|
||||
|
@ -673,7 +630,6 @@ class Object(GenericObject):
|
|||
|
||||
return source
|
||||
|
||||
|
||||
def generate_header(self):
|
||||
header = self.generate_comment()
|
||||
|
||||
|
@ -754,7 +710,6 @@ class Object(GenericObject):
|
|||
|
||||
return header
|
||||
|
||||
|
||||
def generate_source(self):
|
||||
source = separator
|
||||
source += " * VI Object: %s\n" % self.name
|
||||
|
@ -916,7 +871,6 @@ class Object(GenericObject):
|
|||
return source
|
||||
|
||||
|
||||
|
||||
class ManagedObject(GenericObject):
|
||||
def __init__(self, name, extends, properties, features=0, extended_by=None):
|
||||
GenericObject.__init__(self, name, 'VI Managed Object', True,
|
||||
|
@ -929,7 +883,6 @@ class ManagedObject(GenericObject):
|
|||
if self.extended_by is not None:
|
||||
self.extended_by.sort()
|
||||
|
||||
|
||||
def generate_lookup_code1(self, add_banner=False):
|
||||
source = ""
|
||||
|
||||
|
@ -955,7 +908,6 @@ class ManagedObject(GenericObject):
|
|||
|
||||
return source
|
||||
|
||||
|
||||
def generate_lookup_code2(self, add_banner=False):
|
||||
source = ""
|
||||
|
||||
|
@ -981,7 +933,6 @@ class ManagedObject(GenericObject):
|
|||
|
||||
return source
|
||||
|
||||
|
||||
def generate_header(self):
|
||||
header = self.generate_comment()
|
||||
|
||||
|
@ -1017,7 +968,6 @@ class ManagedObject(GenericObject):
|
|||
|
||||
return header
|
||||
|
||||
|
||||
def generate_helper_header(self):
|
||||
# functions
|
||||
return (
|
||||
|
@ -1030,7 +980,6 @@ class ManagedObject(GenericObject):
|
|||
% {"name": self.name}
|
||||
)
|
||||
|
||||
|
||||
def generate_source(self):
|
||||
source = self.generate_comment()
|
||||
|
||||
|
@ -1084,7 +1033,6 @@ class ManagedObject(GenericObject):
|
|||
|
||||
return source
|
||||
|
||||
|
||||
def generate_helper_source(self):
|
||||
# lookup
|
||||
return (
|
||||
|
@ -1106,13 +1054,11 @@ class Enum(Type):
|
|||
FEATURE__SERIALIZE = (1 << 2)
|
||||
FEATURE__DESERIALIZE = (1 << 3)
|
||||
|
||||
|
||||
def __init__(self, name, values, features=0):
|
||||
Type.__init__(self, "enum", name)
|
||||
self.values = values
|
||||
self.features = features
|
||||
|
||||
|
||||
def generate_header(self):
|
||||
header = separator
|
||||
header += " * VI Enum: %s\n" % self.name
|
||||
|
@ -1145,7 +1091,6 @@ class Enum(Type):
|
|||
|
||||
return header
|
||||
|
||||
|
||||
def generate_source(self):
|
||||
source = separator
|
||||
source += " * VI Enum: %s\n" % self.name
|
||||
|
@ -1183,18 +1128,15 @@ class Enum(Type):
|
|||
return source
|
||||
|
||||
|
||||
|
||||
def report_error(message):
|
||||
print("error: " + message)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
||||
def capitalize_first(string):
|
||||
return string[:1].upper() + string[1:]
|
||||
|
||||
|
||||
|
||||
def parse_object(block):
|
||||
# expected format: [managed] object <name> [extends <name>]
|
||||
header_items = block[0][1].split()
|
||||
|
@ -1239,7 +1181,6 @@ def parse_object(block):
|
|||
return Object(name=name, extends=extends, properties=properties)
|
||||
|
||||
|
||||
|
||||
def parse_enum(block):
|
||||
# expected format: enum <name>
|
||||
header_items = block[0][1].split()
|
||||
|
@ -1260,7 +1201,6 @@ def parse_enum(block):
|
|||
return Enum(name=name, values=values)
|
||||
|
||||
|
||||
|
||||
def parse_method(block):
|
||||
# expected format: method <name> [returns <type> <occurrence>]
|
||||
header_items = block[0][1].split()
|
||||
|
@ -1298,7 +1238,6 @@ def parse_method(block):
|
|||
return Method(name=name, parameters=parameters, returns=returns)
|
||||
|
||||
|
||||
|
||||
def is_known_type(type):
|
||||
return type in predefined_objects or \
|
||||
type in predefined_enums or \
|
||||
|
@ -1307,7 +1246,6 @@ def is_known_type(type):
|
|||
type in enums_by_name
|
||||
|
||||
|
||||
|
||||
def open_and_print(filename):
|
||||
if filename.startswith("./"):
|
||||
print(" GEN " + filename[2:])
|
||||
|
@ -1317,7 +1255,6 @@ def open_and_print(filename):
|
|||
return open(filename, "wt")
|
||||
|
||||
|
||||
|
||||
predefined_enums = ["Boolean"]
|
||||
|
||||
predefined_objects = ["AnyType",
|
||||
|
@ -1386,7 +1323,6 @@ input_filename = os.path.join(sys.argv[1], "esx/esx_vi_generator.input")
|
|||
output_dirname = os.path.join(sys.argv[2], "esx")
|
||||
|
||||
|
||||
|
||||
types_typedef = open_and_print(os.path.join(output_dirname, "esx_vi_types.generated.typedef"))
|
||||
types_typeenum = open_and_print(os.path.join(output_dirname, "esx_vi_types.generated.typeenum"))
|
||||
types_typetostring = open_and_print(os.path.join(output_dirname, "esx_vi_types.generated.typetostring"))
|
||||
|
@ -1400,7 +1336,6 @@ helpers_header = open_and_print(os.path.join(output_dirname, "esx_vi.generated.h
|
|||
helpers_source = open_and_print(os.path.join(output_dirname, "esx_vi.generated.c"))
|
||||
|
||||
|
||||
|
||||
number = 0
|
||||
objects_by_name = {}
|
||||
managed_objects_by_name = {}
|
||||
|
@ -1409,7 +1344,6 @@ methods_by_name = {}
|
|||
block = None
|
||||
|
||||
|
||||
|
||||
# parse input file
|
||||
for line in open(input_filename, "rt").readlines():
|
||||
number += 1
|
||||
|
@ -1449,7 +1383,6 @@ for line in open(input_filename, "rt").readlines():
|
|||
block.append((number, line))
|
||||
|
||||
|
||||
|
||||
for method in methods_by_name.values():
|
||||
# method parameter types must be serializable
|
||||
for parameter in method.parameters:
|
||||
|
@ -1489,7 +1422,6 @@ for method in methods_by_name.values():
|
|||
objects_by_name[method.returns.type].features |= Object.FEATURE__LIST
|
||||
|
||||
|
||||
|
||||
for enum in enums_by_name.values():
|
||||
# apply additional features
|
||||
if enum.name in additional_enum_features:
|
||||
|
@ -1499,7 +1431,6 @@ for enum in enums_by_name.values():
|
|||
enum.features |= Enum.FEATURE__DESERIALIZE
|
||||
|
||||
|
||||
|
||||
for obj in objects_by_name.values():
|
||||
for property in obj.properties:
|
||||
if property.occurrence != OCCURRENCE__IGNORED and \
|
||||
|
@ -1551,7 +1482,6 @@ for obj in objects_by_name.values():
|
|||
extended_obj.extended_by.sort()
|
||||
|
||||
|
||||
|
||||
for obj in objects_by_name.values():
|
||||
# if an object is a candidate (it is used directly as parameter or return
|
||||
# type or is a member of another object) and it is extended by another
|
||||
|
@ -1560,7 +1490,6 @@ for obj in objects_by_name.values():
|
|||
obj.features |= Object.FEATURE__DYNAMIC_CAST
|
||||
|
||||
|
||||
|
||||
def propagate_feature(obj, feature):
|
||||
global features_have_changed
|
||||
|
||||
|
@ -1590,7 +1519,6 @@ def propagate_feature(obj, feature):
|
|||
propagate_feature(objects_by_name[property.type], feature)
|
||||
|
||||
|
||||
|
||||
def inherit_features(obj):
|
||||
global features_have_changed
|
||||
|
||||
|
@ -1614,7 +1542,6 @@ def inherit_features(obj):
|
|||
inherit_features(objects_by_name[extended_by])
|
||||
|
||||
|
||||
|
||||
# there are two directions to spread features:
|
||||
# 1) up and down the inheritance chain
|
||||
# 2) from object types to their member property types
|
||||
|
@ -1634,7 +1561,6 @@ while features_have_changed:
|
|||
inherit_features(obj)
|
||||
|
||||
|
||||
|
||||
for obj in managed_objects_by_name.values():
|
||||
for property in obj.properties:
|
||||
if property.occurrence != OCCURRENCE__IGNORED and \
|
||||
|
@ -1658,7 +1584,6 @@ for obj in managed_objects_by_name.values():
|
|||
extended_obj.extended_by.sort()
|
||||
|
||||
|
||||
|
||||
notice = "/* Generated by esx_vi_generator.py */\n\n\n\n"
|
||||
|
||||
types_typedef.write(notice)
|
||||
|
@ -1674,7 +1599,6 @@ helpers_header.write(notice)
|
|||
helpers_source.write(notice)
|
||||
|
||||
|
||||
|
||||
# output enums
|
||||
types_typedef.write(separator +
|
||||
" * VI Enums\n" +
|
||||
|
@ -1691,7 +1615,6 @@ for name in names:
|
|||
types_source.write(enums_by_name[name].generate_source())
|
||||
|
||||
|
||||
|
||||
# output objects
|
||||
types_typedef.write("\n\n\n" +
|
||||
separator +
|
||||
|
@ -1712,7 +1635,6 @@ for name in names:
|
|||
types_source.write(objects_by_name[name].generate_source())
|
||||
|
||||
|
||||
|
||||
# output managed objects
|
||||
types_typedef.write("\n\n\n" +
|
||||
separator +
|
||||
|
@ -1733,7 +1655,6 @@ for name in names:
|
|||
types_source.write(managed_objects_by_name[name].generate_source())
|
||||
|
||||
|
||||
|
||||
# output methods
|
||||
names = sorted(methods_by_name.keys())
|
||||
|
||||
|
@ -1752,7 +1673,6 @@ for name in names:
|
|||
methods_macro.write(string)
|
||||
|
||||
|
||||
|
||||
# output helpers
|
||||
names = sorted(managed_objects_by_name.keys())
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ separator = "/*" + ("*" * 50) + "*\n"
|
|||
wmi_version_separator = "/"
|
||||
wmi_classes_by_name = {}
|
||||
|
||||
|
||||
class WmiClass:
|
||||
"""Represents WMI class and provides methods to generate C code.
|
||||
|
||||
|
@ -49,7 +50,6 @@ class WmiClass:
|
|||
self.versions = versions if versions else list()
|
||||
self.common = None
|
||||
|
||||
|
||||
def prepare(self):
|
||||
"""Prepares the class for code generation
|
||||
|
||||
|
@ -73,7 +73,6 @@ class WmiClass:
|
|||
# are in the same order - to ensure C struct member alignment
|
||||
self._align_property_members()
|
||||
|
||||
|
||||
def generate_classes_header(self):
|
||||
"""Generate C header code and return it as string
|
||||
|
||||
|
@ -102,7 +101,6 @@ class WmiClass:
|
|||
|
||||
return header
|
||||
|
||||
|
||||
def generate_classes_source(self):
|
||||
"""Returns a C code string defining wsman data structs
|
||||
|
||||
|
@ -132,13 +130,11 @@ class WmiClass:
|
|||
source += ' { "", "", 0 },\n' # null terminated
|
||||
source += '};\n\n'
|
||||
|
||||
|
||||
source += self._define_WmiInfo_struct()
|
||||
source += "\n\n"
|
||||
|
||||
return source
|
||||
|
||||
|
||||
def generate_classes_typedef(self):
|
||||
"""Returns C string for typdefs"""
|
||||
|
||||
|
@ -152,8 +148,6 @@ class WmiClass:
|
|||
|
||||
return typedef
|
||||
|
||||
|
||||
|
||||
def _declare_data_structs(self):
|
||||
"""Returns string C code declaring data structs.
|
||||
|
||||
|
@ -184,7 +178,6 @@ class WmiClass:
|
|||
|
||||
return header
|
||||
|
||||
|
||||
def _declare_hypervObject_struct(self):
|
||||
"""Return string for C code declaring hypervObject instance"""
|
||||
|
||||
|
@ -211,7 +204,6 @@ class WmiClass:
|
|||
|
||||
return header
|
||||
|
||||
|
||||
def _define_WmiInfo_struct(self):
|
||||
"""Return string for C code defining *_WmiInfo struct
|
||||
|
||||
|
@ -241,7 +233,6 @@ class WmiClass:
|
|||
|
||||
return source
|
||||
|
||||
|
||||
def _align_property_members(self):
|
||||
"""Identifies common properties in all class versions.
|
||||
|
||||
|
@ -308,7 +299,6 @@ class WmiClass:
|
|||
self.common.append(x[0])
|
||||
|
||||
|
||||
|
||||
class ClassUriInfo:
|
||||
"""Prepares URI information needed for wsman requests."""
|
||||
|
||||
|
@ -328,7 +318,6 @@ class ClassUriInfo:
|
|||
self.resourceUri = "%s/%s" % (baseUri, wmi_name)
|
||||
|
||||
|
||||
|
||||
class WmiClassVersion:
|
||||
"""Represents specific version of WMI class."""
|
||||
|
||||
|
@ -339,7 +328,6 @@ class WmiClassVersion:
|
|||
self.uri_info = uri_info
|
||||
|
||||
|
||||
|
||||
class Property:
|
||||
typemap = {
|
||||
"boolean": "BOOL",
|
||||
|
@ -359,7 +347,6 @@ class Property:
|
|||
"uint64": "UINT64"
|
||||
}
|
||||
|
||||
|
||||
def __init__(self, type, name, is_array):
|
||||
if type not in Property.typemap:
|
||||
report_error("unhandled property type %s" % type)
|
||||
|
@ -368,7 +355,6 @@ class Property:
|
|||
self.name = name
|
||||
self.is_array = is_array
|
||||
|
||||
|
||||
def generate_classes_header(self):
|
||||
if self.is_array:
|
||||
return " XML_TYPE_DYN_ARRAY %s;\n" % self.name
|
||||
|
@ -376,7 +362,6 @@ class Property:
|
|||
return " XML_TYPE_%s %s;\n" \
|
||||
% (Property.typemap[self.type], self.name)
|
||||
|
||||
|
||||
def generate_classes_source(self, class_name):
|
||||
if self.is_array:
|
||||
return " SER_NS_DYN_ARRAY(%s_RESOURCE_URI, \"%s\", 0, 0, %s),\n" \
|
||||
|
@ -385,12 +370,10 @@ class Property:
|
|||
return " SER_NS_%s(%s_RESOURCE_URI, \"%s\", 1),\n" \
|
||||
% (Property.typemap[self.type], class_name.upper(), self.name)
|
||||
|
||||
|
||||
def generate_typemap(self):
|
||||
return ' { "%s", "%s", %s },\n' % (self.name, self.type.lower(), str(self.is_array).lower())
|
||||
|
||||
|
||||
|
||||
def open_and_print(filename):
|
||||
if filename.startswith("./"):
|
||||
print(" GEN " + filename[2:])
|
||||
|
@ -400,13 +383,11 @@ def open_and_print(filename):
|
|||
return open(filename, "wt")
|
||||
|
||||
|
||||
|
||||
def report_error(message):
|
||||
print("error: " + message)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
||||
def parse_class(block, number):
|
||||
# expected format: class <name>
|
||||
header_items = block[0][1].split()
|
||||
|
@ -452,7 +433,6 @@ def parse_class(block, number):
|
|||
wmi_classes_by_name[wmi_name] = WmiClass(wmi_name, [cls])
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
report_error("usage: %s srcdir builddir" % sys.argv[0])
|
||||
|
@ -512,6 +492,5 @@ def main():
|
|||
classes_source.write(cls.generate_classes_source())
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -5,6 +5,7 @@ import sys
|
|||
import json
|
||||
import xmltodict
|
||||
|
||||
|
||||
def checkCPUIDFeature(cpuData, feature):
|
||||
eax_in = feature["eax_in"]
|
||||
ecx_in = feature["ecx_in"]
|
||||
|
|
Loading…
Reference in New Issue