|
24 | 24 | libraryNotFound = False |
25 | 25 |
|
26 | 26 | 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 |
31 | 33 | 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 |
36 | 41 |
|
37 | 42 | if libraryNotFound: |
38 | | - sys.exit() |
| 43 | + sys.exit() |
39 | 44 |
|
40 | 45 |
|
41 | 46 | def generateKernFile(font): |
42 | 47 |
|
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) |
46 | 51 |
|
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 |
51 | 56 |
|
52 | | - print '*******************************' |
53 | | - print 'Kerning for %s...' % (styleName) |
| 57 | + print('*******************************') |
| 58 | + print('Kerning for %s...' % (styleName)) |
54 | 59 |
|
55 | | - WriteFeaturesKernFDK.KernDataClass( |
56 | | - ufoFont, folderPath, minKern, |
57 | | - writeTrimmed, writeSubtables, kernFileName |
58 | | - ) |
| 60 | + WriteFeaturesKernFDK.KernDataClass( |
| 61 | + ufoFont, folderPath, minKern, |
| 62 | + writeTrimmed, writeSubtables, kernFileName |
| 63 | + ) |
59 | 64 |
|
60 | 65 |
|
61 | 66 | 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] |
65 | 70 |
|
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] |
68 | 73 |
|
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 |
73 | 78 |
|
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() |
77 | 82 |
|
78 | | - t1 = time.time() |
| 83 | + t1 = time.time() |
79 | 84 |
|
80 | | - fontPath = os.path.abspath(sys.argv[-1]) |
81 | | - print fontPath |
| 85 | + fontPath = os.path.abspath(sys.argv[-1]) |
| 86 | + print(fontPath) |
82 | 87 |
|
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) |
85 | 90 |
|
86 | | - else: |
87 | | - print "No fonts found" |
88 | | - return |
| 91 | + else: |
| 92 | + print("No fonts found") |
| 93 | + return |
89 | 94 |
|
90 | | - t2 = time.time() |
91 | | - elapsedSeconds = t2-t1 |
| 95 | + t2 = time.time() |
| 96 | + elapsedSeconds = t2 - t1 |
| 97 | + elapsedMinutes = elapsedSeconds / 60 |
92 | 98 |
|
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)) |
97 | 103 |
|
98 | 104 |
|
99 | | -if __name__=='__main__': |
100 | | - run() |
| 105 | +if __name__ == '__main__': |
| 106 | + run() |
0 commit comments