Merge pull request #1572 from pbrod/Fix_issue1571

Fixes issue 1571:
This commit is contained in:
Robin Dunn
2020-03-23 16:07:22 -07:00
committed by GitHub
38 changed files with 230 additions and 266 deletions

View File

@@ -117,7 +117,9 @@ def convert(fileName, maskClr, outputDir, outputName, outType, outExt):
else:
newname = os.path.join(outputDir,
os.path.basename(os.path.splitext(fileName)[0]) + outExt)
open(newname, "wb").write(open(fileName, "rb").read())
with open(newname, "wb") as f_out:
with open(fileName, "rb") as f_in:
f_out.write(f_in.read())
return 1, "ok"
else:
@@ -158,7 +160,8 @@ def img2py(image_file, python_file,
return
lines = []
data = b64encode(open(tfname, "rb").read())
with open(tfname, "rb") as fid:
data = b64encode(fid.read())
while data:
part = data[:72]
data = data[72:]
@@ -182,27 +185,27 @@ def img2py(image_file, python_file,
append_catalog = True
sourcePy = open(python_file, "r")
try:
for line in sourcePy:
with open(python_file, "r") as sourcePy:
try:
for line in sourcePy:
if line == "catalog = {}\n":
append_catalog = False
else:
lineMatcher = indexPattern.match(line)
if lineMatcher:
old_index.append(lineMatcher.groups()[0])
finally:
sourcePy.close()
if line == "catalog = {}\n":
append_catalog = False
else:
lineMatcher = indexPattern.match(line)
if lineMatcher:
old_index.append(lineMatcher.groups()[0])
finally:
pass
if append_catalog:
out = open(python_file, "a")
try:
out.write("\n# ***************** Catalog starts here *******************")
out.write("\n\ncatalog = {}\n")
out.write("index = []\n\n")
finally:
out.close()
with open(python_file, "a") as out:
try:
out.write("\n# ***************** Catalog starts here *******************")
out.write("\n\ncatalog = {}\n")
out.write("index = []\n\n")
finally:
pass
if python_file == '-':
out = sys.stdout

View File

@@ -626,12 +626,12 @@ class XmlResourceCompiler:
def FileToString(self, filename):
outputList = []
buffer = open(filename, "rb").read()
with open(filename, "rb") as fid:
buffer = fid.read()
fileLen = len(buffer)
linelng = 0
for i in range(len(buffer)):
for i in range(fileLen):
s = buffer[i:i+1]
c = byte2int(s)
if s == b'\n':

View File

@@ -83,8 +83,8 @@ def get_paths_dict():
def unpack_cached(cached, dest_dir):
""" Unpack from the cache."""
print('Unpack', cached, 'to', dest_dir)
tf = tarfile.open(cached, "r:*")
tf.extractall(dest_dir)
with tarfile.open(cached, "r:*") as tf:
tf.extractall(dest_dir)
dest_dir = os.listdir(dest_dir)[0]
return dest_dir