I have a metaclass for Row data. Any records at all should inherent from this class, so you can see below I'm trying to inherent twice, once for programs and once for assets. But I need to pass an OrderedDict to the metaclass or alteranative move the slot and init functions to the actual classes... but that seems like a waste of space.
###############################################################
#NORMALIZED CLASS ROWS
###############################################################
class MetaNormRow(type, OrderedDict):
__slots__ = list(OrderedDict.keys())
def __init__(self, **kwargs):
for arg, default in OrderedDict.items():
setattr(self, arg, re.sub(r'[^\x00-\x7F]', '', kwargs.get(arg, default)))
print (str(arg) + " : "+ str(re.sub(r'[^\x00-\x7F]', '', kwargs.get(arg, default))))
def items(self):
for slot in self.__slots__:
yield slot, getattr(self, slot)
def values(self):
for slot in self.__slots__:
yield getattr(self, slot)
class NormAsset(object):
__metaclass__ = MetaNormRow(DefaultAsset)
class NormProg(object):
__metaclass__ = MetaNormRow(DefaultProgs)
Here is how I will use the NormAsset and Prog classes:
kwargs = {
"status": norm_status,
"computer_name": norm_comp_name,
"domain_name": norm_domain,
"serial_num": norm_serial,
"device_type": norm_device_type,
"mfr": norm_mfr,
"model": norm_model,
"os_type": norm_os_type,
"os_ver": norm_os_ver,
"os_subver": norm_os_subver,
"location_code": norm_location_code,
"tan_id": tan_id,
"tan_comp_name": tan_comp_name,
"tan_os": tan_os,
"tan_os_build": tan_os_build,
"tan_os_sp": tan_os_sp,
"tan_country_code": tan_country_code,
"tan_mfr": tan_mfr,
"tan_model": tan_model,
"tan_serial": tan_serial
}
norm_tan_dict[norm_comp_name] = rows.NormAsset(**kwargs)
To clarify, the following functions works 100%... but I need like 10 of these, the only thing that differs is the DefaultAsset diction... so I feel there should be a way to do this without repeating this for every class... the whole point of class inheretance:
class NormAsset(object):
__slots__ = list(DefaultAsset.keys())
def __init__(self, **kwargs):
for arg, default in DefaultAsset.items():
setattr(self, arg, re.sub(r'[^\x00-\x7F]', '', kwargs.get(arg, default)))
#print (str(arg) + " : "+ str(re.sub(r'[^\x00-\x7F]', '', kwargs.get(arg, default))))
def items(self):
for slot in self.__slots__:
yield slot, getattr(self, slot)
def values(self):
for slot in self.__slots__:
yield getattr(self, slot)