Skip to content

Commit

Permalink
Builder: Updated Python scripts for version 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 15, 2018
1 parent 4b7de99 commit 3d8ad7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
27 changes: 14 additions & 13 deletions doomsday/build/scripts/buildpackage.py
@@ -1,34 +1,35 @@
#!/usr/bin/env python2.7
#
# Command line utility for zipping a directory of files into a .pack.
# Checks that the required Info file is present.
# Checks that the required Info file is present.
#
# Usage:
# buildpackage (pack-dir) (output-dir)
#

from __future__ import print_function
import sys, os, os.path, zipfile, time

if len(sys.argv) < 2:
print "Usage: %s (pack-dir) (output-dir)" % sys.argv[0]
print("Usage: %s (pack-dir) (output-dir)" % sys.argv[0])
sys.exit(0)

# Check quiet flag.
class Package:
def __init__(self, sourcePath):
self.sourcePath = sourcePath

def build(self, outputPath):
# Ensure the output path exists.
try:
os.makedirs(outputPath)
except:
pass

outputName = os.path.join(outputPath, os.path.basename(self.sourcePath))
pack = zipfile.ZipFile(outputName, 'w', zipfile.ZIP_DEFLATED)
pack = zipfile.ZipFile(outputName, 'w', zipfile.ZIP_DEFLATED)
contents = []

# Index the contents of the folder recursively.
def descend(path):
for name in os.listdir(os.path.join(self.sourcePath, path)):
Expand All @@ -40,7 +41,7 @@ def descend(path):
else:
internalPath = name
fullPath = os.path.join(self.sourcePath, internalPath)

if os.path.isfile(fullPath):
contents.append((fullPath, internalPath))
elif os.path.isdir(fullPath):
Expand All @@ -52,21 +53,21 @@ def descend(path):
for full, internal in contents:
if internal.lower() == 'info' or internal.lower() == 'info.dei':
foundInfo = True
break
break
if not foundInfo:
print "No 'Info' file found in \"%s\"!" % self.sourcePath
print("No 'Info' file found in \"%s\"!" % self.sourcePath)
sys.exit(1)

# Write entries in alphabetical order.
date_time = time.localtime(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
for full, internal in sorted(contents):
info = zipfile.ZipInfo(internal, date_time)
info.external_attr = 0644 << 16L
info.external_attr = 0o644 << 16
with open(full, 'rb') as f:
pack.writestr(info, f.read())

# Write it out.
print "Wrote %s (contains %i files)." % (outputName.replace("\\", "/"), len(pack.namelist()))
print("Wrote %s (contains %i files)." % (outputName.replace("\\", "/"), len(pack.namelist())))
pack.close()

if __name__ == "__main__":
Expand Down
9 changes: 5 additions & 4 deletions doomsday/build/scripts/packres.py
Expand Up @@ -3,11 +3,12 @@
# that Doomsday needs at runtime. The PK3 files are organized using the
# traditional data/ and defs/ structure.

from __future__ import print_function
import sys, os, os.path, zipfile

if len(sys.argv) < 2:
print "Usage: %s pk3-target-dir" % sys.argv[0]
print "(run in build/scripts/)"
print("Usage: %s pk3-target-dir" % sys.argv[0])
print("(run in build/scripts/)")
sys.exit(0)

# Check quiet flag.
Expand All @@ -27,7 +28,7 @@ def add_files(self, fileNamesArray):
self.files += fileNamesArray

def msg(self, text):
if not quietMode: print text
if not quietMode: print(text)

def create(self, name):
full_name = os.path.join(target_dir, name)
Expand Down Expand Up @@ -61,7 +62,7 @@ def process_dir(path, dest_path):
process_dir(full_src, dest)

# Write it out.
print "Created %s (with %i files)." % (os.path.normpath(full_name), len(pk3.namelist()))
print("Created %s (with %i files)." % (os.path.normpath(full_name), len(pk3.namelist())))
pk3.close()

# First up, doomsday.pk3.
Expand Down

0 comments on commit 3d8ad7a

Please sign in to comment.