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
|
#!/usr/bin/env python
# vim: set filencoding=utf8
"""
Mercurial Shared SSH Repository Metadat Sync
@author: Mike Crute (mcrute@gmail.com)
@organization: SoftGroup Hosting
@date: February 23, 2011
"""
import repolib
def sync_repository_config(repos, users, log):
for repo in repos:
if repo.exists:
log.info("Writing hgrc for %r", repo.path)
repo.write_hgrc(users)
else:
log.warn("Non-existent repo %r", repo.path)
def sync_ssh_config(auth_keys_filename, users, log):
with open(auth_keys_filename, 'w') as auth_keys:
log.info("Writing %r", auth_keys_filename)
for user in users:
log.info("Writing user '%s'", user)
auth_keys.write(user.ssh_line)
def main(argv):
log = repolib.get_logger('sync-repo-config')
try:
cfg_file = argv[-1] if argv else "/etc/hgssh.cfg"
cfg = repolib.ConfigLoader(cfg_file)
except IOError:
log.error("Config file %r doesn't exist", cfg_file)
return 1
sync_repository_config(cfg.repos, cfg.user_dict, log)
try:
sync_ssh_config(cfg.repo_user_authorized_keys, cfg.users, log)
except ValueError, exc:
log.error("%s", exc)
return 1
return 0
if __name__ == "__main__":
import sys
sys.exit(main(sys.argv[1:]))
|