This repository has been archived by the owner on May 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
build.py
executable file
·67 lines (55 loc) · 1.82 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
#!/usr/bin/env python
# coding: utf-8
from __future__ import print_function
from __future__ import unicode_literals
from cgi import escape
import subprocess
def is_iterm_modern():
osa = subprocess.Popen(['osascript', './detect_version.applescript'],
stdout=subprocess.PIPE)
result = osa.communicate()[0].strip()
return result == 'true'
def xml_safe(script):
return escape(script).encode('utf8')
def build(src_dir, out_dir, templates, context):
for tpl in templates:
in_path = src_dir + tpl
out_path = out_dir + tpl
with open(in_path, 'r') as fin:
tpl = fin.read()
data = tpl.format(**context)
with open(out_path, 'w') as fout:
fout.write(data)
print('{0} -> {1}'.format(in_path, out_path))
def build_application():
src_dir = './application/'
out_dir = './Open iTerm.app/Contents/'
if is_iterm_modern():
script_path = src_dir + 'application.modern.applescript'
else:
script_path = src_dir + 'application.applescript'
script = open(script_path, 'r').read()
context = {
'APPLICATION_APPLESCRIPT': xml_safe(script),
'APPLICATION_NAME': 'OpeniTerm',
'APPLICATION_IDENTIFIER': 'com.peterldowns.OpeniTerm',
}
templates = ['document.wflow', 'Info.plist']
build(src_dir, out_dir, templates, context)
def build_service():
src_dir = './service/'
out_dir = './Open iTerm.workflow/Contents/'
if is_iterm_modern():
script_path = src_dir + 'service.modern.applescript'
else:
script_path = src_dir + 'service.applescript'
script = open(script_path, 'r').read()
context = {
'FINDER_SERVICE_APPLESCRIPT': xml_safe(script),
'FINDER_SERVICE_MENU_NAME': 'Open iTerm',
}
templates = ['document.wflow', 'Info.plist']
build(src_dir, out_dir, templates, context)
if __name__ == '__main__':
build_application()
build_service()