Exemple #1
0
def get_list():
    column = ('id,sn,ip,hostname,idc_id,purchase_date,warranty,'
              'vendor,model,admin,business,cpu,ram,disk,os,status')
    columns = column.split(',')
    sql = 'select * from assets where status = 0'
    count, rt_list = execute_sql(sql, fetch=True)
    asset_list = [dict(zip(columns, asset)) for asset in rt_list]
    return asset_list
Exemple #2
0
def vilidate_login(username, password):
    sql = 'select * from user where username=%s and password=md5(%s)'
    args = (username, password)
    count, rt_list = execute_sql(sql, args, fetch=True)
    if count == 1:
        return True
    else:
        return False
Exemple #3
0
def get_user():
    columns = ("id", "username", "password", "job", "age")
    sql = 'select * from user'
    user_list = []
    count, rt_list = execute_sql(sql, fetch=True)
    for user in rt_list:
        user_list.append(dict(zip(columns, user)))
    return user_list
Exemple #4
0
def get_accesslog(topn=10):
    columns = ("id", "ip", "url", "status", "count")
    sql = 'select * from accesslog limit %s'
    args = (topn, )
    accesslog_list = []
    count, rt_list = execute_sql(sql, args=args, fetch=True)
    for item in rt_list:
        accesslog_list.append(dict(zip(columns, item)))
    return accesslog_list
Exemple #5
0
def get_user_by_id(uid):
    columns = ("id", "username", "password", "job", "age")
    sql = 'select * from user where id=%s'
    args = (uid, )
    user_list = []
    count, rt_list = execute_sql(sql, args=args, fetch=True)
    for user in rt_list:
        user_list.append(dict(zip(columns, user)))
    return user_list
Exemple #6
0
def create_asset(asset_dict):
    sql = 'insert into assets(sn,ip,hostname,idc_id,purchase_date,warranty,vendor,' \
          'model,admin,business,cpu,ram,disk,os) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
    args_list = []
    lists = [
        'sn', 'ip', 'hostname', 'idc_id', 'purchase_date', 'warranty',
        'vendor', 'model', 'admin', 'business', 'cpu', 'ram', 'disk', 'os'
    ]
    for i in lists:
        args_list.append(asset_dict.get('_' + i))
    count, rt_list = execute_sql(sql, args=args_list, fetch=False)
    return count != 0
Exemple #7
0
def get_asset_by_sn(sn):
    column = ('id,sn,ip,hostname,idc_id,purchase_date,warranty,'
              'vendor,model,admin,business,cpu,ram,disk,os,status')
    columns = column.split(',')
    sql = 'select * from assets where sn=%s'
    args = (sn, )
    count, rt_list = execute_sql(sql, args)
    asset_list = [dict(zip(columns, asset)) for asset in rt_list]
    if count != 0:
        return asset_list[0]
    else:
        return []
Exemple #8
0
def update_asset(sn, asset_dict):
    sql = "update assets set ip=%s,hostname=%s,idc_id=%s,purchase_date=%s,warranty=%s," \
          "vendor=%s,model=%s,admin=%s,business=%s,cpu=%s,ram=%s,disk=%s,os=%s where sn=%s"
    args_list = []
    lists = [
        'ip', 'hostname', 'idc_id', 'purchase_date', 'warranty', 'vendor',
        'model', 'admin', 'business', 'cpu', 'ram', 'disk', 'os'
    ]
    for i in lists:
        args_list.append(asset_dict.get('_' + i))
    args_list.append(sn)
    count, rt_list = execute_sql(sql, args=args_list, fetch=False)
    return count != 0
Exemple #9
0
def vilidate_find(username, passwd, age, job):
    if not username:
        return True, u'用户名不能为空'
    sql = "select username from user where username=%s"
    args = (username, )
    count, rt_list = execute_sql(sql, args, fetch=True)
    if count != 0:
        return True, u'用户名已存在'
    if not passwd:
        return True, u'密码不能为空'
    if not age:
        return True, u'年龄不能为空'
    if not job:
        return True, u'职务不能为空'
    return False, ''
Exemple #10
0
def user_update(uid, age, job):
    sql = 'update user set job=%s,age=%s where id=%s;'
    args = (job, age, uid)
    count, rt_list = execute_sql(sql, args=args, fetch=False)
    return count != 0
Exemple #11
0
def user_delete(uid):
    sql = 'delete from user where id=%s' % uid
    count, rt_list = execute_sql(sql, fetch=False)
    return count != 0
Exemple #12
0
def add_user(username, passwd, age, job):
    sql = 'insert into user(username,password,job,age) values(%s,md5(%s),%s,%s)'
    args = (username, passwd, job, age)
    count, rt_list = execute_sql(sql, args=args, fetch=False)
    return count != 0
Exemple #13
0
def change_user_passwd(userid, user_passwd):
    sql = 'update user set password=md5(%s) where id=%s'
    args = (user_passwd, userid)
    count, rt_list = execute_sql(sql, args=args, fetch=False)
    return count != 0
Exemple #14
0
def get_idc():
    sql = 'select id,name from idcs where status = 0'
    count, rt_list = execute_sql(sql, fetch=True)
    return rt_list
Exemple #15
0
def delete_asset(aid):
    sql = 'update assets set status=1 where id=%s'
    args = (aid, )
    count, rt_list = execute_sql(sql, args=args, fetch=False)
    return count != 0