Skip to content

Commit 7a9da11

Browse files
committed
scripts: Convert archive.py to Python 3
The changes are mostly mechanically converting str to bytes.
1 parent a3ae05c commit 7a9da11

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ docs: docs/quickstart.html docs/manual.html
7777

7878
build/pugixml-%: .FORCE | $(RELEASE)
7979
@mkdir -p $(BUILD)
80-
TIMESTAMP=`git show v$(VERSION) -s --format=%ct` && python scripts/archive.py $@ pugixml-$(VERSION) $$TIMESTAMP $|
80+
TIMESTAMP=`git show v$(VERSION) -s --format=%ct` && python3 scripts/archive.py $@ pugixml-$(VERSION) $$TIMESTAMP $|
8181

8282
$(EXECUTABLE): $(OBJECTS)
8383
$(CXX) $(OBJECTS) $(LDFLAGS) -o $@

scripts/archive.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1+
import io
12
import os.path
23
import sys
34
import tarfile
45
import time
56
import zipfile
6-
import StringIO
77

88
def read_file(path, use_crlf):
99
with open(path, 'rb') as file:
1010
data = file.read()
1111

12-
if '\0' not in data:
13-
data = data.replace('\r', '')
12+
if b'\0' not in data:
13+
data = data.replace(b'\r', b'')
1414
if use_crlf:
15-
data = data.replace('\n', '\r\n')
15+
data = data.replace(b'\n', b'\r\n')
1616

1717
return data
1818

@@ -24,7 +24,7 @@ def write_zip(target, arcprefix, timestamp, sources):
2424
info = zipfile.ZipInfo(path)
2525
info.date_time = time.localtime(timestamp)
2626
info.compress_type = zipfile.ZIP_DEFLATED
27-
info.external_attr = 0644 << 16L
27+
info.external_attr = 0o644 << 16
2828
archive.writestr(info, data)
2929

3030
def write_tar(target, arcprefix, timestamp, sources, compression):
@@ -35,7 +35,7 @@ def write_tar(target, arcprefix, timestamp, sources, compression):
3535
info = tarfile.TarInfo(path)
3636
info.size = len(data)
3737
info.mtime = timestamp
38-
archive.addfile(info, StringIO.StringIO(data))
38+
archive.addfile(info, io.BytesIO(data))
3939

4040
if len(sys.argv) < 5:
4141
raise RuntimeError('Usage: python archive.py <target> <archive prefix> <timestamp> <source files>')

0 commit comments

Comments
 (0)