本文整理汇总了Python中DataBase类的典型用法代码示例。如果您正苦于以下问题:Python DataBase类的具体用法?Python DataBase怎么用?Python DataBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
'''
进程主入口方法,连接redis数据库,开启子线程读取读写器的信息
'''
self.r = redis.StrictRedis(host=Var.REDIS_HOST, port=Var.REDIS_PORT, db=Var.REDIS_DB)
dataBase = DataBase()
ips = dataBase.getReaderIP()
threads = []
try:
for ip in ips:
# 为每个读写器的验证开一个线程
threads.append(threading.Thread(target=self.ping, args=(ip, )))
for thread in threads:
thread.start()
while True:
for i in range(0, len(threads)):
if threads[i].isAlive() == False:
threads[i] = threading.Thread(target=self.ping, args=(ips[i], ))
threads[i].start()
self.r.ping()
# self.clearRedis(dataBase)
except Exception, ex:
print "Monitor run error function"
print ex
示例2: send_list
def send_list(self, data):
data_base = DataBase(self.key)
# client_name, classification
packets = data_base.get_list(data[1], data[0])
if packets[0] == "":
return [0, packets]
return [len(packets), packets]
示例3: update_process
def update_process(self, data):
data_base = DataBase(self.key)
# client name, process name
primary_key = data_base.get_primary_key(data[3], data[1])
# param, value, classification_ID
data_base.update_table("Classification", "Classification", data[0], primary_key)
return "Process updated"
示例4: listen_to_client
def listen_to_client(self, client, address):
client_name = client.recv(BUFF_SIZE)
data_base = DataBase(self.key)
if not data_base.is_exist("Clients", client_name):
data_base.add_row_to_table("Clients", [client_name, address[0], address[1]])
print "Client " + client_name + " is connected"
else:
print "client " + client_name + " is connected again"
while True:
try:
data = client.recv(BUFF_SIZE)
print data
if data:
if "#" in data:
data_list = self.unpack_command(data)
print data_list
answer = self.handle_command(data_list)
print answer
if type(answer) is list:
print "list"
packets = answer[1]
client.send(str(answer[0]))
for x in range(answer[0]):
client.send(packets[x])
else:
client.send(answer)
else:
pass
else:
print 'Client disconnected'
except:
print "Client " + client_name + " has been disconnected"
client.close()
return False
示例5: POST
def POST(self):
form = myform()
nuevousuario = registro()
if (not form.validates() or not login(form.d.user,form.d.contrasena)) and (not hasattr(session, 'usuario')):
cabecera = "<form name=\"main\" method=\"post\"> "+form.render()+"</form>"
if not nuevousuario.validates():
formularioRegistro = "<form name=\"main\" method=\"post\"> "+nuevousuario.render()+"</form>"
else:
formularioRegistro=""
DataBase.insertar(nuevousuario.d.nombre,nuevousuario.d.apellidos,nuevousuario.d.correo,nuevousuario.d.dianacimiento,nuevousuario.d.mesnacimiento,
nuevousuario.d.anonacimiento,nuevousuario.d.direccion,nuevousuario.d.password,nuevousuario.d.visa,nuevousuario.d.formapago)
DataBase.close()
else:
session.usuario = form.d.user
cabecera = "Bienvenido "+session.usuario+" <a href=\"salir\">SALIR</a><a href=\"modificar\">Modificar</a>"
formularioRegistro=""
addWeb("/")
global rss
global ultimahora
global urlrss
ultimahora=datetime.datetime.now()
if datetime.datetime.now()-ultimahora>=datetime.timedelta(seconds=10) or rss==None:
ultimahora=datetime.datetime.now()
feed = feedparser.parse(urlrss)
entradas = feed.entries
rss="<ul>"
for entrada in entradas:
rss+="<li><a href=\""+entrada.link+"\">"+entrada.title+"</a></li>"
rss+="</ul>"
return render.index(form=cabecera,enlaces=session.get('enlaces'),registro=formularioRegistro,rss=rss)
示例6: GET
def GET(self):
cabecera = "Bienvenido "+session.usuario+" <a href=\"salir\">SALIR</a> <li><a href=\"modificar\">Modificar</a><li> "
self.registro = form.Form(
form.Textbox('nombre',form.Validator("El nombre no puede estar vacio", lambda i: i !=""),description="Nombre",value=DataBase.getNombre()),
form.Textbox('apellidos',form.Validator("Los apellidos no pueden estar vacios", lambda i: i !=""),description="Apellidos",value=DataBase.getApellidos()),
form.Textbox('correo',vemail,description="Correo",value=DataBase.getCorreo()),
form.Dropdown('dianacimiento',[(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8'),
(9, '9'), (10, '10'), (11, '11'), (12, '12'), (13, '13'), (14, '14'), (15, '15'), (16, '16'), (17, '17'), (18, '18'), (19, '19'), (20, '20'),
(21, '21'), (22, '22'), (23, '23'), (24, '24'), (25, '25'), (26, '26'), (27, '27'), (28, '28'), (29, '29'), (30, '30'), (31, '31')],description="Dia de nacimiento",value=DataBase.getDiaNacimiento()),
form.Dropdown('mesnacimiento',[(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8'),
(9, '9'), (10, '10'), (11, '11'), (12, '12')],description="Mes de nacimiento",value=DataBase.getMesNacimiento()),
form.Dropdown('anonacimiento',[(1993,'1993'),(1992,'1992'),(1991,'1991')],description="Ano nacimiento",value=DataBase.getAnoNacimiento()),
form.Textarea('direccion',form.Validator("La direccion no puede estar vacia", lambda i: i !=""),description="Direccion",value=DataBase.getDireccion()),
form.Password('password',vpass,description="Password"),
form.Password('password2',vpass,description="Verificacion"),
form.Textbox('visa',vvisa,description="Numero visa",value=DataBase.getNumeroVisa()),
form.Radio('formapago',['Contra reembolso','Tarjeta Visa'],value=DataBase.getFormaPago()),
form.Checkbox('aceptacion', form.Validator("Acepta las clausulas", lambda i: i == 'true'), value='true'),
form.Button('submit',type="submit", description="Enviar"),
validators = [
form.Validator("Las pass no coinciden", lambda i: i.password == i.password2)]
)
formulariomodificar = self.registro()
return render.modificar(form=cabecera,enlaces=session.get('enlaces'),modificar="<form name=\"main\" method=\"post\"> "+formulariomodificar.render()+"</form>")
示例7: login
def login(usuario,contrasena):
if usuario=="" or contrasena=="" or usuario==None or contrasena==None:
return False
elif usuario == DataBase.getNombre() and contrasena == DataBase.getPassword():
return True
else:
return False
示例8: add_process
def add_process(self, data):
data_base = DataBase(self.key)
print data[3]
if not data_base.is_process_exist(data[3], data[1]):
# client name, process name, process signature, classification
data_base.add_row_to_table("Classification", [data_base.classification_id_counter, data[3], data[1], str(data[2]), int(data[0])])
return "Process " + data[1] + " added to client " + data[3] + " with classification " + data[0]
return "Process already exists"
示例9: aanmelden
def aanmelden(self, controller):
if self.naam.get() == '' or self.email.get() == '':
self.error.configure(text='Vul alle gegevens in.')
else:
api = Api()
db = DataBase()
ucode = uuid4().hex
db.saveFilm(self.data["titel"], self.data["aanbieder"], api.getCurrentTime(), ucode, self.naam.get(), self.email.get())
controller.show_frame(qrFrame, ucode)
示例10: POST
def POST(self):
formulariomodificar = self.registro()
cabecera = "Bienvenido "+session.usuario+" <a href=\"salir\">SALIR</a> <li><a href=\"modificar\">Modificar</a><li>"
if formulariomodificar.validates():
DataBase.insertar(formulariomodificar.d.nombre,formulariomodificar.d.apellidos,formulariomodificar.d.correo,formulariomodificar.d.dianacimiento,formulariomodificar.d.mesnacimiento,
formulariomodificar.d.anonacimiento,formulariomodificar.d.direccion,formulariomodificar.d.password,formulariomodificar.d.visa,formulariomodificar.d.formapago)
return render.modificar(form=cabecera,enlaces=session.get('enlaces'),modificar="<p>TODO INSERTADO</p><form name=\"main\" method=\"post\"> "+formulariomodificar.render()+"</form>")
else:
return render.modificar(form=cabecera,enlaces=session.get('enlaces'),modificar="<form name=\"main\" method=\"post\"> "+formulariomodificar.render()+"</form>")
示例11: remove_process
def remove_process(self, data):
data_base = DataBase(self.key)
print data[0]
print data[1]
# clint name, process name
primary_key = data_base.get_primary_key(data[1], data[0])
print primary_key
# classification_ID
data_base.delete_row("Classification", primary_key)
return "Process removed"
示例12: __init__
class ServerSocket:
def __init__(self): #Constructor
self.server_socket = socket.socket()
self.server_socket.bind(('0.0.0.0', 1729))
self.server_socket.listen(10)
self.open_client_sockets = []
self.database = DataBase()
def handle_clients(self): #handle all the clients using the service
while True:
read_list , write_list, error_list = select.select([self.server_socket]+ self.open_client_sockets, [], [])
for current_socket in read_list:
if current_socket is self.server_socket:
(new_socket , address) = self.server_socket.accept()
self.open_client_sockets.append(new_socket)
else:
data = current_socket.recv(1024)
if data =="":
self.open_client_sockets.remove(current_socket)
print "connection with client close"
else :
datalist = self.unpack_command(data)
current_socket.send(self.handle_command(datalist))
def unpack_command(self, command): #unpacking command parts like command itself, parameters , parameters' number
params = []
details = command.split('#')
command = details[0]
param_number = int(details[1])
for x in xrange(param_number):
params.append(details[x+2])
return [command, param_number, params]
#region fill it
def send_list(self, client_name, classification):
return self.database.get_list(client_name, classification)
def remove_process(self, classification_ID):
self.database.delete_row("Classification", classification_ID)
return "process removed"
def update_process(self, param, value, classification_ID):
self.database.update_table("Classification", param, value, classification_ID)
return "process update"
#endregion
def handle_command(self, datalist): #call the right command from the dictionary
commands_dict = {"GetWhiteList": self.send_list(datalist[2][0], datalist[2][1]), "GetBlackList": self.send_list(datalist[2][0], datalist[2][1]), "RemoveProcess": self.remove_process(datalist[2][0]), "UpdateProcess": self.update_process(datalist[2][0], datalist[2][1], datalist[2][2])}
if (datalist[1] in commands_dict.keys()):
return commands_dict[datalist[0]]
示例13: __cache
def __cache(self, url, path, ids):
'''
缓存数据
'''
list = []
tagCasts = DataBase().tagCasts
if not os.path.exists(path):
os.mkdir(path)
for iid in ids:
# 标签EPC映射
castedId = tagCasts.has_key(iid) and tagCasts[iid] or iid
id = re.compile(r'^0+').sub('', castedId)
newUrl = url + str(id)
data = urllib2.urlopen(newUrl).read()
data = json.loads(data)
data['EPC'] = iid
qrCodes = DataBase().qrCodes
data['qrCode'] = qrCodes.has_key(iid) and qrCodes[iid] or None
# 缓存数据中的图片
if data['code'] == 200:
# 缓存产品图片
data = self.cacheImgs(path, data, id, u'goods_img')
# threading.Thread(target=self.cacheImgs, args=(data, id, u'goods_Img')).start()
# 缓存商品颜色图片
data = self.cacheImgs(path, data, id, u'goods')
# threading.Thread(target=self.cacheImgs, args=(data, id, u'goods')).start()
# 缓存商标logo
data = self.cacheImgs(path, data, id, u'brand_ico')
# threading.Thread(target=self.cacheImgs, args=(data, id, u'brand_ico')).start()
# 缓存默认商品图片
data = self.cacheImgs(path, data, id, u'goodsDefault')
# threading.Thread(target=self.cacheImgs, args=(data, id, u'goodsDefault')).start()
# 缓存促销banner图片
data = self.cacheImgs(path, data, id, u'promotion_banner')
# threading.Thread(target=self.cacheImgs, args=(data, id, u'promotion_banner')).start()
# 缓存同等商品图片
data = self.cacheImgs(path, data, id, u'sameGoods')
# threading.Thread(target=self.cacheImgs, args=(data, id, u'sameGoods')).start()
list.append(data)
# 安排每5分钟运行一次自己
self.schedule.enter(300, 0, self.__cache, (url, path, ids))
return list
示例14: addAluno
def addAluno(self, turma, aluno):
"""Add aluno relacionado a turma direto no bd"""
if DataBase.addTurma_Aluno(turma, aluno):
self.carregarAluno(self.getTurma())
return True
else:
return False
示例15: listaDb
def listaDb(self):
"""Returna uma lista com todos as disciplinas do BD"""
lista = DataBase.getListDbDisciplina()
if lista == None:
return ()
else:
return lista