in Allura/allura/scripts/refreshrepo.py [0:0]
def execute(cls, options):
q_project = {}
if options.nbhd:
nbhd = M.Neighborhood.query.get(url_prefix=options.nbhd)
if not nbhd:
return "Invalid neighborhood url prefix."
q_project['neighborhood_id'] = nbhd._id
if options.project:
q_project['shortname'] = options.project
elif options.project_regex:
q_project['shortname'] = {'$regex': options.project_regex}
log.info('Refreshing repositories')
for chunk in chunked_find(M.Project, q_project):
for p in chunk:
log.info("Refreshing repos for project '%s'." % p.shortname)
if options.dry_run:
continue
c.project = p
if options.mount_point:
mount_points = [options.mount_point]
else:
mount_points = [ac.options.mount_point for ac in
M.AppConfig.query.find(dict(project_id=p._id))]
for app in (p.app_instance(mp) for mp in mount_points):
c.app = app
if not hasattr(app, 'repo'):
continue
if c.app.repo.tool.lower() not in options.repo_types:
log.info("Skipping %r: wrong type (%s)", c.app.repo,
c.app.repo.tool.lower())
continue
ci_ids = []
if options.clean:
ci_ids = list(c.app.repo.all_commit_ids())
elif options.clean_after:
for ci in M.repository.CommitDoc.m.find({'repo_ids': c.app.repo._id,
'committed.date': {'$gt': options.clean_after}}):
ci_ids.append(ci._id)
if ci_ids:
log.info("Deleting mongo data for %i commits...",
len(ci_ids))
# delete these in chunks, otherwise the query doc can
# exceed the max BSON size limit (16MB at the moment)
for ci_ids_chunk in chunked_list(ci_ids, 3000):
i = M.repository.CommitDoc.m.find(
{"_id": {"$in": ci_ids_chunk}}).count()
if i:
log.info("Deleting %i CommitDoc docs...", i)
M.repository.CommitDoc.m.remove(
{"_id": {"$in": ci_ids_chunk}})
for ci_ids_chunk in chunked_list(ci_ids, 3000):
# delete LastCommitDocs
i = M.repository.LastCommitDoc.m.find(
dict(commit_id={'$in': ci_ids_chunk})).count()
if i:
log.info(
"Deleting %i LastCommitDoc docs...", i)
M.repository.LastCommitDoc.m.remove(
dict(commit_id={'$in': ci_ids_chunk}))
del ci_ids
try:
if options.all:
log.info('Refreshing ALL commits in %r',
c.app.repo)
else:
log.info('Refreshing NEW commits in %r',
c.app.repo)
if options.profile:
import cProfile
cProfile.runctx(
'c.app.repo.refresh(options.all, notify=options.notify, '
' commits_are_new=options.commits_are_new)',
globals(), locals(), 'refresh.profile')
else:
c.app.repo.refresh(
options.all, notify=options.notify, commits_are_new=options.commits_are_new)
except Exception:
log.exception('Error refreshing %r', c.app.repo)
ThreadLocalODMSession.flush_all()