Skip to content

Commit

Permalink
scripts: Convert archive.py to Python 3
Browse files Browse the repository at this point in the history
The changes are mostly mechanically converting str to bytes.
  • Loading branch information
zeux committed Nov 26, 2020
1 parent a3ae05c commit 7a9da11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ docs: docs/quickstart.html docs/manual.html

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

$(EXECUTABLE): $(OBJECTS)
$(CXX) $(OBJECTS) $(LDFLAGS) -o $@
Expand Down
12 changes: 6 additions & 6 deletions scripts/archive.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import io
import os.path
import sys
import tarfile
import time
import zipfile
import StringIO

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

if '\0' not in data:
data = data.replace('\r', '')
if b'\0' not in data:
data = data.replace(b'\r', b'')
if use_crlf:
data = data.replace('\n', '\r\n')
data = data.replace(b'\n', b'\r\n')

return data

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

def write_tar(target, arcprefix, timestamp, sources, compression):
Expand All @@ -35,7 +35,7 @@ def write_tar(target, arcprefix, timestamp, sources, compression):
info = tarfile.TarInfo(path)
info.size = len(data)
info.mtime = timestamp
archive.addfile(info, StringIO.StringIO(data))
archive.addfile(info, io.BytesIO(data))

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

0 comments on commit 7a9da11

Please sign in to comment.