def gen_data(self, count = 10): random.seed() objects = list() object_names = Names("names.txt") if count > 1000: object_names.extend(1000) self.names.extend(1000) object_count = count / 10 objects_list = object_names.rset(object_count) randdates = Dates() dates = randdates.rlist(count + 1) texts = self.names.rset(count + 1) self.data.append("SELECT startChangeset();") while count > 0: r = random.randint(0,15) if (len(objects) > 1) and ((r < 15) or (len(objects) >= object_count) ): #choos which object should be modified obj = objects[random.randint(0, len(objects) - 1)] #choos which column should be set index = random.randint(0, len(self.names_list) - 3) col = self.names_list[index] #set value if self.types_list[index] == "bigint": value = random.randint(0,1000000) elif self.types_list[index] == "int": value = random.randint(0,10000) elif self.types_list[index] == "text": value = texts[count] elif self.types_list[index] == "date": value = dates[count] else: value = "" str = self.large_modul_set_template % {'column': col, 'object': obj, 'val': value} else: obj_name = objects_list[len(objects)] objects.append(obj_name) str = self.large_modul_add_template % obj_name self.data.append(str) count = count - 1 index = Numbers(len(self.data)).rset(len(self.data)/5) for i in index: self.data.insert(i,self.commit_template) self.data.append("SELECT commitChangeset('commit');") return self.data
ssvendor = subvendor.rset(4) print ssvendor print ssvendor.ritem() print ssvendor.rset(2) ip = IPv4s() ip.setBlock("A",10) ip.setBlock("B",0) ip.setBlock("C",10,2) ip.setBlock("D",0,25) print ip.ritem() print ip.ritem() print ip.rset(10) date = Dates() print date.ritem() print date.ritem() print date.ritem() date = Dates(2011,3) print date.ritem() print date.ritem() print date.ritem() mac = Macs() print mac.ritem() print mac.ritem()
# generate list of select strings str = map("SELECT vendor_add('{0}');".format, vendor) print "\n".join(str) # get set of N random and unique names hw = names.rset(n) # generate list of select strings str = map("SELECT hardware_add('{0}');".format, hw) print "\n".join(str) # get list on N random (not unique) names from set vendor hw_vendor = vendor.rlist(n) # generate list of select strings from hw and hw_vendor lists str = map("SELECT hardware_set_vendor('{0}','{1}');".format, hw, hw_vendor) print "\n".join(str) # init dates generator (default params) dates = Dates() # get list (not unique) of N dates date = dates.rlist(n) str = map("SELECT hardware_set_purchase('{0}','{1}');".format, hw, date) print "\n".join(str) # init dates generator with new params dates = Dates(2011,4) # get list (not unique) of N dates date = dates.rlist(n) str = map("SELECT hardware_set_warranty('{0}','{1}');".format, hw, date) print "\n".join(str)