-
Notifications
You must be signed in to change notification settings - Fork 141
/
reindex_help.py
executable file
·58 lines (45 loc) · 1.62 KB
/
reindex_help.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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
This script (re)generates the help index for every locale.
"""
import os
import sys
import subprocess
PROJECT_PATH = os.path.dirname(__file__);
HELPBOOK_PATH = os.path.join(PROJECT_PATH, "Resources/Boxer.help")
STANDALONE_HELPBOOK_PATH = os.path.join(PROJECT_PATH, "Standalone/Resources/Help.help")
HELP_INDEX_NAME = "search.helpindex"
def locales_in_path(path):
locales = []
for name in os.listdir(path):
basename, ext = os.path.splitext(name)
if ext.lower() == ".lproj": locales.append(name)
return locales
def reindex_helpbook(helpbook_path):
"""
Reindexes all locales within the helpbook at the specified path.
"""
helpbook_resource_path = os.path.join(helpbook_path, "Contents", "Resources")
for locale in locales_in_path(helpbook_resource_path):
print u" -- Reindexing locale %s..." % locale
locale_path = os.path.join(helpbook_resource_path, locale)
index_path = os.path.join(locale_path, HELP_INDEX_NAME)
subprocess.call(["hiutil", "-C", "-a", "-s", "en", "-vv", "-m", "2", "-f", index_path, locale_path])
# Touch the path so that XCode will see that it has changed when building.
os.utime(helpbook_path, None)
def kill_helpd():
"""
Kills the helpd process to reset its help cache.
"""
subprocess.call(["killall", "helpd"])
if __name__ == "__main__":
if len(sys.argv) > 1:
helpbook_paths = sys.argv[1:]
else:
helpbook_paths = [HELPBOOK_PATH, STANDALONE_HELPBOOK_PATH]
for helpbook_path in helpbook_paths:
print u"Reindexing helpbook %s..." % helpbook_path
reindex_helpbook(helpbook_path)
print u"Restarting helpd process..."
kill_helpd()