-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
114 lines (104 loc) · 3.46 KB
/
build.py
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
# -----------------
# Extension Details
# -----------------
name = "Slinky"
version = "1.1"
developer = "Ryan Bugden"
developer_url = "https://ryanbugden.com"
rf_version = "4.4b"
pyc_only = False
menu_items = [
dict(
path="slinky.py",
preferredName="Slinky",
shortKey=""
),
]
main_script = "slinky.py"
icon_file = "images/mechanic_icon.png"
launch_at_startup = False
install_after_build = True
# ----------------------
# Don't edit below here.
# ----------------------
from AppKit import *
import os
import shutil
from mojo.extensions import ExtensionBundle
# Convert short key modifiers.
modifier_map = {
"command": NSCommandKeyMask,
"control": NSControlKeyMask,
"option": NSAlternateKeyMask,
"shift": NSShiftKeyMask,
"capslock": NSAlphaShiftKeyMask,
}
for menu_item in menu_items:
short_key = menu_item.get("short_key")
if isinstance(short_key, tuple):
short_key = list(short_key)
character = short_key.pop(0)
converted = None
for modifier in short_key:
modifier = modifier_map.get(modifier)
if converted is None:
converted = modifier
else:
converted |= modifier
short_key = (converted, character)
menu_item["short_key"] = short_key
# Make the various paths.
base_path = os.path.dirname(__file__)
source_path = os.path.join(base_path, "source")
lib_path = source_path
license_path = os.path.join(base_path, "license.txt")
requirements_path = os.path.join(base_path, "requirements.txt")
resources_path = os.path.join(source_path, "resources")
if not os.path.exists(resources_path):
resources_path = None
extension_file = "%s.roboFontExt" % name
build_path = base_path
extension_path = os.path.join(build_path, extension_file)
# Build the extension.
B = ExtensionBundle()
B.name = name
B.developer = developer
B.developerURL = developer_url
B.version = version
B.icon = icon_file
B.launchAtStartUp = launch_at_startup
B.mainScript = main_script
doc_path = os.path.join(source_path, "documentation")
has_docs = False
if os.path.exists(os.path.join(doc_path, "index.html")):
has_docs = True
elif os.path.exists(os.path.join(doc_path, "index.md")):
has_docs = True
if not has_docs:
doc_path = None
B.html = has_docs
B.requiresVersionMajor = rf_version.split(".")[0]
B.requiresVersionMinor = rf_version.split(".")[1]
B.addToMenu = menu_items
with open(license_path) as license:
B.license = license.read()
if os.path.exists(requirements_path):
with open(requirements_path) as requirements:
B.requirements = requirements.read()
print("Building extension...", end=" ")
v = B.save(extension_path, libPath=lib_path, pycOnly=pyc_only, htmlPath=doc_path, resourcesPath=resources_path)
print("done!")
errors = B.validationErrors()
if errors:
print("There were errors:")
print(errors)
# Install the extension.
if install_after_build:
print("Installing extension...", end=" ")
install_dir = os.path.expanduser(f"~/Library/Application Support/RoboFont/plugins")
install_path = os.path.join(install_dir, extension_file)
if os.path.exists(install_path):
shutil.rmtree(install_path)
shutil.copytree(extension_path, install_path)
print("Done!")
print("RoboFont must now be restarted.")