Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partially making in py3 ready #232

Merged
merged 1 commit into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 113 additions & 102 deletions afdko/Tools/SharedData/FDKScripts/BezTools.py

Large diffs are not rendered by default.

277 changes: 139 additions & 138 deletions afdko/Tools/SharedData/FDKScripts/ConvertFontToCID.py

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions afdko/Tools/SharedData/FDKScripts/FDKUtils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function, absolute_import

"""
FDKUtils.py v 1.2 April 13 6 2016
A module of functions that are needed by several of the FDK scripts.
Expand Down Expand Up @@ -37,13 +39,13 @@ def findFDKDirs():
elif curSystem == "Linux":
fdkToolsDir = os.path.join(dir, "linux")
else:
print "Fatal error: un-supported platform %s %s." % (os.name, sys.platform)
print("Fatal error: un-supported platform %s %s." % (os.name, sys.platform))
raise FDKEnvError

if not (os.path.exists(fdkScriptsDir) and os.path.exists(fdkToolsDir)):
print "Fatal error: could not find the FDK scripts dir %s and the tools directory %s." % (fdkScriptsDir, fdkToolsDir)
print("Fatal error: could not find the FDK scripts dir %s and the tools directory %s." % (fdkScriptsDir, fdkToolsDir))
raise FDKEnvError

# the FDK.py bootstrap program already adds fdkScriptsDir to the sys.path;
# this is useful only when running the calling script directly using an external Python.
if not fdkScriptsDir in sys.path:
Expand All @@ -57,22 +59,22 @@ def findFDKDirs():
def findFDKFile(fdkDir, fileName):
path = os.path.join(fdkDir, fileName)
if os.path.exists(path):
return path
p1 = path + ".exe"
if os.path.exists(p1):
return p1
p2 = path + ".cmd"
return path
p1 = path + ".exe"
if os.path.exists(p1):
return p1
p2 = path + ".cmd"
if os.path.exists(p2):
return p2
return p2
if fileName not in ["addGlobalColor"]:
print "Fatal error: could not find '%s or %s or %s'." % (path,p1,p2)
print("Fatal error: could not find '%s or %s or %s'." % (path,p1,p2))
raise FDKEnvError

def runShellCmd(cmd):
try:
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout
log = p.read()
return log
return str(log)
Copy link
Member

@anthrotype anthrotype Jan 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's wrong. log returned by subprocess is a bytes string. On py3, if you do str(b"a") without an encoding argument, you get its repr "b'a'". You want to call decode method of bytes with the encoding that the subprocess command is using to print to stdout (probably ascii or utf-8, but you have to know).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, this is really wrong... but it works. To my defence: the whole file is a mess and needs a decent fix up...

will fix it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

Copy link
Contributor Author

@typemytype typemytype Jan 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed ed87e80

except :
msg = "Error executing command '%s'. %s" % (cmd, traceback.print_exc())
print(msg)
Expand All @@ -85,12 +87,12 @@ def runShellCmdLogging(cmd):
while 1:
output = proc.stdout.readline()
if output:
print output,
print(output, end=' ')
logList.append(output)
if proc.poll() != None:
output = proc.stdout.readline()
if output:
print output,
print(output, end=' ')
logList.append(output)
break
log = "".join(logList)
Expand Down Expand Up @@ -169,13 +171,11 @@ def clean_afdko():
print("Deleted", basepath)
except:
pass
return

return

def check_afkdo():
return

if __name__ == "__main__":
clean_afdko()


Loading