Пример #1
0
    def _generate_file_list_table(self):
         with self.file_list_col as db_col:
            sql = """SELECT _id, 
                            fid, 
                            server_path, 
                            file_name, 
                            isdir, 
                            state, 
                            file_category, 
                            parent_path, 
                            file_md5, 
                            server_ctime, 
                            server_mtime, 
                            client_ctime, 
                            client_mtime,
                            file_size
                    FROM cachefilelist;"""
            db_col.execute_sql(sql)
            while db_col.has_rest():
                try:
                    f = model_nd.NDFileList()
                    f.set_value_with_idx(f.account, self.using_account.account_id)
                    f.set_value_with_idx(f.file_name, db_col.get_string(3))
                    f.set_value_with_idx(f.file_hash, db_col.get_string(8))
                    f.set_value_with_idx(f.file_size, db_col.get_int64(13))
                    f.set_value_with_idx(f.create_time, db_col.get_int64(10))
                    f.set_value_with_idx(f.server_path, db_col.get_string(2))

                    self.model_nd_col.db_insert_filelist(f.get_values())
                except Exception as e:
                    pass
            self.model_nd_col.db_commit()
Пример #2
0
    def __decode_recover_net_disk_file(self):
        if not self.file_list_recover_col.is_valid():
            return
        ts = self.file_list_recover_col.fetch_table(
            'metadata', {
                "normalized_path": "Text",
                "metadata_last_modified_date": "Float",
                "metadata_client_mtime": "Float",
                "metadata_path": "Text",
                "file_content_hash": "Text",
                "metadata_total_bytes": "Int",
            })
        for rec in self.file_list_recover_col.read_deleted_record(ts):
            try:
                f = model_nd.NDFileList()
                f.set_value_with_idx(f.account, self.using_account.account_id)
                f.set_value_with_idx(
                    f.file_name,
                    self.__process_file_name(rec['normalized_path'].Value))
                f.set_value_with_idx(f.file_hash,
                                     rec['file_content_hash'].Value)
                f.set_value_with_idx(f.file_size,
                                     rec['metadata_total_bytes'].Value)
                f.set_value_with_idx(f.create_time,
                                     rec['metadata_client_mtime'].Value)
                f.set_value_with_idx(f.server_path,
                                     rec['normalized_path'].Value)
                f.set_value_with_idx(f.deleted, 1)

                self.model_nd_col.db_insert_filelist(f.get_values())
            except Exception as e:
                self.logger.error()
        self.model_nd_col.db_commit()
Пример #3
0
 def _insert_item_to_db(self, obj):
     f = model_nd.NDFileList()
     f.set_value_with_idx(f.account, self.account_id)
     f.set_value_with_idx(f.file_name, obj.get('name', None))
     f.set_value_with_idx(f.file_size, obj.get('Size', None))
     f.set_value_with_idx(f.update_time, TimeHelper.str_to_ts(obj.get('FileModifyedTime', None),
                                                              _format="%Y-%m-%dT%H:%M:%S"))
     f.set_value_with_idx(f.server_path, obj.get('Path', None))
     self.model_nd.db_insert_filelist(f.get_values())
Пример #4
0
    def __add_net_disk_file_record(self):
        with self.using_net_disk_col as db_col:
            sql = """SELECT normalized_path, 
                            metadata_last_modified_date, 
                            metadata_client_mtime, 
                            metadata_path, 
                            metadata_icon, 
                            metadata_is_deleted, 
                            file_content_hash,
                            metadata_total_bytes
                    FROM metadata
                    WHERE metadata_is_dir != 1;"""
            db_col.execute_sql(sql)
            while db_col.has_rest():
                try:

                    f = model_nd.NDFileList()
                    f.set_value_with_idx(f.account,
                                         self.using_account.account_id)
                    f.set_value_with_idx(f.server_path, db_col.get_string(3))
                    f.set_value_with_idx(
                        f.file_name,
                        self.__process_file_name(db_col.get_string(3)))
                    f.set_value_with_idx(
                        f.file_type,
                        self.__determine_file_type(
                            f.get_value_with_idx(f.file_name)))
                    f.set_value_with_idx(f.file_hash, db_col.get_string(6))
                    f.set_value_with_idx(f.file_size, db_col.get_int64(7))
                    f.set_value_with_idx(
                        f.create_time,
                        Utils.convert_timestamp(db_col.get_float(2)))
                    f.set_value_with_idx(
                        f.update_time,
                        Utils.convert_timestamp(db_col.get_float(1)))

                    self.model_nd_col.db_insert_filelist(f.get_values())
                except Exception as e:
                    self.logger.error()
            self.model_nd_col.db_commit()
Пример #5
0
    def _generate_file_list_table(self, db, account):
        if not db:
            return
        is_connected = FileList.connect(db)
        if not is_connected:
            return

        dir_type = 1
        # TODO: 待优化
        files = {obj.nid: obj for obj in FileList.objects.all}
        root = FileList()
        root.nid = '0'
        root.file_name = ''
        root.file_type = dir_type
        files[root.nid] = root

        for i in files.values():
            i.parent = files.get(i.pid, None)
        for i in files.values():
            i.server_path = self._parse_server_path(files, i) + '/' + i.file_name
            if i.server_path.startswith(r'//'):
                i.server_path = i.server_path[1:]
        for obj in files.values():
            try:
                if obj.file_type == dir_type:
                    continue
                f = model_nd.NDFileList()
                f.set_value_with_idx(f.account, account.account_id)
                f.set_value_with_idx(f.file_name, obj.file_name)
                f.set_value_with_idx(f.file_hash, obj.file_hash)
                f.set_value_with_idx(f.file_size, obj.file_size)
                f.set_value_with_idx(f.create_time, obj.ct)
                f.set_value_with_idx(f.update_time, obj.mt)
                f.set_value_with_idx(f.file_type, self._process_file_type(obj.file_category))
                f.set_value_with_idx(f.server_path, obj.server_path)
                f.set_value_with_idx(f.deleted, obj.deleted)
                self.model_nd_col.db_insert_filelist(f.get_values())
            except Exception as e:
                self.logger.error()
        self.model_nd_col.db_commit()
Пример #6
0
    def decode_recover_file_list(self):
        if not self.f_recover_helper.is_valid():
            return
        ts = self.f_recover_helper.fetch_table('cachefilelist', {
            "_id": "Int",
            "fid": "Int",
            "server_path": "Text",
            "file_name": "Text",
            "isdir": "Int",
            "state": "Int",
            "file_category": "Int",
            "parent_path": "Text",
            "file_md5": "Text",
            "server_ctime": "Int",
            "server_mtime": "Int",
            "client_ctime": "Int",
            "client_mtime": "Int",
            "file_size": "Int",
        })
        for rec in self.f_recover_helper.read_deleted_record(ts):
            if canceller.IsCancellationRequested:
                return
            try:
                f = model_nd.NDFileList()
                f.set_value_with_idx(f.account, self.using_account.account_id)
                f.set_value_with_idx(f.file_name, rec['uname'].Value)
                f.set_value_with_idx(f.file_hash, rec['file_md5'].Value)
                f.set_value_with_idx(f.file_size, rec['file_size'].Value)
                f.set_value_with_idx(f.create_time, rec['server_mtime'].Value)
                f.set_value_with_idx(f.server_path, rec['server_path'].Value)
                f.set_value_with_idx(f.deleted, 1)

                self.model_nd_col.db_insert_filelist(f.get_values())
            except Exception as e:
                pass
        self.model_nd_col.db_commit()
Пример #7
0
 def parse(self, account_folder):
     f_node = self.node.GetByPath('Documents/{}/netdisk.sqlite'.format(account_folder))
     if f_node is None:
         return
     conn = unity_c37r.create_connection_tentatively(f_node)
     cmd = sql.SQLiteCommand(conn)
     cmd.CommandText = '''
         select uk, user_name, avatar_url from feed_userlist
     '''
     reader = cmd.ExecuteReader()
     current_account = None
     if reader.Read():
         a = model_im.Account()
         a.account_id = unity_c37r.c_sharp_get_string(reader, 0)
         current_account = a.account_id
         a.username = unity_c37r.c_sharp_get_string(reader, 1)
         a.nickname = a.username
         a.photo = unity_c37r.c_sharp_get_string(reader, 2)
         self.nd.im.db_insert_table_account(a)
     else:
         raise IOError('[BAIDU NETDISK] E: NO ACCOUNT INFORMATION!')
     reader.Close()
     cmd.CommandText = '''
         select fid, server_full_path, file_name, file_size, file_md5, ctime, mtime, atime from cachefilelist
     '''
     reader = cmd.ExecuteReader()
     while reader.Read():
         f = model_nd.NDFileList()
         f.set_value_with_idx(f.account, current_account)
         f.set_value_with_idx(f.file_name, unity_c37r.c_sharp_get_string(reader, 2))
         f.set_value_with_idx(f.server_path, unity_c37r.c_sharp_get_string(reader, 1))
         f.set_value_with_idx(f.create_time, unity_c37r.c_sharp_try_get_time(reader, 5))
         f.set_value_with_idx(f.update_time, unity_c37r.c_sharp_try_get_time(reader, 6))
         f.set_value_with_idx(f.cache_time, unity_c37r.c_sharp_try_get_time(reader, 7))
         f.set_value_with_idx(f.file_hash, unity_c37r.c_sharp_get_string(reader, 4))
         f.set_value_with_idx(f.file_size, unity_c37r.c_sharp_get_long(reader, 3))
         self.nd.db_insert_filelist(f.get_values())
     reader.Close()
     self.nd.db_commit()
     cmd.CommandText = '''
         select file_name, server_full_path, file_size, blocklistmd5, trans_type, trans_status, ctime, mtime, atime, downloadlink, thumburl from transfilelist
     '''
     reader = cmd.ExecuteReader()
     while reader.Read():
         f = model_nd.NDFileTransfer()
         f.set_value_with_idx(f.account, current_account)
         f.set_value_with_idx(f.file_name, unity_c37r.c_sharp_get_string(reader, 0))
         f.set_value_with_idx(f.server_path, unity_c37r.c_sharp_get_string(reader, 1))
         f.set_value_with_idx(f.file_size, unity_c37r.c_sharp_get_long(reader, 2))
         f.set_value_with_idx(f.hash_code, unity_c37r.c_sharp_get_string(reader, 3))
         f.set_value_with_idx(f.is_download, 1)
         st = unity_c37r.c_sharp_get_long(reader, 5)
         if st == 1:
             f.set_value_with_idx(f.status, model_nd.NDFileDone)
         else:
             f.set_value_with_idx(f.status, model_nd.NDFileProcessing)
         f.set_value_with_idx(f.url, unity_c37r.c_sharp_get_string(reader, 9))
         f.set_value_with_idx(f.begin_time, unity_c37r.c_sharp_try_get_time(reader, 8))
         f_name = f.get_value_with_idx(f.file_name)
         paddern = os.path.splitext(f_name)
         if len(paddern) > 1:
             paddern = paddern[1]
         else:
             paddern = ""
         r_fname = 'Documents/{0}/Cache/{1}{2}'.format(account_folder, f.get_value_with_idx(f.hash_code), paddern)
         s_node = self.node.GetByPath(r_fname)
         if s_node is not None:
             f.set_value_with_idx(f.local_path, s_node.AbsolutePath)
         self.nd.db_insert_transfer(f.get_values())
     reader.Close()
     cmd.CommandText = '''
         select server_full_path, file_md5, file_size, ctime, mtime from image_filelist
     '''
     reader = cmd.ExecuteReader()
     while reader.Read():
         f = model_nd.NDFileList()
         f.set_value_with_idx(f.account, current_account)
         f.set_value_with_idx(f.file_name, unity_c37r.c_sharp_get_string(reader, 0))
         f.set_value_with_idx(f.server_path, f.get_value_with_idx(f.file_name))
         f.set_value_with_idx(f.create_time, unity_c37r.c_sharp_try_get_time(reader, 3))
         f.set_value_with_idx(f.update_time, unity_c37r.c_sharp_try_get_time(reader, 4))
         f.set_value_with_idx(f.file_hash, unity_c37r.c_sharp_get_string(reader, 1))
         self.nd.db_insert_filelist(f.get_values())
     self.nd.db_commit()
     reader.Close()
     cmd.CommandText = '''
         select from_uk, server_fullpath, server_filename, size, server_mtime, server_ctime, dlink, uname, msg_time from Mbox_groupfile_share
     '''
     reader = cmd.ExecuteReader()
     while reader.Read():
         s = model_nd.NDFileShared()
         s.set_value_with_idx(s.account, current_account)
         s.set_value_with_idx(s.file_name, unity_c37r.c_sharp_get_string(reader, 2))
         s.set_value_with_idx(s.server_path, unity_c37r.c_sharp_get_string(reader, 1))
         s.set_value_with_idx(s.file_size, unity_c37r.c_sharp_get_long(reader, 3) )
         s.set_value_with_idx(s.sender_id, unity_c37r.c_sharp_get_string(reader, 0))
         s.set_value_with_idx(s.update_time, unity_c37r.c_sharp_try_get_time(reader, 4))
         s.set_value_with_idx(s.create_time, unity_c37r.c_sharp_try_get_time(reader, 5))
         s.set_value_with_idx(s.url, unity_c37r.c_sharp_get_string(reader, 6))
         s.set_value_with_idx(s.sender_name, unity_c37r.c_sharp_get_string(reader, 7))
         s.set_value_with_idx(s.send_time, unity_c37r.c_sharp_try_get_time(reader, 8))
         self.nd.db_insert_shared(s.get_values())
     reader.Close()
     self.nd.db_commit()
     cmd.CommandText = '''
         select gid, name, uname, uk, avatarurl, ctime from Mbox_group
     '''
     reader = cmd.ExecuteReader()
     grp_dict = dict()
     while reader.Read():
         grp = model_im.Chatroom()
         grp.account_id = current_account
         grp.chatroom_id = unity_c37r.c_sharp_get_string(reader, 0)
         grp.name = unity_c37r.c_sharp_get_string(reader, 1)
         grp.owner_id = unity_c37r.c_sharp_get_string(reader, 3)
         grp.photo = unity_c37r.c_sharp_get_string(reader, 4)
         grp.create_time = unity_c37r.c_sharp_try_get_time(reader, 5)
         grp_dict[grp.chatroom_id] = grp
         self.nd.im.db_insert_table_chatroom(grp)
     self.nd.im.db_commit()
     reader.Close()
     cmd.CommandText = '''
         select gid, ctime, uk, uname, nick_name, avatar_url from Mbox_group_member
     '''
     reader = cmd.ExecuteReader()
     while reader.Read():
         gm = model_im.ChatroomMember()
         gm.account_id = current_account
         gm.chatroom_id = unity_c37r.c_sharp_get_string(reader, 0)
         gm.member_id = unity_c37r.c_sharp_get_string(reader, 2)
         gm.display_name = unity_c37r.c_sharp_get_string(reader, 3)
         gm.photo = unity_c37r.c_sharp_get_string(reader, 5)
         self.nd.im.db_insert_table_chatroom_member(gm)
     # add system message
     gm = model_im.ChatroomMember()
     gm.account_id = current_account
     gm.member_id = 0
     gm.display_name = u'系统消息'
     self.nd.im.db_insert_table_chatroom_member(gm)
     self.nd.im.db_commit()
     reader.Close()
     # group messages
     cmd.CommandText = '''
         select gid, msgid, msguk, time, content, username from mbox_groupmsg
     '''
     reader = cmd.ExecuteReader()
     while reader.Read():
         m = model_im.Message()
         m.talker_id = unity_c37r.c_sharp_get_string(reader, 0)
         if grp_dict.__contains__(m.talker_id):
             m.talker_name = grp_dict[m.talker_id].name
         m.msg_id = unity_c37r.c_sharp_get_string(reader, 1)
         m.sender_id = unity_c37r.c_sharp_get_string(reader, 2)
         m.send_time = unity_c37r.c_sharp_try_get_time(reader, 3)
         m.content = unity_c37r.c_sharp_get_string(reader, 4)
         m.is_sender = 1 if current_account == m.sender_id else 0
         m.account_id = current_account
         m.type = model_im.MESSAGE_CONTENT_TYPE_TEXT
         self.nd.im.db_insert_table_message(m)
     self.nd.im.db_commit()
     reader.Close()
     cmd.CommandText = '''
         select uk, uname, avatarurl from mbox_newfriendunreadlist
     '''
     reader = cmd.ExecuteReader()
     while reader.Read():
         f = model_im.Friend()
         f.account_id = current_account
         f.friend_id = unity_c37r.c_sharp_get_string(reader, 0)
         f.photo = unity_c37r.c_sharp_get_string(reader, 2)
         f.nickname = unity_c37r.c_sharp_get_string(reader, 1)
         self.nd.im.db_insert_table_friend(f)
     self.nd.im.db_commit()
     reader.Close()
     cmd.CommandText = '''
         select msgid, msguk, is_receive, time, content, username from mbox_msg
     '''
     reader = cmd.ExecuteReader()
     while reader.Read():
         m = model_im.Message()
         m.is_sender = unity_c37r.c_sharp_get_long(reader, 2)
         m.msg_id = unity_c37r.c_sharp_get_string(reader, 0)
         m.talker_id = unity_c37r.c_sharp_get_string(reader, 1)
         if m.is_sender == 0:
             m.sender_id = m.talker_id
         else:
             m.sender_id = current_account
         m.account_id = current_account
         m.content = unity_c37r.c_sharp_get_string(reader, 4)
         m.send_time = unity_c37r.c_sharp_try_get_time(reader, 3)
         m.talker_name = unity_c37r.c_sharp_get_string(reader, 5)
         m.type = model_im.MESSAGE_CONTENT_TYPE_TEXT
         self.nd.im.db_insert_table_message(m)
     self.nd.im.db_commit()
     reader.Close()