mirror of
https://github.com/freedoom/freedoom.git
synced 2025-09-02 07:25:45 -04:00
bootstrap: fix bootstrap.py with python2
- import print_function - wrap buffer, which is required in py3 to read/write bytes (not strings) from stdin/stdout, but missing in py2 (gives AttributeError)
This commit is contained in:
parent
f6ea500080
commit
11b220c707
1 changed files with 18 additions and 6 deletions
|
@ -1,8 +1,21 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import sys
|
import sys
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
def read():
|
||||||
|
try:
|
||||||
|
return sys.stdin.buffer.read()
|
||||||
|
except AttributeError:
|
||||||
|
return sys.stdin.read()
|
||||||
|
|
||||||
|
def write(out):
|
||||||
|
try:
|
||||||
|
sys.stdout.buffer.write(out)
|
||||||
|
except AttributeError:
|
||||||
|
sys.stdout.write(out)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# read PLAYPAL from stdin, write minimal doom2.wad to stdout
|
# read PLAYPAL from stdin, write minimal doom2.wad to stdout
|
||||||
if sys.stdin.isatty():
|
if sys.stdin.isatty():
|
||||||
|
@ -11,7 +24,7 @@ def main():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# three lumps needed - see bootstrap/README.txt
|
# three lumps needed - see bootstrap/README.txt
|
||||||
lumps = [(b'PLAYPAL', sys.stdin.buffer.read()),
|
lumps = [(b'PLAYPAL', read()),
|
||||||
(b'TEXTURE1', struct.pack("i", 0)), # empty texture1
|
(b'TEXTURE1', struct.pack("i", 0)), # empty texture1
|
||||||
(b'PNAMES', struct.pack("i8s", 1, b''))] # single pname
|
(b'PNAMES', struct.pack("i8s", 1, b''))] # single pname
|
||||||
|
|
||||||
|
@ -23,15 +36,14 @@ def main():
|
||||||
pos += len(data)
|
pos += len(data)
|
||||||
|
|
||||||
# write wad header
|
# write wad header
|
||||||
wadheader = (b'IWAD', len(waddir), pos)
|
write(struct.pack("4sii", b'IWAD', len(waddir), pos))
|
||||||
sys.stdout.buffer.write(struct.pack("4sii", *wadheader))
|
|
||||||
|
|
||||||
# write lump contents
|
# write lump contents
|
||||||
for name, data in lumps:
|
for name, data in lumps:
|
||||||
sys.stdout.buffer.write(data)
|
write(data)
|
||||||
|
|
||||||
# write wad directory
|
# write wad directory
|
||||||
for i in waddir:
|
for i in waddir:
|
||||||
sys.stdout.buffer.write(struct.pack("ii8s", *i))
|
write(struct.pack("ii8s", *i))
|
||||||
|
|
||||||
if __name__ == "__main__": main()
|
if __name__ == "__main__": main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue