def _execute_(self, args, kwargs): """ Oracle specific execution of the query. """ # TODO: args appears unused, raise exception if we see any? # Only copy the arguments we're interested in _p = UserDictCase(kwargs) params = {} # Check that all required parameters were provided: # NOTE: bindnames() is Oracle specific: for k in self._real_cursor.bindnames(): if not _p.has_key(k): # Raise the fault ourselves raise sql_base.SQLError(1008, 'Not all variables bound', k) params[k] = to_string(_p[k]) # cx_Oracle expects the first arg to be the statement and no # positional args: try: self._real_cursor.execute(*(None, ), **params) except cx_Oracle.OperationalError: e = sys.exc_info()[1] raise sql_base.SQLError("Cannot execute SQL statement: %s" % str(e)) self.description = self._real_cursor.description return self._real_cursor.rowcount
def _execute_(self, args, kwargs): """ Oracle specific execution of the query. """ # TODO: args appears unused, raise exception if we see any? # Only copy the arguments we're interested in _p = UserDictCase(kwargs) params = {} # Check that all required parameters were provided: # NOTE: bindnames() is Oracle specific: for k in self._real_cursor.bindnames(): if not _p.has_key(k): # Raise the fault ourselves raise sql_base.SQLError(1008, 'Not all variables bound', k) params[k] = to_string(_p[k]) # cx_Oracle expects the first arg to be the statement and no # positional args: try: self._real_cursor.execute(*(None, ), **params) except cx_Oracle.OperationalError: e = sys.exc_info()[1] raise sql_base.SQLError("Cannot execute SQL statement: %s" % str(e)) self.description = self._real_cursor.description return self._real_cursor.rowcount
class Device(GenericDevice): """ This is the base Device class that supports instantiation from a dictionarry. the __init__ takes the dictionary as its argument, together with a list of valid fields to recognize and with a mapping for dictionary keys into valid field names for self.data The fields are required to know what fields we have in the table. The mapping allows transformation from whatever comes in to valid fields in the table Looks complicated but it isn't -- gafton """ 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_with_tb(IndexError("Can not process data = %s, key = %s" % (repr(self.data), k)), sys.exc_info()[2])
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])
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]
def set_info(self, name, value): """ set a certain value for the userinfo field. This is BUTT ugly. """ log_debug(3, name, value) # translation from what the client send us to real names of the fields # in the tables. mapping = { "first_name": "first_names", "position": "title", "title": "prefix" } if not name: return -1 name = name.lower() if type(value) == type(""): value = value.strip() # We have to watch over carefully for different field names # being sent from rhn_register changed = 0 # translation if name in mapping.keys(): name = mapping[name] # Some fields can not have null string values if name in ["first_names", "last_name", "prefix", # personal_info "address1", "city", "country"]: # site_info # we require something of it if len(str(value)) == 0: return -1 # fields in personal_info (and some in site) if name in ["last_name", "first_names", "company", "phone", "fax", "email", "title"]: self.info[name] = value[:128] changed = 1 elif name == "prefix": values = ["Mr.", "Mrs.", "Ms.", "Dr.", "Hr.", "Sr.", " "] # Now populate a dictinary of valid values valids = UserDictCase() for v in values: # initialize from good values, with and w/o the dot valids[v] = v valids[v[:-1]] = v # commonly encountered values valids["Miss"] = "Miss" valids["Herr"] = "Hr." valids["Sig."] = "Sr." valids["Sir"] = "Mr." # Now check it out if valids.has_key(value): self.info["prefix"] = valids[value] changed = 1 else: log_error("Unknown prefix value `%s'. Assumed `Mr.' instead" % value) self.info["prefix"] = "Mr." changed = 1 # fields in site if name in ["phone", "fax", "zip"]: self.site[name] = value[:32] changed = 1 elif name in ["city", "country", "alt_first_names", "alt_last_name", "address1", "address2", "email", "last_name", "first_names"]: if name == "last_name": self.site["alt_last_name"] = value changed = 1 elif name == "first_names": self.site["alt_first_names"] = value changed = 1 else: self.site[name] = value[:128] changed = 1 elif name in ["state"]: # stupid people put stupid things in here too self.site[name] = value[:60] changed = 1 if not changed: log_error("SET_INFO: Unknown info `%s' = `%s'" % (name, value)) return 0
class Device(GenericDevice): """ This is the base Device class that supports instantiation from a dictionarry. the __init__ takes the dictionary as its argument, together with a list of valid fields to recognize and with a mapping for dictionary keys into valid field names for self.data The fields are required to know what fields we have in the table. The mapping allows transformation from whatever comes in to valid fields in the table Looks complicated but it isn't -- gafton """ 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])
def set_info(self, name, value): """ set a certain value for the userinfo field. This is BUTT ugly. """ log_debug(3, name, value) # translation from what the client send us to real names of the fields # in the tables. mapping = { "first_name": "first_names", "position": "title", "title": "prefix" } if not name: return -1 name = name.lower() if type(value) == type(""): value = value.strip() # We have to watch over carefully for different field names # being sent from rhn_register changed = 0 # translation if name in mapping.keys(): name = mapping[name] # Some fields can not have null string values if name in [ "first_names", "last_name", "prefix", # personal_info "address1", "city", "country" ]: # site_info # we require something of it if len(str(value)) == 0: return -1 # fields in personal_info (and some in site) if name in [ "last_name", "first_names", "company", "phone", "fax", "email", "title" ]: self.info[name] = value[:128] changed = 1 elif name == "prefix": values = ["Mr.", "Mrs.", "Ms.", "Dr.", "Hr.", "Sr.", " "] # Now populate a dictinary of valid values valids = UserDictCase() for v in values: # initialize from good values, with and w/o the dot valids[v] = v valids[v[:-1]] = v # commonly encountered values valids["Miss"] = "Miss" valids["Herr"] = "Hr." valids["Sig."] = "Sr." valids["Sir"] = "Mr." # Now check it out if valids.has_key(value): self.info["prefix"] = valids[value] changed = 1 else: log_error("Unknown prefix value `%s'. Assumed `Mr.' instead" % value) self.info["prefix"] = "Mr." changed = 1 # fields in site if name in ["phone", "fax", "zip"]: self.site[name] = value[:32] changed = 1 elif name in [ "city", "country", "alt_first_names", "alt_last_name", "address1", "address2", "email", "last_name", "first_names" ]: if name == "last_name": self.site["alt_last_name"] = value changed = 1 elif name == "first_names": self.site["alt_first_names"] = value changed = 1 else: self.site[name] = value[:128] changed = 1 elif name in ["state"]: # stupid people put stupid things in here too self.site[name] = value[:60] changed = 1 if not changed: log_error("SET_INFO: Unknown info `%s' = `%s'" % (name, value)) return 0