Kiln » Kiln Storage Service Read More
Clone URL:  
ogconfig.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
import os import re import socket import sys from xml.etree import ElementTree import settings import kilnconfig if __name__ == '__main__': # If we run it from the command line, we sometimes don't have the right path for BugzScout. sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from bugzscout import report_exception RE_2_DIR = re.compile(r'^[a-f0-9]{2}$', re.IGNORECASE) RE_REPO_DIR = re.compile(r'^[a-f0-9]+-[a-f0-9]+-[a-f0-9]+-[a-f0-9]+-[a-f0-9]+$', re.IGNORECASE) IGNORE_PATTERNS = ['*.pdb', '*.zip', '*.jar', '*.gz', '*.bz2', '*.tar', '*.class', '*.dll', '*.exe', '*.mdb', '*.kbf', '*.vim'] def add_string(parent, name, value): node = ElementTree.Element('void', {'property': name}) str_node = ElementTree.Element('string') str_node.text = value node.append(str_node) parent.append(node) def add_bool(parent, name, value): node = ElementTree.Element('void', {'property': name}) str_node = ElementTree.Element('boolean') str_node.text = 'true' if value else 'false' node.append(str_node) parent.append(node) def add_ignores(parent, ignores): names = ElementTree.Element('void', {'property': 'ignoredNames'}) patterns = ElementTree.Element('void', {'property': 'ignoredPatterns'}) for s in ignores: node = ElementTree.Element('void', {'method': 'add'}) str_node = ElementTree.Element('string') str_node.text = s node.append(str_node) patterns.append(node) names.append(patterns) parent.append(names) def create_tree(kiln_config): root = ElementTree.Element('java', {'version': '1.6.0_22', 'class': 'java.beans.XMLDecoder'}) tree = ElementTree.ElementTree(root) config = ElementTree.Element('object', {'class': 'org.opensolaris.opengrok.configuration.Configuration'}) add_string(config, 'ctags', kiln_config.read('OpenGrok', 'CTags')) add_string(config, 'sourceRoot', kiln_config.read(None, 'KilnRepositoryRoot')) add_string(config, 'dataRoot', kiln_config.read('OpenGrok', 'DataDir')) add_bool(config, 'generateHtml', False) add_ignores(config, IGNORE_PATTERNS) projects = ElementTree.Element('void', {'property': 'projects'}) config.append(projects) root.append(config) return tree, root, projects def add_repo(parent, repo, path): if not path.startswith('/'): path = '/' + path add = ElementTree.Element('void', {'method': 'add'}) project = ElementTree.Element('object', {'class': 'org.opensolaris.opengrok.configuration.Project'}) add_string(project, 'description', path) add_string(project, 'path', path) add.append(project) parent.append(add) def update_config(): def repo_has_changesets(path): return os.path.exists(os.path.join(path, '.hg', 'store', 'data')) try: config_file = None if settings.HOSTED: config_file = '/home/kiln/daemon.conf' config = kilnconfig.KilnConfig(config_file) repo_dir = os.path.abspath(config.read(None, 'KilnRepositoryRoot')) og_data_dir = os.path.abspath(config.read('OpenGrok', 'DataDir')) tree, root, projects = create_tree(config) for dir1 in os.listdir(repo_dir): if RE_2_DIR.match(dir1): for dir2 in os.listdir(os.path.join(repo_dir, dir1)): if RE_2_DIR.match(dir2): for repo in os.listdir(os.path.join(repo_dir, dir1, dir2)): path = os.path.join(dir1, dir2, repo) if RE_REPO_DIR.match(repo) and repo_has_changesets(os.path.join(repo_dir, path)): add_repo(projects, repo, path.replace('\\', '/')) elif RE_REPO_DIR.match(dir1): add_repo(projects, dir1, dir1) with open(os.path.join(og_data_dir, 'configuration.xml'), 'w') as fd: tree.write(fd, 'UTF-8') addr = config.read('OpenGrok', 'ConfigUpdate', default='localhost:2424') host, port = addr.split(':') sock = socket.socket() try: sock.connect((host, int(port))) tree.write(sock.makefile('w', 1024), 'UTF-8') finally: sock.close() except Exception, e: report_exception(e) if __name__ == '__main__': update_config()