diff options
author | Simon Tatham <anakin@pobox.com> | 2020-08-26 21:13:29 +0100 |
---|---|---|
committer | Simon Tatham <anakin@pobox.com> | 2020-08-26 21:13:29 +0100 |
commit | 558d8cf7cd971c024a1eee0221e0dc1c952039f0 (patch) | |
tree | 149a2ea05fd809e37294e64ceecf18f158f74f7c | |
parent | 1c1c3850e8a54938f41afb5e49a9176b229a3a88 (diff) | |
download | wix-on-linux-558d8cf7cd971c024a1eee0221e0dc1c952039f0.tar.gz wix-on-linux-558d8cf7cd971c024a1eee0221e0dc1c952039f0.tar.bz2 wix-on-linux-558d8cf7cd971c024a1eee0221e0dc1c952039f0.zip |
Migrate Python code to Python 3.
-rwxr-xr-x | makecab.py | 30 | ||||
-rwxr-xr-x | wrapper.py | 2 |
2 files changed, 17 insertions, 15 deletions
@@ -1,4 +1,4 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
2 | 2 | ||
3 | import sys | 3 | import sys |
4 | import os | 4 | import os |
@@ -10,7 +10,7 @@ from collections import namedtuple | |||
10 | CFHEADER_s = struct.Struct("<4sLLLLLBBHHHHH") | 10 | CFHEADER_s = struct.Struct("<4sLLLLLBBHHHHH") |
11 | CFHEADER = namedtuple("CFHEADER", "sig res0 size res1 firstfile res2 " | 11 | CFHEADER = namedtuple("CFHEADER", "sig res0 size res1 firstfile res2 " |
12 | "verminor vermajor folders files flags setid icabinet") | 12 | "verminor vermajor folders files flags setid icabinet") |
13 | CFHEADER_sig = "MSCF" | 13 | CFHEADER_sig = b"MSCF" |
14 | 14 | ||
15 | CFFOLDER_s = struct.Struct("<LHH") | 15 | CFFOLDER_s = struct.Struct("<LHH") |
16 | CFFOLDER = namedtuple("CFFOLDER", "firstdata ndata compresstype") | 16 | CFFOLDER = namedtuple("CFFOLDER", "firstdata ndata compresstype") |
@@ -26,7 +26,7 @@ def mszip(data): | |||
26 | zlib.DEF_MEM_LEVEL, zlib.Z_DEFAULT_STRATEGY) | 26 | zlib.DEF_MEM_LEVEL, zlib.Z_DEFAULT_STRATEGY) |
27 | compressed = compressor.compress(data) | 27 | compressed = compressor.compress(data) |
28 | compressed += compressor.flush() | 28 | compressed += compressor.flush() |
29 | return "CK" + compressed # add MSZIP header | 29 | return b"CK" + compressed # add MSZIP header |
30 | 30 | ||
31 | def packdate(y,m,d): | 31 | def packdate(y,m,d): |
32 | return ((y - 1980) << 9) | (m << 5) | d | 32 | return ((y - 1980) << 9) | (m << 5) | d |
@@ -34,19 +34,20 @@ def packtime(h,m,s): | |||
34 | return ((h << 11) | (m << 5) | (s >> 1)) | 34 | return ((h << 11) | (m << 5) | (s >> 1)) |
35 | 35 | ||
36 | def checksum(data): | 36 | def checksum(data): |
37 | data_full_words = data[:len(data) & ~3] | 37 | data_fullwords_len = len(data) & ~3 |
38 | data_last_word = data[len(data_full_words):] | 38 | data_last_word = data[data_fullwords_len:] |
39 | data_last_word = "".join(reversed(data_last_word)) | 39 | data_last_word = bytes(reversed(data_last_word)) |
40 | data_last_word += "\0" * (3 & -len(data)) # pad to multiple of 4 bytes | 40 | data_last_word += b"\0" * (3 & -len(data)) # pad to multiple of 4 bytes |
41 | data = data_full_words + data_last_word | ||
42 | toret = 0 | 41 | toret = 0 |
43 | for offset in xrange(0, len(data), 4): | 42 | for part, partlen in ((data, data_fullwords_len), |
44 | toret ^= struct.unpack_from("<L", data, offset)[0] | 43 | (data_last_word, len(data_last_word))): |
44 | for offset in range(0, partlen, 4): | ||
45 | toret ^= struct.unpack_from("<L", part, offset)[0] | ||
45 | return toret | 46 | return toret |
46 | 47 | ||
47 | def build_cab(files): | 48 | def build_cab(files): |
48 | uncompressed_data = "" | 49 | uncompressed_data = b"" |
49 | fileheaders = "" | 50 | fileheaders = b"" |
50 | for name, data, mtime in files: | 51 | for name, data, mtime in files: |
51 | mtime_u = time.gmtime(mtime) | 52 | mtime_u = time.gmtime(mtime) |
52 | fileheader = CFFILE( | 53 | fileheader = CFFILE( |
@@ -54,9 +55,10 @@ def build_cab(files): | |||
54 | date=packdate(mtime_u.tm_year, mtime_u.tm_mon, mtime_u.tm_mday), | 55 | date=packdate(mtime_u.tm_year, mtime_u.tm_mon, mtime_u.tm_mday), |
55 | time=packtime(mtime_u.tm_hour, mtime_u.tm_min, mtime_u.tm_sec)) | 56 | time=packtime(mtime_u.tm_hour, mtime_u.tm_min, mtime_u.tm_sec)) |
56 | uncompressed_data += data | 57 | uncompressed_data += data |
57 | fileheaders += CFFILE_s.pack(*fileheader) + name + "\0" | 58 | fileheaders += CFFILE_s.pack(*fileheader) |
59 | fileheaders += name.encode("ASCII") + b"\0" | ||
58 | 60 | ||
59 | compressed_data = "" | 61 | compressed_data = b"" |
60 | offset = 0 | 62 | offset = 0 |
61 | n_data_blocks = 0 | 63 | n_data_blocks = 0 |
62 | while offset < len(uncompressed_data): | 64 | while offset < len(uncompressed_data): |
@@ -1,4 +1,4 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
2 | 2 | ||
3 | import sys | 3 | import sys |
4 | import os | 4 | import os |