Skip to content

Commit ad038cf

Browse files
committed
Code quality and consistency updates
1 parent 55babeb commit ad038cf

File tree

8 files changed

+328
-314
lines changed

8 files changed

+328
-314
lines changed

checkUFOProcessedLayer.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright 2014 Adobe. All rights reserved.
22

33
"""
4-
For a UFO font, check that the glyph hashes stored when checkOutlines or autohint
5-
were last run still match the source glyph hashes. If not, all outdated glyphs are
6-
deleted from the Adobe processed layer.
4+
For a UFO font, check that the glyph hashes stored when checkOutlines or
5+
autohint were last run still match the source glyph hashes.
6+
If not, all outdated glyphs are deleted from the Adobe processed layer.
77
"""
88

99
__usage__ = """
@@ -26,15 +26,15 @@
2626

2727

2828
def run():
29-
fontPath = sys.argv[1]
30-
doSync = True
31-
allMatch, msgList = ufoTools.checkHashMaps(fontPath, doSync)
32-
if allMatch:
33-
print "All processed glyphs match"
34-
else:
35-
for msg in msgList:
36-
print msg
29+
fontPath = sys.argv[1]
30+
doSync = True
31+
allMatch, msgList = ufoTools.checkHashMaps(fontPath, doSync)
32+
if allMatch:
33+
print("All processed glyphs match")
34+
else:
35+
for msg in msgList:
36+
print(msg)
3737

3838

3939
if __name__ == "__main__":
40-
run()
40+
run()

generateAllKernFiles.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@
1818
try:
1919
from defcon import Font
2020
except ImportError:
21-
print("ERROR: This script requires defcon. It can be downloaded from "
22-
"https://github.com/typesupply/defcon")
21+
print(
22+
"ERROR: This script requires defcon. It can be downloaded from "
23+
"https://github.com/typesupply/defcon"
24+
)
2325
libraryNotFound = True
2426
try:
2527
import kernFeatureWriter
2628
except ImportError:
27-
print("ERROR: This script requires kernFeatureWriter.py. It can be "
28-
"downloaded from https://github.com/adobe-type-tools/python-modules")
29+
print(
30+
"ERROR: This script requires kernFeatureWriter.py. It can be "
31+
"downloaded from https://github.com/adobe-type-tools/python-modules"
32+
)
2933
libraryNotFound = True
3034

3135

@@ -84,14 +88,15 @@ def run():
8488

8589
t2 = time.time()
8690
elapsedSeconds = t2 - t1
91+
elapsedMinutes = elapsedSeconds / 60
8792

88-
if (elapsedSeconds // 60) < 1:
89-
print('Completed in %.1f seconds.' % elapsedSeconds)
93+
if elapsedMinutes < 1:
94+
print(('Completed in %.1f seconds.' % elapsedSeconds))
9095
else:
91-
print('Completed in %.1f minutes.' % (elapsedSeconds // 60))
96+
print(('Completed in %.1f minutes.' % elapsedMinutes))
9297

9398

9499
if __name__ == '__main__':
95100
if libraryNotFound:
96101
sys.exit(1)
97-
sys.exit(run())
102+
run()

generateAllMarkFiles.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,13 @@ def run():
8787

8888
t2 = time.time()
8989
elapsedSeconds = t2 - t1
90+
elapsedMinutes = elapsedSeconds / 60
9091

91-
if (elapsedSeconds // 60) < 1:
92-
print('Completed in %.1f seconds.' % elapsedSeconds)
92+
if elapsedMinutes < 1:
93+
print(('Completed in %.1f seconds.' % elapsedSeconds))
9394
else:
94-
print('Completed in %.1f minutes.' % (elapsedSeconds // 60))
95+
print(('Completed in %.1f minutes.' % elapsedMinutes))
9596

9697

9798
if __name__ == '__main__':
98-
if libraryNotFound:
99-
sys.exit(1)
100-
sys.exit(run())
99+
run()

generateSingleKernFile.py

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,77 +24,83 @@
2424
libraryNotFound = False
2525

2626
try:
27-
from defcon import Font
28-
except:
29-
print "ERROR: This script requires defcon. It can be downloaded from https://github.com/typesupply/defcon"
30-
libraryNotFound = True
27+
from defcon import Font
28+
except ImportError:
29+
print(
30+
"ERROR: This script requires defcon. "
31+
"It can be downloaded from https://github.com/typesupply/defcon")
32+
libraryNotFound = True
3133
try:
32-
import WriteFeaturesKernFDK
33-
except:
34-
print "ERROR: This script requires WriteFeaturesKernFDK.py. It can be downloaded from https://github.com/adobe-type-tools/python-modules"
35-
libraryNotFound = True
34+
import WriteFeaturesKernFDK
35+
except ImportError:
36+
print(
37+
"ERROR: This script requires WriteFeaturesKernFDK.py. "
38+
"It can be downloaded from "
39+
"https://github.com/adobe-type-tools/python-modules")
40+
libraryNotFound = True
3641

3742
if libraryNotFound:
38-
sys.exit()
43+
sys.exit()
3944

4045

4146
def generateKernFile(font):
4247

43-
folderPath, fontFileName = os.path.split(font)
44-
# path to the folder where the font is contained and the font's file name
45-
os.chdir(folderPath)
48+
folderPath, fontFileName = os.path.split(font)
49+
# path to the folder where the font is contained and the font's file name
50+
os.chdir(folderPath)
4651

47-
ufoFont = Font(fontFileName)
48-
ufoBaseName = os.path.splitext(fontFileName)[0]
49-
kernFileName = 'kern_%s.fea' % ufoBaseName
50-
styleName = ufoFont.info.styleName
52+
ufoFont = Font(fontFileName)
53+
ufoBaseName = os.path.splitext(fontFileName)[0]
54+
kernFileName = 'kern_%s.fea' % ufoBaseName
55+
styleName = ufoFont.info.styleName
5156

52-
print '*******************************'
53-
print 'Kerning for %s...' % (styleName)
57+
print('*******************************')
58+
print('Kerning for %s...' % (styleName))
5459

55-
WriteFeaturesKernFDK.KernDataClass(
56-
ufoFont, folderPath, minKern,
57-
writeTrimmed, writeSubtables, kernFileName
58-
)
60+
WriteFeaturesKernFDK.KernDataClass(
61+
ufoFont, folderPath, minKern,
62+
writeTrimmed, writeSubtables, kernFileName
63+
)
5964

6065

6166
def run():
62-
# if a path is provided
63-
if len(sys.argv[1:]):
64-
baseFolderPath = sys.argv[1]
67+
# if a path is provided
68+
if len(sys.argv[1:]):
69+
baseFolderPath = sys.argv[1]
6570

66-
if baseFolderPath[-1] == '/': # remove last slash if present
67-
baseFolderPath = baseFolderPath[:-1]
71+
if baseFolderPath[-1] == '/': # remove last slash if present
72+
baseFolderPath = baseFolderPath[:-1]
6873

69-
# make sure the path is valid
70-
if not os.path.isdir(baseFolderPath):
71-
print 'Invalid directory.'
72-
return
74+
# make sure the path is valid
75+
if not os.path.isdir(baseFolderPath):
76+
print('Invalid directory.')
77+
return
7378

74-
# if a path is not provided, use the current directory
75-
else:
76-
baseFolderPath = os.getcwd()
79+
# if a path is not provided, use the current directory
80+
else:
81+
baseFolderPath = os.getcwd()
7782

78-
t1 = time.time()
83+
t1 = time.time()
7984

80-
fontPath = os.path.abspath(sys.argv[-1])
81-
print fontPath
85+
fontPath = os.path.abspath(sys.argv[-1])
86+
print(fontPath)
8287

83-
if os.path.exists(fontPath) and fontPath.lower().endswith('.ufo'):
84-
generateKernFile(fontPath)
88+
if os.path.exists(fontPath) and fontPath.lower().endswith('.ufo'):
89+
generateKernFile(fontPath)
8590

86-
else:
87-
print "No fonts found"
88-
return
91+
else:
92+
print("No fonts found")
93+
return
8994

90-
t2 = time.time()
91-
elapsedSeconds = t2-t1
95+
t2 = time.time()
96+
elapsedSeconds = t2 - t1
97+
elapsedMinutes = elapsedSeconds / 60
9298

93-
if (elapsedSeconds/60) < 1:
94-
print 'Completed in %.1f seconds.' % elapsedSeconds
95-
else:
96-
print 'Completed in %.1f minutes.' % (elapsedSeconds/60)
99+
if elapsedMinutes < 1:
100+
print(('Completed in %.1f seconds.' % elapsedSeconds))
101+
else:
102+
print(('Completed in %.1f minutes.' % elapsedMinutes))
97103

98104

99-
if __name__=='__main__':
100-
run()
105+
if __name__ == '__main__':
106+
run()

generateSingleMarkFiles.py

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,75 +26,76 @@
2626
libraryNotFound = False
2727

2828
try:
29-
from defcon import Font
29+
from defcon import Font
3030
except:
31-
print "ERROR: This script requires defcon. It can be downloaded from https://github.com/typesupply/defcon"
32-
libraryNotFound = True
31+
print "ERROR: This script requires defcon. It can be downloaded from https://github.com/typesupply/defcon"
32+
libraryNotFound = True
3333
try:
34-
import WriteFeaturesMarkFDK
34+
import WriteFeaturesMarkFDK
3535
except:
36-
print "ERROR: This script requires WriteFeaturesMarkFDK.py. It can be downloaded from https://github.com/adobe-type-tools/python-modules"
37-
libraryNotFound = True
36+
print "ERROR: This script requires WriteFeaturesMarkFDK.py. It can be downloaded from https://github.com/adobe-type-tools/python-modules"
37+
libraryNotFound = True
3838

3939
if libraryNotFound:
40-
sys.exit()
40+
sys.exit()
4141

4242

4343
def generateMarkFiles(font):
4444

45-
folderPath, fontFileName = os.path.split(font)
46-
# path to the folder where the font is contained and the font's file name
47-
os.chdir(folderPath)
45+
folderPath, fontFileName = os.path.split(font)
46+
# path to the folder where the font is contained and the font's file name
47+
os.chdir(folderPath)
4848

49-
ufoFont = Font(fontFileName)
50-
styleName = ufoFont.info.styleName
49+
ufoFont = Font(fontFileName)
50+
styleName = ufoFont.info.styleName
5151

52-
print '*******************************'
53-
print 'Exporting mark files for %s...' % (styleName)
52+
print '*******************************'
53+
print 'Exporting mark files for %s...' % (styleName)
5454

55-
WriteFeaturesMarkFDK.MarkDataClass(
56-
ufoFont, folderPath, trimCasingTags,
57-
genMkmkFeature, writeClassesFile, indianScriptsFormat
58-
)
55+
WriteFeaturesMarkFDK.MarkDataClass(
56+
ufoFont, folderPath, trimCasingTags,
57+
genMkmkFeature, writeClassesFile, indianScriptsFormat
58+
)
5959

6060

6161
def run():
62-
# if a path is provided
63-
if len(sys.argv[1:]):
64-
baseFolderPath = sys.argv[1]
62+
# if a path is provided
63+
if len(sys.argv[1:]):
64+
baseFolderPath = sys.argv[1]
6565

66-
if baseFolderPath[-1] == '/': # remove last slash if present
67-
baseFolderPath = baseFolderPath[:-1]
66+
if baseFolderPath[-1] == '/': # remove last slash if present
67+
baseFolderPath = baseFolderPath[:-1]
6868

69-
# make sure the path is valid
70-
if not os.path.isdir(baseFolderPath):
71-
print 'Invalid directory.'
72-
return
69+
# make sure the path is valid
70+
if not os.path.isdir(baseFolderPath):
71+
print 'Invalid directory.'
72+
return
7373

74-
# if a path is not provided, use the current directory
75-
else:
76-
baseFolderPath = os.getcwd()
74+
# if a path is not provided, use the current directory
75+
else:
76+
baseFolderPath = os.getcwd()
7777

78-
t1 = time.time()
78+
t1 = time.time()
7979

80-
fontPath = os.path.abspath(sys.argv[-1])
81-
print fontPath
80+
fontPath = os.path.abspath(sys.argv[-1])
81+
print fontPath
8282

83-
if os.path.exists(fontPath) and fontPath.lower().endswith('.ufo'):
84-
generateMarkFiles(fontPath)
83+
if os.path.exists(fontPath) and fontPath.lower().endswith('.ufo'):
84+
generateMarkFiles(fontPath)
8585

86-
else:
87-
print "No fonts found"
88-
return
86+
else:
87+
print "No fonts found"
88+
return
8989

90-
t2 = time.time()
91-
elapsedSeconds = t2-t1
90+
t2 = time.time()
91+
elapsedSeconds = t2 - t1
92+
elapsedMinutes = elapsedSeconds / 60
9293

93-
if (elapsedSeconds/60) < 1:
94-
print 'Completed in %.1f seconds.' % elapsedSeconds
95-
else:
96-
print 'Completed in %.1f minutes.' % (elapsedSeconds/60)
94+
if elapsedMinutes < 1:
95+
print(('Completed in %.1f seconds.' % elapsedSeconds))
96+
else:
97+
print(('Completed in %.1f minutes.' % elapsedMinutes))
9798

9899

99-
if __name__=='__main__':
100-
run()
100+
if __name__ == '__main__':
101+
run()

0 commit comments

Comments
 (0)