Ejemplo n.º 1
0
 def __init__(self, fields, dict=None, mapping=None):
     GenericDevice.__init__(self)
     x = {}
     for k in fields:
         x[k] = None
     self.data = UserDictCase(x)
     if not dict:
         return
     # make sure we get a UserDictCase to work with
     if type(dict) == type({}):
         dict = UserDictCase(dict)
     if mapping is None or type(mapping) == type({}):
         mapping = UserDictCase(mapping)
     if not isinstance(dict, UserDictCase) or \
        not isinstance(mapping, UserDictCase):
         log_error("Argument passed is not a dictionary", dict, mapping)
         raise TypeError("Argument passed is not a dictionary", dict,
                         mapping)
     # make sure we have a platform
     for k in list(dict.keys()):
         if dict[k] == '':
             dict[k] = None
         if self.data.has_key(k):
             self.data[k] = dict[k]
             continue
         if mapping.has_key(k):
             # the mapping dict might tell us to lose some fields
             if mapping[k] is not None:
                 self.data[mapping[k]] = dict[k]
         else:
             log_error("Unknown HW key =`%s'" % k, dict.dict(),
                       mapping.dict())
             # The try-except is added just so that we can send e-mails
             try:
                 raise KeyError("Don't know how to parse key `%s''" % k,
                                dict.dict())
             except:
                 Traceback(mail=1)
                 # Ignore this key
                 continue
     # clean up this data
     try:
         for k in list(self.data.keys()):
             if type(self.data[k]) == type("") and len(self.data[k]):
                 self.data[k] = self.data[k].strip()
                 if not len(self.data[k]):
                     continue
                 if self.data[k][0] == '"' and self.data[k][-1] == '"':
                     self.data[k] = self.data[k][1:-1]
     except IndexError:
         raise_with_tb(
             IndexError("Can not process data = %s, key = %s" %
                        (repr(self.data), k)),
             sys.exc_info()[2])
Ejemplo n.º 2
0
 def __init__(self, fields, dict=None, mapping=None):
     GenericDevice.__init__(self)
     x = {}
     for k in fields:
         x[k] = None
     self.data = UserDictCase(x)
     if not dict:
         return
     # make sure we get a UserDictCase to work with
     if type(dict) == type({}):
         dict = UserDictCase(dict)
     if mapping is None or type(mapping) == type({}):
         mapping = UserDictCase(mapping)
     if not isinstance(dict, UserDictCase) or \
        not isinstance(mapping, UserDictCase):
         log_error("Argument passed is not a dictionary", dict, mapping)
         raise TypeError("Argument passed is not a dictionary",
                         dict, mapping)
     # make sure we have a platform
     for k in dict.keys():
         if dict[k] == '':
             dict[k] = None
         if self.data.has_key(k):
             self.data[k] = dict[k]
             continue
         if mapping.has_key(k):
             # the mapping dict might tell us to lose some fields
             if mapping[k] is not None:
                 self.data[mapping[k]] = dict[k]
         else:
             log_error("Unknown HW key =`%s'" % k,
                       dict.dict(), mapping.dict())
             # The try-except is added just so that we can send e-mails
             try:
                 raise KeyError("Don't know how to parse key `%s''" % k,
                                dict.dict())
             except:
                 Traceback(mail=1)
                 # Ignore this key
                 continue
     # clean up this data
     try:
         for k in self.data.keys():
             if type(self.data[k]) == type("") and len(self.data[k]):
                 self.data[k] = string.strip(self.data[k])
                 if not len(self.data[k]):
                     continue
                 if self.data[k][0] == '"' and self.data[k][-1] == '"':
                     self.data[k] = self.data[k][1:-1]
     except IndexError:
         raise IndexError, "Can not process data = %s, key = %s" % (
             repr(self.data), k), sys.exc_info()[2]