def create(sn, ip, hostname, os, purchase_date, warranty, vendor, model, idcs, admin, business, cpu, mem, disk): _sql = 'insert into assets(sn, ip, hostname, os, purchase_date, warranty, vendor, model, idc_id, admin, business, cpu, mem, disk) values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' args = (sn, ip, hostname, os, purchase_date, warranty, vendor, model, idcs, admin, business, cpu, mem, disk) execute_commit_sql(_sql, args) return True
def update(ip, hostname, os, purchase_date, warranty, vendor, model, idc_id, admin, business, cpu, mem, disk, sn): _sql = 'update assets set ip=%s, hostname=%s, os=%s, purchase_date=%s, warranty=%s, vendor=%s, model=%s, idc_id=%s, admin=%s, business=%s, cpu=%s, mem=%s, disk=%s where sn=%s' args = (ip, hostname, os, purchase_date, warranty, vendor, model, idc_id, admin, business, cpu, mem, disk, sn) execute_commit_sql(_sql, args) return True
def log2db(logfile): dbutils.execute_commit_sql('DELETE FROM accesslog;') fhandler = open(logfile, 'r') rt_dict = {} # 统计 while True: line = fhandler.readline() if line == '': break nodes = line.split() ip, url, code = nodes[0], nodes[6], nodes[8] key = (ip, url, code) if key not in rt_dict: rt_dict[key] = 1 else: rt_dict[key] = rt_dict[key] + 1 fhandler.close() rt_list = [] for _key, _cnt in rt_dict.items(): rt_list.append(_key + (_cnt, )) _sql = 'insert into accesslog(ip, url, code, cnt) values (%s, %s, %s, %s)' dbutils.bulker_commit_sql(_sql, rt_list)
def delete(id): _sql = "update assets set status = 1 where id =%s" args = (id,) _cnt,_rt_list = execute_commit_sql(_sql,args) if _cnt: return True return False
def loganalysis(logfile): execute_commit_sql('delete from accesslog;') fhandler = open(logfile, 'rb') rt = {} while True: line = fhandler.readline() if line == "": break nodes = line.split() ip, url, code = nodes[0], nodes[6], nodes[8] key = (ip, url, code) if key not in rt: rt[key] = 1 else: rt[key] += 1 rt_list = rt.items() rt_data = [] for line in rt_list: lines = line[0] + (line[1], ) rt_data.append(lines) _sql = "insert into accesslog(ip,url,code,cnt) VALUES (%s,%s,%s,%s)" bulker_commit_sql(_sql, rt_data)
def create(sql_list=[]): #_sql_args = ','.join(sql_list) _sql = "insert into assets(sn,ip,hostname,os,cpu,ram,disk,idc_id,admin,business,purchase_date,warranty,model,vendor) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" args = tuple(sql_list) execute_commit_sql(_sql,args)
def update(sql_list=[]): _sql="update assets set sn=%s,ip=%s,hostname=%s,os=%s,cpu=%s,ram=%s,disk=%s,idc_id=%s,admin=%s,business=%s,purchase_date=%s,warranty=%s,model=%s,vendor=%s where id=%s" args = tuple(sql_list) execute_commit_sql(_sql,args)
def delete(aid): _sql = 'update assets set status=1 where sn=%s' args = (aid,) _cnt, _rt_list = execute_commit_sql(_sql, args) return _cnt, _rt_list
def create(sn, ip, hostname, os, purchase_date, warranty, vendor, model, idcs, admin, application, business, cpu, mem, disk): _sql = 'insert into assets(sn, ip, hostname, os, purchase_date, warranty, vendor, model, idc_id, admin, application, business, cpu, mem, disk) values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' args = (sn, ip, hostname, os, purchase_date, warranty, vendor, model, idcs, admin, application, business, cpu, mem, disk) execute_commit_sql(_sql, args) return True
def update_user(uid, name, password, age): _sql = 'update user set age=%s where id=%s' execute_commit_sql(_sql, (age, uid))
def create(sn, warranty, cpu, ram, disk, ip, idc_id): _sql = 'insert into assets(sn,warranty,cpu,ram,disk,ip,idc_id) values(%s,%s,%s,%s,%s,%s,%s)' _args = (sn, warranty, cpu, ram, disk, ip, idc_id) execute_commit_sql(_sql, _args)
def add_user(username, password, age, phone, email): _sql = 'insert into user(username, password, age, phone, email) values(%s, md5(%s), %s, %s, %s)' _args = (username, password, age, phone, email) execute_commit_sql(_sql, _args)
def update_user(uid, password, age, phone, email): _sql = 'update user set password=md5(%s), age=%s, phone=%s, email=%s where id=%s' execute_commit_sql(_sql, (password, age, phone, email, uid))
def update_user(username, password, age, id): _sql = 'update user set age=%s where id=%s' _args = (age, id) _count = execute_commit_sql(_sql, _args)
def delete(aid): _sql = 'update assets set status=1 where sn=%s' args = (aid, ) _cnt, _rt_list = execute_commit_sql(_sql, args) return _cnt, _rt_list
# encoding:utf-8
def update_user(user_age,uid): _sql = 'update user set age=%s where id=%s' _args = (user_age,uid) _count = execute_commit_sql(_sql,_args)
def change_user_password(uid, upassword): _sql = 'update user set password=md5(%s) where id=%s' execute_commit_sql(_sql, (upassword, uid))
def delete_user(uid): _sql = 'delete from user where id=%s ' _args = (uid) _count = execute_commit_sql(_sql,_args)
def add_user(name, password, age): _sql = 'insert into users(name, password, age) values(%s, md5(%s), %s)' _args = (name, password, age) execute_commit_sql(_sql, _args)
def charge_user_password(uid,user_password): _sql = 'update user set password=md5(%s) where id=%s' _args = (user_password,uid) _count = execute_commit_sql(_sql, _args)
def delete_user(uid): _sql = 'delete from user where id=%s' execute_commit_sql(_sql, (uid, ))
def update(ip, hostname, os, purchase_date, warranty, vendor, model, idc_id, admin, application, business, cpu, mem, disk, sn): _sql = 'update assets set ip=%s, hostname=%s, os=%s, purchase_date=%s, warranty=%s, vendor=%s, model=%s, idc_id=%s, admin=%s, application=%s, business=%s, cpu=%s, mem=%s, disk=%s where sn=%s' args = (ip, hostname, os, purchase_date, warranty, vendor, model, idc_id, admin, application, business, cpu, mem, disk, sn) execute_commit_sql(_sql, args) return True