|
a/scripts/refresh-all-repos.py |
|
b/scripts/refresh-all-repos.py |
1 |
import logging
|
1 |
import logging
|
2 |
import optparse
|
2 |
import optparse
|
3 |
from collections import defaultdict
|
3 |
from collections import defaultdict
|
4 |
|
4 |
|
5 |
from pylons import c
|
5 |
from pylons import c
|
|
|
6 |
from ming.orm import ThreadLocalORMSession
|
6 |
|
7 |
|
7 |
from allura import model as M
|
8 |
from allura import model as M
|
8 |
|
9 |
|
9 |
log = logging.getLogger(__name__)
|
10 |
log = logging.getLogger(__name__)
|
|
|
11 |
|
|
|
12 |
PAGESIZE=1024
|
10 |
|
13 |
|
11 |
def main():
|
14 |
def main():
|
12 |
parser = optparse.OptionParser()
|
15 |
parser = optparse.OptionParser()
|
13 |
parser.add_option(
|
16 |
parser.add_option(
|
14 |
'--clean', action='store_true', dest='clean', default=False,
|
17 |
'--clean', action='store_true', dest='clean', default=False,
|
|
... |
|
... |
28 |
q_project = {}
|
31 |
q_project = {}
|
29 |
log.info('Refreshing repositories')
|
32 |
log.info('Refreshing repositories')
|
30 |
if options.clean:
|
33 |
if options.clean:
|
31 |
log.info('Removing all repository objects')
|
34 |
log.info('Removing all repository objects')
|
32 |
M.repository.RepoObject.query.remove()
|
35 |
M.repository.RepoObject.query.remove()
|
33 |
all_projects = M.Project.query.find(q_project).all()
|
36 |
for chunk in chunked_project_iterator(q_project):
|
34 |
for p in all_projects:
|
37 |
for p in chunk:
|
35 |
c.project = p
|
38 |
c.project = p
|
36 |
if projects:
|
39 |
if projects:
|
37 |
mount_points = projects[p.shortname]
|
40 |
mount_points = projects[p.shortname]
|
38 |
else:
|
41 |
else:
|
39 |
mount_points = [ ac.options.mount_point
|
42 |
mount_points = [ ac.options.mount_point
|
40 |
for ac in M.AppConfig.query.find(dict(project_id=p._id)) ]
|
43 |
for ac in M.AppConfig.query.find(dict(project_id=p._id)) ]
|
41 |
for app in (p.app_instance(mp) for mp in mount_points):
|
44 |
for app in (p.app_instance(mp) for mp in mount_points):
|
42 |
c.app = app
|
45 |
c.app = app
|
43 |
if not hasattr(app, 'repo'): continue
|
46 |
if not hasattr(app, 'repo'): continue
|
44 |
if options.clean:
|
47 |
if options.clean:
|
45 |
M.LastCommitFor.query.remove(dict(repo_id=c.app.repo._id))
|
48 |
M.LastCommitFor.query.remove(dict(repo_id=c.app.repo._id))
|
46 |
try:
|
49 |
try:
|
47 |
c.app.repo._impl._setup_hooks()
|
50 |
c.app.repo._impl._setup_hooks()
|
48 |
except:
|
51 |
except:
|
49 |
log.exception('Error setting up hooks for %r', c.app.repo)
|
52 |
log.exception('Error setting up hooks for %r', c.app.repo)
|
50 |
try:
|
53 |
try:
|
51 |
if options.all:
|
54 |
if options.all:
|
52 |
log.info('Refreshing ALL commits in %r', c.app.repo)
|
55 |
log.info('Refreshing ALL commits in %r', c.app.repo)
|
53 |
else:
|
56 |
else:
|
54 |
log.info('Refreshing NEW commits in %r', c.app.repo)
|
57 |
log.info('Refreshing NEW commits in %r', c.app.repo)
|
55 |
c.app.repo.refresh(options.all)
|
58 |
c.app.repo.refresh(options.all)
|
56 |
except:
|
59 |
except:
|
57 |
log.exception('Error refreshing %r', c.app.repo)
|
60 |
log.exception('Error refreshing %r', c.app.repo)
|
|
|
61 |
ThreadLocalORMSession.flush_all()
|
|
|
62 |
ThreadLocalORMSession.close_all()
|
|
|
63 |
|
|
|
64 |
def chunked_project_iterator(q_project):
|
|
|
65 |
page = 0
|
|
|
66 |
while True:
|
|
|
67 |
results = (M.Project.query
|
|
|
68 |
.find(q_project)
|
|
|
69 |
.skip(PAGESIZE*page)
|
|
|
70 |
.limit(PAGESIZE)
|
|
|
71 |
.all())
|
|
|
72 |
if not results: break
|
|
|
73 |
yield results
|
|
|
74 |
page += 1
|
|
|
75 |
|
58 |
|
76 |
|
59 |
if __name__ == '__main__':
|
77 |
if __name__ == '__main__':
|
60 |
main()
|
78 |
main()
|