Ejemplo n.º 1
0
 def __init__(self, file_name, bytes_wide, group_size):
     self.bytes_wide = int(bytes_wide)
     self.group_size = int(group_size)
     self.file_name = file_name
     self.file_size = get_file_size(file_name)
     self.read_count = 0
     self.abort = False
     threading.Thread.__init__(self)
Ejemplo n.º 2
0
 def __init__(self, file_name, bytes_wide, group_size):
     self.bytes_wide = int(bytes_wide)
     self.group_size = int(group_size)
     self.file_name = file_name
     self.file_size = get_file_size(file_name)
     self.read_count = 0
     self.abort = False
     threading.Thread.__init__(self)
Ejemplo n.º 3
0
def _do_img_upload(_session, batch="1", file_path=""):
    file_path = "test2.txt"
    file_name = file_path.rsplit(".", maxsplit=1)[0] + ".zip"
    with ZipFile(file_name, 'w', ZIP_DEFLATED, allowZip64=False) as zip_file:
        zip_file.write(file_path)

    file_size = get_file_size(file_name)
    with open(file_name, "rb") as f:
        _session.headers["Referer"] = YINDING_HOST + "base/custInfo.getUpload.do?random=" \
                                      + str(rand_0_1())

        # 判断资源是否上传过
        data = {
            "objName": file_name,
            "size": str(file_size),
        }
        resp = _session.post(
            YINDING_HOST + "base/custInfo.queryResourceName.do", data,
            **KWARGS)
        if resp.status_code != 200:
            raise UploadFailedException("判断资源非200")

        flag = resp.text.split(",", 1)[0]
        if flag == "-1":
            raise UploadFailedException("资源命名错误,请删除后重新上传")
        elif flag == "-2":
            raise UploadFailedException("该文件已上完成,请选择其它")
        elif flag.startswith("goOn"):
            raise UploadFailedException("资源未上传完整")
        elif flag != "1":
            raise UploadFailedException("未知错误: " + flag)

        # 上传图片
        __do_img_upload(_session, f, file_size, batch)

        # 向数据库中存入资源总大小
        data = {
            "objName": file_name + "-" + batch,
            "size": str(file_size),
        }
        resp = _session.post(YINDING_HOST + "base/resource.changeFileSize.do",
                             data, **KWARGS)
        if resp.status_code != 200:
            raise UploadFailedException("存入资源返回非200")

        # 进行文件解析
        data = {
            "custInfo.uploadBatch": batch,
            "objName": file_name,
        }
        resp = _session.post(YINDING_HOST + "base/base/custInfo.anaPicInfo.do",
                             data, **KWARGS)
        if resp.status_code != 200:
            raise UploadFailedException("文件解析返回非200")
        elif resp.text != "SUCCESS":
            raise UploadFailedException(resp.text)
Ejemplo n.º 4
0
    def __init__(self, file_name, bytes_wide, group_size, starting_address=0):
        """Initialize."""

        self.starting_address = starting_address
        self.bytes_wide = int(bytes_wide)
        self.group_size = int(group_size)
        self.file_name = file_name
        self.file_size = get_file_size(file_name)
        self.read_count = 0
        self.abort = False
        threading.Thread.__init__(self)
Ejemplo n.º 5
0
    def btn_go_clicked(self):
        try:
            algorithm = None
            if self.radio_btn_huffman_coding.isChecked():
                algorithm = CodingAlgorithms.Huffman
            elif self.radio_btn_arithmetic_coding.isChecked():
                algorithm = CodingAlgorithms.Arithmetic
            else:
                show_error_message_box(
                    'Algorimts nav izvēlēts!',
                    'Lūdzu, izvēlēties kādu no diviem algoritmiem: Huffman Coding vai Arithmetic Coding.'
                )
                return

            method = None
            if self.radio_btn_compress.isChecked():
                method = CodingMethods.Compress
            elif self.radio_btn_decompress.isChecked():
                method = CodingMethods.Decompress
            else:
                show_error_message_box(
                    'Metode nav izvēlēts!',
                    'Lūdzu, izvēlēties kādu no diviem metodēm: Saspiešana vai Dekodēšana.'
                )
                return

            input_file_path = self.input_input_file_path.text()
            if not input_file_path:
                show_error_message_box(
                    'Ievades faila cēļš nav norādīts!',
                    'Lūdzu, norādiet cēļu līdz ievades failam, ar kuru būs izdārīta saspiešana vai dekodēšana.'
                )
                return

            output_file_name = self.input_output_file_name.text()
            output_file_path = None
            if not output_file_name:
                show_error_message_box(
                    'Izvades faila nosaukums nav norādīts!',
                    'Lūdzu, norādiet ievades faila nosaukumu, kurā būs ierakstīts rezultāts.'
                )
                return
            else:
                divider = '/'
                output_file_path = '{path_to_file}{divider}{file_name}'.format(
                    path_to_file=divider.join(
                        input_file_path.split(divider)[:-1]),
                    divider=divider,
                    file_name=output_file_name)

            secret_file_path = None
            if algorithm is CodingAlgorithms.Huffman:
                if method is CodingMethods.Decompress:
                    secret_file_path = self.input_secret_file_path.text()
                    if not secret_file_path:
                        show_error_message_box(
                            'Dekodešanas faila cēļš nav norādīts!',
                            'Lūdzu, norādiet cēļu līdz dekodešanas failam priekš Huffman algoritmam.'
                        )
                        return
                else:
                    divider = '/'
                    secret_file_path = '{path_to_file}{divider}{file_name}'.format(
                        path_to_file=divider.join(
                            input_file_path.split(divider)[:-1]),
                        divider=divider,
                        file_name='decode_secret.pkl')

            # Call Coding algorithms with getting Result()
            start_time = time.time()
            if method is CodingMethods.Compress:
                compress(algorithm, input_file_path, output_file_path,
                         secret_file_path)
            else:
                decompress(algorithm, input_file_path, output_file_path,
                           secret_file_path)
            end_time = time.time()
            result = Result(input_file_size=get_file_size(input_file_path),
                            output_file_size=get_file_size(output_file_path),
                            time=end_time - start_time)
            show_message_box('Programma veiksmīgi nostrādāja!', str(result))

        except Exception as e:
            print(e)
Ejemplo n.º 6
0
    def load(cls, path):
        with open(path, "rb") as f:
            entries = OrderedDict()
            magic_code = f.read(8)
            if magic_code != b"FONTDATF":
                raise IOError(f"Invalid FIF file (magic_code={magic_code})")
            is_big_endian = read_int(f) == 1

            read_byte_f = lambda: read_byte(f, is_big_endian)
            read_short_f = lambda: read_short(f, is_big_endian)
            read_int_f = lambda: read_int(f, is_big_endian)
            read_wide_char_f = lambda: read_wide_char(f, is_big_endian)

            check_1 = read_short_f()
            if check_1 != 101:
                raise IOError(f"Invalid FIF file (check_1 {check_1} != 0x65)")

            entry_table_offset = read_short_f()
            entry_count = read_int_f()

            if get_file_size(path) != entry_table_offset + (entry_count * 16):
                raise IOError(
                    f"Invalid FIF file (file size {get_file_size(path)} is mismatch with "
                    f"entry_table_offset={entry_table_offset}, entry_count={entry_count})"
                )

            characters_per_texture = read_int_f()
            texture_count = read_short_f()
            width = read_short_f()
            height = read_short_f()
            last_width = read_short_f()
            last_height = read_short_f()
            characters_per_row = read_short_f()
            row_count = read_short_f()
            character_width = read_short_f()
            character_height = read_short_f()
            column_width = read_short_f()
            row_height = read_short_f()

            check_2 = read_short_f()
            if check_2 != character_height:
                raise IOError(
                    f"Invalid FIF file (check_2 {check_2} != character_height {character_height})"
                )

            check_3 = read_byte_f()
            if check_3 != 32:
                raise IOError(f"Invalid FIF file (check_3 {check_3} != 32)")

            check_4 = read_byte_f()
            if check_4 != 1:
                raise IOError(f"Invalid FIF file (check_4 {check_4} != 1)")

            f.seek(entry_table_offset)

            for i in range(entry_count):
                left_padding = read_int_f()
                glyph_width = read_int_f()
                right_padding = read_int_f()
                character = read_wide_char_f()
                index = read_short_f()

                if index != i:
                    raise IOError(
                        f"Invalid FIF file (index i {i} != index {index})")

                entries[character] = FifEntry(left_padding, right_padding,
                                              glyph_width)

            fif = FifFile(entries, width, height, character_width,
                          character_height, is_big_endian)
            fif.entry_table_offset = entry_table_offset
            fif.entry_count = entry_count
            fif.texture_count = texture_count
            fif.characters_per_texture = characters_per_texture
            fif.last_width = last_width
            fif.last_height = last_height
            fif.characters_per_row = characters_per_row
            fif.row_count = row_count
            fif.column_width = column_width
            fif.row_height = row_height

            return fif