Ejemplo n.º 1
0
    def DbGetInfoByFid(self, fid):
        '''
        通过file_id获取文件信息
        :param fid:file_id
        :return:
        '''
        file_id = binascii.a2b_hex(fid.lower())

        file_info = MysqlDB().select("ppc_tenant_files",
                                     "*",
                                     file_id=str(file_id))

        if len(file_info) != 0:
            size = file_info[0][5]
            md5 = binascii.b2a_hex(file_info[0][4])
            # binascii.b2a_hex(data):将二进制数据字符串转换为十六进制编码
            source_url = file_info[0][13]
            active_prefix_id = file_info[0][12]
            prefix_list = MysqlDB().select("ppc_tenant_url_prefix",
                                           "url_prefix",
                                           id=active_prefix_id)
            # ppc_tenant_files中的active_prefix_id与ppc_url_prefix中的id相对应
            file_url = "http://" + prefix_list[0][0] + file_info[0][2]
            sourcetype_list = MysqlDB().select("ppc_tenant_source",
                                               "source_type",
                                               id=file_info[0][1])
            # sid=file_info[0][1], ppc_tenant_files中的sid与ppc_user_source中的id相对应
            source_type = sourcetype_list[0][0]
            ext = file_info[0][14]  # ?
            relative_url = file_info[0][2]

            return (size, md5, source_url, file_url, source_type, ext,
                    relative_url)
        else:
            return file_info
Ejemplo n.º 2
0
def db_get_info_by_source_url(source):
    """
    通过文件的source_url获取文件信息
    :param source:source_url
    :return:
    """
    if source.startswith('http://'):
        source_url = source
    else:
        source_url = "http://" + source

    file_info = MysqlDB().select("ppc_tenant_files", "*", source=str(source_url))

    if len(file_info) != 0:
        file_id = binascii.b2a_hex(file_info[0][3]).upper()
        file_size = file_info[0][5]
        active_prefix_id = file_info[0][12]
        prefix_list = MysqlDB().select("ppc_tenant_url_prefix", "url_prefix", id=active_prefix_id)
        # ppc_tenant_files中的id与ppc_tenant_url_prefix中的active_prefix_id相对应
        file_url = "http://" + prefix_list[0][0] + file_info[0][2]
        sourcetype_list = MysqlDB().select("ppc_tenant_source", "source_type", id=file_info[0][1])
        # sid=file_info[0][1], ppc_tenant_files中的sid与ppc_tenant_source中的id相对应
        source_type = sourcetype_list[0][0]
        file_source = file_info[0][13]
        psize = file_info[0][6]
        ppc = file_info[0][7]

        return file_id, file_size, file_url, source_type, file_source, psize, ppc
    else:
        return file_info
Ejemplo n.º 3
0
    def DbCheckFileExist(self, userid, filepath, source_type=None):
        '''
        检测指定用户的指定文件是否存在
        :param userid:用户id
        :param filepath:文件路径
        :param source_type:用户的数据源类型
        :return:响应
        '''
        if source_type in (None, ""):
            source_type = "OSS"

        ids = MysqlDB().select("ppc_tenant_source",
                               "id",
                               tenant_id=int(userid),
                               source_type=str(source_type))
        sid = ids[0][0]  # ppc_user_files中的sid与ppc_user_source中的id相对应
        results = MysqlDB().select("ppc_tenant_files",
                                   "*",
                                   sid=int(sid),
                                   relative_url=str(filepath))

        if len(results) > 0:
            return True
        else:
            return False
Ejemplo n.º 4
0
def db_delete_ops_host(host_id=None):
    """
    通过host_id在ops_host中删除对应记录,若无host_id传入,将清空整张表,清表请慎重
    :param host_id:
    :return:
    """
    if host_id is None:
        MysqlDB(database=MYSQL_CONTROL).delete('ops_host')
    else:
        MysqlDB(database=MYSQL_CONTROL).delete('ops_host', host_id=host_id)
Ejemplo n.º 5
0
def db_create_prefix(prefix, uid=""):
    """
    往ppc_tenant_url_prefix中插入数据
    :param prefix:
    :param uid:用户id
    :return:
    """
    if (uid is not None) and (uid != ""):
        MysqlDB().insert("ppc_tenant_url_prefix", url_prefix=str(prefix), tenant_id=int(uid))
    else:
        MysqlDB().insert("ppc_tenant_url_prefix", url_prefix=str(prefix))
Ejemplo n.º 6
0
def db_update_ops_host_info(update_key, update_value, host_id=None):
    """

    :param update_key:
    :param update_value:
    :param host_id:
    :return:
    """
    if host_id is None:
        MysqlDB(database=MYSQL_CONTROL).update('ops_host_info', update_key, update_value)
    else:
        MysqlDB(database=MYSQL_CONTROL).update('ops_host_info', update_key, update_value, host_id=host_id)
Ejemplo n.º 7
0
def db_update_ops_host(update_key, update_value, host_id=None):
    """
    将某个数据库中所有数据的某个字段的值更新,若传入参数host_id,则只更新host_id对应的数据
    :param update_key:
    :param update_value:
    :param host_id:
    :return:
    """
    if host_id is None:
        MysqlDB(database=MYSQL_CONTROL).update('ops_host', update_key, update_value)
    else:
        MysqlDB(database=MYSQL_CONTROL).update('ops_host', update_key, update_value, host_id=host_id)
Ejemplo n.º 8
0
 def DbCreatePrefix(self, prefix, uid=""):
     '''
     往ppc_tenant_url_prefix中插入数据
     :param prefix:
     :param uid:用户id
     :return:
     '''
     if (uid is not None) and (uid != ""):
         MysqlDB().insert("ppc_tenant_url_prefix",
                          url_prefix=str(prefix),
                          tenant_id=int(uid))
     else:
         MysqlDB().insert("ppc_tenant_url_prefix", url_prefix=str(prefix))
Ejemplo n.º 9
0
def db_delete_user(username):
    """
    将指定用户的数据从mysql数据库中删除
    :param username:用户名
    :return:void
    """
    MysqlDB().delete("ppc_users", username=str(username))
Ejemplo n.º 10
0
def db_delete_flv_by_url(url):
    """
    根据文件的url信息,在ppc_tenant_live_channel中删除指定文件
    :param url:source_url
    :return:
    """
    MysqlDB().delete("ppc_tenant_live_channel", output_url=str(url))
Ejemplo n.º 11
0
def db_delete_file_by_url(url):
    """
    根据文件的url信息,在ppc_tenant_files中删除指定文件
    :param url:source_url
    :return:
    """
    MysqlDB().delete("ppc_tenant_files", source=str(url))
Ejemplo n.º 12
0
def db_get_info_by_url(prefix, relative_url):
    """
    通过url的prefix和relative_url获取文件信息
    :param prefix:
    :param relative_url:
    :return:
    """
    prefix_info = MysqlDB().select("ppc_tenant_url_prefix", "*", url_prefix=str(prefix))
    file_info = MysqlDB().select("ppc_tenant_files", "*", active_prefix_id=prefix_info[0][0],
                                 relative_url=str(relative_url))
    file_id = binascii.b2a_hex(file_info[0][3]).upper()
    size = file_info[0][5]
    md5 = binascii.b2a_hex(file_info[0][4])
    file_url = prefix_info[0][2] + file_info[0][2]
    # file_url由ppc_url_prefix中的prefix和ppc_user_files中的relative_url组成
    return file_id, size, md5, file_url
Ejemplo n.º 13
0
def db_delete_host_current_server(host_id):
    """
    通过host_id在ops_host_info中删除对应记录
    :param host_id:
    :return:
    """
    MysqlDB(database=MYSQL_CONTROL).delete('ops_host_current_server', host_id=host_id)
Ejemplo n.º 14
0
 def DbDeletePrefix(self, prefix):
     '''
     将指定用户的数据从mysql数据库中删除
     :param prefix:
     :return:void
     '''
     MysqlDB().delete("ppc_tenant_url_prefix", url_prefix=str(prefix))
Ejemplo n.º 15
0
def db_delete_prefix(prefix):
    """
    将指定用户的数据从mysql数据库中删除
    :param prefix:
    :return:void
    """
    MysqlDB().delete("ppc_tenant_url_prefix", url_prefix=str(prefix))
Ejemplo n.º 16
0
 def DbDeleteUser(self, username):
     '''
     将指定用户的数据从mysql数据库中删除
     :param username:用户名
     :return:void
     '''
     MysqlDB().delete("ppc_users", username=str(username))
Ejemplo n.º 17
0
 def DbDeleteFileByUrl(self, url):
     """
     根据文件的url信息,在ppc_tenant_files中删除指定文件
     :param url:source_url
     :return:
     """
     MysqlDB().delete("ppc_tenant_files", source=str(url))
Ejemplo n.º 18
0
def db_delete_user_no_prefix(username):

    mysql_handle = MysqlDB()
    ids = mysql_handle.select('ppc_tenants', 'id', name=username)
    if len(ids) != 0:
        account_id = int(ids[0][0])
        mysql_handle.delete('ppc_user_group', user_id=account_id)
        mysql_handle.delete('ppc_users', username=username)
        mysql_handle.delete('ppc_tenants', name=username)
    else:
        print "#############################################"
        print "###   no such account, pls check out!     ###"
        print "#############################################"
Ejemplo n.º 19
0
def db_delete_user_file(sid, relative_url):
    """
    在ppc_tenant_files里删除指定的文件
    :param sid:
    :param relative_url:
    :return:
    """
    MysqlDB().delete("ppc_tenant_files", sid=int(sid), relative_url=str(relative_url))
Ejemplo n.º 20
0
def db_delete_file_by_md5(md5):
    """
    根据文件的MD5信息,在ppc_tenant_files中删除指定文件
    :param md5:
    :return:
    """
    md5 = binascii.a2b_hex(md5.upper())
    MysqlDB().delete("ppc_tenant_files", md5=str(md5))
Ejemplo n.º 21
0
 def DbDeleteFileByMd5(self, Md5):
     '''
     根据文件的MD5信息,在ppc_tenant_files中删除指定文件
     :param Md5:
     :return:
     '''
     md5 = binascii.a2b_hex(Md5.upper())
     MysqlDB().delete("ppc_tenant_files", md5=str(md5))
Ejemplo n.º 22
0
def db_get_ops_host_info_by_host_id(host_id):
    """
    从ops_host_info表中获取host_id对应的数据
    :param host_id:
    :return:
    """
    ids = MysqlDB(database=MYSQL_CONTROL).select("ops_host_info", "*", host_id=str(host_id))
    return ids
Ejemplo n.º 23
0
def db_delete_folder(tenant_id, dir_path):
    """
    将指定用户的数据从mysql数据库中删除
    :param tenant_id:用户id
    :param dir_path:目录路径
    :return:
    """
    MysqlDB().delete("ppc_tenant_directory", tenant_id=int(tenant_id), dir_path=str(dir_path))
Ejemplo n.º 24
0
def db_create_folder(tenant_id, dir_path):
    """
    往ppc_tenant_directory中插入数据
    :param tenant_id:用户id
    :param dir_path:目录路径
    :return:
    """
    MysqlDB().insert("ppc_tenant_directory", tenant_id=int(tenant_id), dir_path=str(dir_path))
Ejemplo n.º 25
0
def db_insert_host_current_server(server_role_id, host_id):
    """
    在ops_host_current_server中插入一条记录
    :param server_role_id:
    :param host_id:
    :return:
    """
    MysqlDB(database=MYSQL_CONTROL).insert('ops_host_current_server', server_role_id=server_role_id, host_id=host_id)
Ejemplo n.º 26
0
def db_delete_blacklist(sid, relative_url):
    """
    在ppc_files_blacklist里删除指定的文件
    :param sid:
    :param relative_url:
    :return:
    """
    MysqlDB().delete("ppc_files_blacklist", sid=int(sid), relative_url=str(relative_url))
Ejemplo n.º 27
0
 def DbGetUserIdByName(self, username):
     '''
     搜索用户相关信息
     :param username:用户名
     :return:
     '''
     ids = MysqlDB().select("ppc_users", "id", username=str(username))
     user_id = ids[0][0]  # row 1 column 1
     return user_id
Ejemplo n.º 28
0
 def DbDeleteUserFile(self, sid, relative_url):
     '''
      在ppc_tenant_files里删除指定的文件
      :param sid:
      :return:
      '''
     MysqlDB().delete("ppc_tenant_files",
                      sid=int(sid),
                      relative_url=str(relative_url))
Ejemplo n.º 29
0
def db_insert_ops_host(host_id, ip, status):
    """
    在ops_host中插入一条记录
    :param host_id:
    :param ip:
    :param status:
    :return:
    """
    MysqlDB(database=MYSQL_CONTROL).insert('ops_host', host_id=host_id, ip=ip, status=status)
Ejemplo n.º 30
0
def db_get_userid_by_name(username):
    """
    搜索用户相关信息
    :param username:用户名
    :return:
    """
    ids = MysqlDB().select("ppc_users", "id", username=str(username))
    user_id = ids[0][0]   # row 1 column 1
    return user_id