<reponame>vaideesg/pyopenapi
import logging
from instance.openapiobj import *

#DONE

class typebase(object):
    """description of class"""

    DEBUG_DEFN = True
    def _init_values(self, name, typen, default):
        self.__dict__["_A_"+name] = self._defn[name] if name in self._defn else default
        if self.DEBUG_DEFN and name in self._defn: del self._defn[name]
        self._logger = logging.getLogger(__name__)

    def _extract_ref(self, entry):
        if '$ref' in entry:
            name = entry['$ref']
            name = name.replace('http://redfish.dmtf.org/schemas/v1', './json-schema')
            name = name.replace('http://redfish.dmtf.org/schemas/swordfish/v1', './json-schema')
            # Kludge. DriveOperations refers to Operations in Volume
            # it should be Volume.Operations
            if name == "./json-schema/Volume.v1_0_0.json#/definitions/Operations":
                name = "./json-schema/Volume.v1_0_0.json#/definitions/Volume.Operations"
                
            if self.DEBUG_DEFN: del entry['$ref']
            return name
        return None

    def __init__(self, cfactory, namespec, defn, pname, ctype=openapiobj):
        self._defn = defn
        self._cfactory = cfactory
        self._namespec = namespec
        self._union = False
        self._method = False
        self._pname = pname
        self._ctype = ctype
        self._cfactory.add(self)
        self._init_values('insertable', bool, True)
        self._init_values('deletable', bool, True)
        self._init_values('updatable', bool, True)
        self._init_values('readonly', bool, True)
        self._init_values('additionalProperties', bool, True)
        self._init_values('description', str, None)
        self._init_values('longDescription', str, None)
        self._init_values('uris', list, [])
        self._child_init()

    def _printer(self, printer):
        printer.begin_attrib()
        for i in [j for j in self.__dict__ if j.startswith('_A_')]:
            printer.add_attrib(i, self.__dict__[i])
        printer.end_attrib()
        printer.begin_class_name()
        for i in [j for j in self.__dict__ if not j.startswith('_')]:
            printer.property(i, self.__dict__[i])
        self._child_printer(printer)
        printer.end_class_name()

    def _child_printer(self, printer):
        pass

    def printx(self):
        self._logger.info("=======" + self._namespec['fqcname'])
        #self._logger.debug(self._insertable)
        #self._logger.debug(self._deletable)
        #self._logger.debug(self._updatable)
        #self._logger.debug(self._description)
        #self._logger.debug(self._longDescription)
        self._logger.debug(self._btype.__name__)
        if '_uris' in self.__dict__:
            self._logger.info(self._uris)
        self._child_printx()
        if self.DEBUG_DEFN:
            self._logger.debug("left overs:")
            self._logger.debug(self._defn)

    def newobj(self, value = None):
        obj = self._ctype(self)
        self._child_newobj(obj, value)
        return obj

    def __str__(self):
        return self._namespec['fqcname']

    def _child_newobj(self, obj):
        pass

    def _child_init(self):
        pass

    def _child_printx(self):
        pass

    def resolve(self, namespec, clsdef):
        return True

import logging
from instance.openapiobj import *

#DONE

class typebase(object):
    """description of class"""

    DEBUG_DEFN = True
    def _init_values(self, name, typen, default):
        self.__dict__["_A_"+name] = self._defn[name] if name in self._defn else default
        if self.DEBUG_DEFN and name in self._defn: del self._defn[name]
        self._logger = logging.getLogger(__name__)

    def _extract_ref(self, entry):
        if '$ref' in entry:
            name = entry['$ref']
            name = name.replace('http://redfish.dmtf.org/schemas/v1', './json-schema')
            name = name.replace('http://redfish.dmtf.org/schemas/swordfish/v1', './json-schema')
            # Kludge. DriveOperations refers to Operations in Volume
            # it should be Volume.Operations
            if name == "./json-schema/Volume.v1_0_0.json#/definitions/Operations":
                name = "./json-schema/Volume.v1_0_0.json#/definitions/Volume.Operations"
                
            if self.DEBUG_DEFN: del entry['$ref']
            return name
        return None

    def __init__(self, cfactory, namespec, defn, pname, ctype=openapiobj):
        self._defn = defn
        self._cfactory = cfactory
        self._namespec = namespec
        self._union = False
        self._method = False
        self._pname = pname
        self._ctype = ctype
        self._cfactory.add(self)
        self._init_values('insertable', bool, True)
        self._init_values('deletable', bool, True)
        self._init_values('updatable', bool, True)
        self._init_values('readonly', bool, True)
        self._init_values('additionalProperties', bool, True)
        self._init_values('description', str, None)
        self._init_values('longDescription', str, None)
        self._init_values('uris', list, [])
        self._child_init()

    def _printer(self, printer):
        printer.begin_attrib()
        for i in [j for j in self.__dict__ if j.startswith('_A_')]:
            printer.add_attrib(i, self.__dict__[i])
        printer.end_attrib()
        printer.begin_class_name()
        for i in [j for j in self.__dict__ if not j.startswith('_')]:
            printer.property(i, self.__dict__[i])
        self._child_printer(printer)
        printer.end_class_name()

    def _child_printer(self, printer):
        pass

    def printx(self):
        self._logger.info("=======" + self._namespec['fqcname'])
        #self._logger.debug(self._insertable)
        #self._logger.debug(self._deletable)
        #self._logger.debug(self._updatable)
        #self._logger.debug(self._description)
        #self._logger.debug(self._longDescription)
        self._logger.debug(self._btype.__name__)
        if '_uris' in self.__dict__:
            self._logger.info(self._uris)
        self._child_printx()
        if self.DEBUG_DEFN:
            self._logger.debug("left overs:")
            self._logger.debug(self._defn)

    def newobj(self, value = None):
        obj = self._ctype(self)
        self._child_newobj(obj, value)
        return obj

    def __str__(self):
        return self._namespec['fqcname']

    def _child_newobj(self, obj):
        pass

    def _child_init(self):
        pass

    def _child_printx(self):
        pass

    def resolve(self, namespec, clsdef):
        return True
#DONE description of class # Kludge. DriveOperations refers to Operations in Volume # it should be Volume.Operations #/definitions/Operations": #/definitions/Volume.Operations" #self._logger.debug(self._insertable) #self._logger.debug(self._deletable) #self._logger.debug(self._updatable) #self._logger.debug(self._description) #self._logger.debug(self._longDescription)