跟进上面 Niall 非常有用的答案,我意识到我需要一个工具来维护这个 [paths] 部分。我最终选择了这个(它使用了 M. Foord的 configobj。
#!/usr/bin/env python
from __future__ import print_function
import os
from configobj import ConfigObj
hgweb_path = os.path.join(os.path.expanduser("~"), "Library", "Preferences", "hgweb.config")
projects = os.path.join(os.path.expanduser("~"), "projects")
config = ConfigObj(hgweb_path)
paths = []
def add_mercurial(arg, dirname, names):
if '.hg' in names:
paths.append(dirname[len(projects) + 1:])
os.path.walk(projects, add_mercurial, None)
config['paths'] = {}
for path in paths:
config['paths']["projects/" + path] = os.path.join(projects, path)
config.write()
该脚本由 OS X 相当于 cron 每 15 分钟运行一次,并确保我的 hgweb 永远不会过时。