-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.py
More file actions
131 lines (118 loc) · 3.69 KB
/
build.py
File metadata and controls
131 lines (118 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# -----------------
# Extension Details
# -----------------
name = "Guide Tool"
version = "1.5"
developer = "Type Supply"
developerURL = "http://typesupply.com"
roboFontVersion = "4.3"
pycOnly = False
menuItems = [
dict(
path="menu_showFontGuidelines.py",
preferredName="Edit Font Guides",
shortKey=""
),
dict(
path="menu_addGlyphGuideline.py",
preferredName="Add Glyph Guide",
shortKey=("g", "shift", "control")
),
dict(
path="menu_addFontGuideline.py",
preferredName="Add Font Guide",
shortKey=("g", "shift", "control", "command")
),
# - prefs
dict(
path="menu_showPrefs.py",
preferredName="Edit Preferences",
shortKey=""
),
]
mainScript = "main.py"
launchAtStartUp = True
installAfterBuild = True
# ----------------------
# Don't edit below here.
# ----------------------
from AppKit import *
import os
import shutil
from mojo.extensions import ExtensionBundle
# Convert short key modifiers.
modifierMap = {
"command": NSCommandKeyMask,
"control": NSControlKeyMask,
"option": NSAlternateKeyMask,
"shift": NSShiftKeyMask,
"capslock": NSAlphaShiftKeyMask,
}
for menuItem in menuItems:
shortKey = menuItem.get("shortKey")
if isinstance(shortKey, tuple):
shortKey = list(shortKey)
character = shortKey.pop(0)
converted = None
for modifier in shortKey:
modifier = modifierMap.get(modifier)
if converted is None:
converted = modifier
else:
converted |= modifier
shortKey = (converted, character)
menuItem["shortKey"] = shortKey
# Make the various paths.
basePath = os.path.dirname(__file__)
sourcePath = os.path.join(basePath, "source")
libFolder = os.path.join(sourcePath, "code")
licensePath = os.path.join(basePath, "license.txt")
requirementsPath = os.path.join(basePath, "requirements.txt")
resourcesFolder = os.path.join(sourcePath, "resources")
if not os.path.exists(resourcesFolder):
resourcesFolder = None
extensionFile = "%s.roboFontExt" % name
buildPath = os.path.join(basePath, "build")
extensionPath = os.path.join(buildPath, extensionFile)
# Build the extension.
B = ExtensionBundle()
B.name = name
B.developer = developer
B.developerURL = developerURL
B.version = version
B.launchAtStartUp = launchAtStartUp
B.mainScript = mainScript
docPath = os.path.join(sourcePath, "documentation")
haveDocumentation = False
if os.path.exists(os.path.join(docPath, "index.html")):
haveDocumentation = True
elif os.path.exists(os.path.join(docPath, "index.md")):
haveDocumentation = True
if not haveDocumentation:
docPath = None
B.html = haveDocumentation
B.requiresVersionMajor = roboFontVersion.split(".")[0]
B.requiresVersionMinor = roboFontVersion.split(".")[1]
B.addToMenu = menuItems
with open(licensePath) as license:
B.license = license.read()
if os.path.exists(requirementsPath):
with open(requirementsPath) as requirements:
B.requirements = requirements.read()
print("Building extension...", end=" ")
v = B.save(extensionPath, libFolder=libFolder, htmlFolder=docPath, resourcesFolder=resourcesFolder)
print("done!")
errors = B.validationErrors()
if errors:
print("Uh oh! There were errors:")
print(errors)
# Install the extension.
if installAfterBuild:
print("Installing extension...", end=" ")
installDirectory = os.path.expanduser("~/Library/Application Support/RoboFont/plugins")
installPath = os.path.join(installDirectory, extensionFile)
if os.path.exists(installPath):
shutil.rmtree(installPath)
shutil.copytree(extensionPath, installPath)
print("done!")
print("RoboFont must now be restarted.")